Ejemplo n.º 1
0
 public async Task <IActionResult> Edit(Grammatic grammatic)
 {
     if (grammatic == null)
     {
         return(View("Error"));
     }
     return(View("Edit", await _ltManager.Update(grammatic)));
 }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(string id)
        {
            Grammatic grammatic = await _ltManager.FindAsync(Guid.Parse(id));

            if (grammatic == null)
            {
                return(View("Error"));
            }
            return(View(grammatic));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Details(Guid id)
        {
            Grammatic grammatic = await _ltManager.FindAsync(id);

            if (grammatic == null)
            {
                return(View("Error"));
            }
            return(View(grammatic));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Validate(string id)
        {
            Grammatic grammatic = await _ltManager.FindAsync(Guid.Parse(id));

            if (grammatic == null)
            {
                return(View("Error"));
            }
            ViewBag.Validate = true;
            return(View("Details", grammatic));
        }
        private void загрузитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            label12.Text = "Статус грамматик";
            isSuccessfullyGrammaticBNF = false;
            isSuccessfullyGrammaticKS  = false;
            BNF                      = null;
            textBox9.Text            = null;
            textBox10.Text           = null;
            textBox12.Text           = null;
            textBox11.Text           = null;
            dataGridView2.DataSource = null;
            dataGridView1.DataSource = null;
            textBox13.Text           = null;
            try
            {
                if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }
                string filename     = openFileDialog1.FileName;
                string textFromFile = System.IO.File.ReadAllText(filename);

                KS = new Grammatic();
                KS.SetGrammaticByFile(textFromFile);

                textBox3.Text = KS.GetVTString(); //Vt
                textBox4.Text = KS.GetVNString(); //vn
                textBox5.Text = KS.Start;         //start
                textBox6.Text = KS.Lambda;
                if (string.IsNullOrEmpty(KS.Lambda))
                {
                    throw new Exception("Введите лямбду");
                }
                textBox2.Text = KS.ToString();//regular

                textBox1.Text             = "Грамматика успешно считана из файла и записана";
                isSuccessfullyGrammaticKS = true;
            }
            catch (Exception ex)
            {
                textBox1.Text            += Environment.NewLine + "Ошибка! " + ex.Message;
                isSuccessfullyGrammaticKS = false;
            }
        }
Ejemplo n.º 6
0
        public async Task <Guid> AddGrammatic(Grammatic grammatic)
        {
            Guid       grammaticGuid = Guid.NewGuid();
            Grammatics grammaticDb   = new Grammatics()
            {
                GrammaticId  = grammaticGuid,
                CreateDate   = DateTime.Now,
                EditDate     = DateTime.Now,
                CreateUserId = Guid.Parse((await _userManager.FindByNameAsync(_httpContextAccessor.HttpContext.User.Identity.Name)).Id),
                Text         = grammatic.Text,
                Title        = grammatic.Title,
                FromLanguage = grammatic.FromLanguage,
                ToLanguage   = grammatic.ToLanguage,
                IsEdit       = true
            };

            _ltContext.Grammatics.Add(grammaticDb);
            await _ltContext.SaveChangesAsync();

            return(grammaticGuid);
        }
Ejemplo n.º 7
0
        public async Task <Grammatic> Update(Grammatic grammatic)
        {
            Grammatics grammaticDb = await _ltContext.Grammatics.FindAsync(grammatic.GrammaticId);

            if (grammaticDb.Text != grammatic.Text || grammaticDb.Title != grammatic.Title ||
                grammaticDb.FromLanguage != grammatic.FromLanguage || grammaticDb.ToLanguage != grammatic.ToLanguage
                )

            {
                grammaticDb.Text         = grammatic.Text;
                grammaticDb.Title        = grammatic.Title;
                grammaticDb.IsEdit       = true;
                grammaticDb.IsValidate   = false;
                grammaticDb.EditDate     = DateTime.Now;
                grammaticDb.FromLanguage = grammatic.FromLanguage;
                grammaticDb.ToLanguage   = grammatic.ToLanguage;
            }
            _ltContext.Entry(grammaticDb).State = EntityState.Modified;
            await _ltContext.SaveChangesAsync();

            return(await FindAsync(grammaticDb.GrammaticId));
        }
        private void button1_Click(object sender, EventArgs e)
        {
            label12.Text = "Статус грамматик";
            isSuccessfullyGrammaticBNF = false;
            isSuccessfullyGrammaticKS  = false;
            BNF                      = null;
            textBox9.Text            = null;
            textBox10.Text           = null;
            textBox12.Text           = null;
            textBox11.Text           = null;
            dataGridView2.DataSource = null;
            dataGridView1.DataSource = null;
            textBox13.Text           = null;
            try
            {
                KS = new Grammatic();
                KS.SetVT(textBox3.Text);
                textBox1.Text += Environment.NewLine + "Алфавит считан успешно";
                KS.SetVN(textBox4.Text);
                textBox1.Text += Environment.NewLine + "Нетерминальный алфавит считан успешно";
                KS.SetStartChar(textBox5.Text);
                textBox1.Text += Environment.NewLine + "Стартовый символ считан успешно";
                KS.SetLambda(textBox6.Text.Trim());
                if (string.IsNullOrEmpty(KS.Lambda))
                {
                    throw new Exception("Введите лямбду");
                }
                KS.SetGrammaticKS(textBox2.Text);
                textBox1.Text += Environment.NewLine + "Грамматика считана успешно";

                isSuccessfullyGrammaticKS = true;
            }
            catch (Exception ex)
            {
                textBox1.Text += Environment.NewLine + "Ошибка! " + ex.Message;
            }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> CreateWithTransform(GrammaticTransform grammaticTransform)
        {
            var result = await _ltManager.AddGrammaticWithTransform(grammaticTransform);

            if (result is Grammatic)
            {
                Grammatic grammatic = result as Grammatic;
                return(RedirectToAction("Details", new { id = grammatic.GrammaticId }));
            }
            else
            {
                grammaticTransform            = result as GrammaticTransform;
                grammaticTransform.Grammatics = (await _ltManager.GetAll())
                                                .Select(s =>
                                                        new SelectListItem
                {
                    Value    = s.GrammaticId.ToString(),
                    Text     = s.Title.ToString(),
                    Selected = true
                })
                                                .ToList();
                return(View(grammaticTransform));
            }
        }
Ejemplo n.º 10
0
        private void button1_Click(object sender, EventArgs e)
        {
            grammatic_textBox.Clear();
            nonterms_count_edit.BackColor   = Color.White;
            rules_tocount_edit.BackColor    = Color.White;
            rule_tolength_edit.BackColor    = Color.White;
            rules_fromcount_edit.BackColor  = Color.White;
            rules_fromlength_edit.BackColor = Color.White;
            grammatic_nonterms.Text         = "Нетерминалы";
            grammatic_rules.Text            = "Правила";
            bool error = false;

            if (!int.TryParse(nonterms_count_edit.Text, out gramm_nonterms_count) || gramm_nonterms_count < 1)
            {
                grammatic_textBox.AppendText("\tНеправильно введено количество нетерминалов. Введите натуральное число\n");
                grammatic_nonterms.Text       = "ВОЗНИКЛА ОШИБКА";
                nonterms_count_edit.BackColor = Color.Red;
                error = true;;
            }
            if (!set_rules_dinamic.Checked)
            {
                if (!int.TryParse(rules_tocount_edit.Text, out gramm_rules_count) || gramm_rules_count < 1)
                {
                    grammatic_textBox.AppendText("\tНеверно введено количество замен. Введите натуральное число\n");
                    grammatic_rules.Text         = "ВОЗНИКЛА ОШИБКА";
                    rules_tocount_edit.BackColor = Color.Red;
                    error = true;
                }
                if (!int.TryParse(rule_tolength_edit.Text, out gramm_rule_lenght) || gramm_rule_lenght < 1)
                {
                    grammatic_textBox.AppendText("\tНеверно введена длинна замен. Введите натуральное число\n");
                    grammatic_rules.Text         = "ВОЗНИКЛА ОШИБКА";
                    rule_tolength_edit.BackColor = Color.Red;
                    error = true;
                }
            }
            else
            {
                Random rand = new Random();
                int    i, j;
                if (!int.TryParse(rules_fromcount_edit.Text, out i) || i < 1)
                {
                    grammatic_textBox.AppendText("\tНеверно введена левая граница возмножного количества замен. Введите натуральное число\n");
                    grammatic_rules.Text           = "ВОЗНИКЛА ОШИБКА";
                    rules_fromcount_edit.BackColor = Color.Red;
                    error = true;
                }
                if (!int.TryParse(rules_tocount_edit.Text, out j) || j < 1 || j < i)
                {
                    grammatic_textBox.AppendText("\tНеверно введена правая граница возможного количества замен. Введите натуральное число, большее, либо равное левой границе\n");
                    grammatic_rules.Text         = "ВОЗНИКЛА ОШИБКА";
                    rules_tocount_edit.BackColor = Color.Red;
                    error = true;
                }
                if (!error)
                {
                    gramm_rules_count = rand.Next(i, j);
                }
                if (!int.TryParse(rules_fromlength_edit.Text, out i) || i < 1)
                {
                    grammatic_textBox.AppendText("\tНеверно введена левая гранца возмножной длинны замены. Введите натуральное число\n");
                    grammatic_rules.Text            = "ВОЗНИКЛА ОШИБКА";
                    rules_fromlength_edit.BackColor = Color.Red;
                    error = true;
                }
                if (!int.TryParse(rule_tolength_edit.Text, out j) || j < 1 || j < i)
                {
                    grammatic_textBox.AppendText("\tНеверно введена правая граница возмножной длинны замен. Введите натуральное число, большее, либо равное левой границе\n");
                    grammatic_rules.Text         = "ВОЗНИКЛА ОШИБКА";
                    rule_tolength_edit.BackColor = Color.Red;
                    error = true;
                }
                if (!error)
                {
                    gramm_rule_lenght = rand.Next(i, j);
                }
            }
            if (error)
            {
                return;
            }
            gramm_left_or_right = auto_left.Checked;
            gramm = new Grammatic(gramm_nonterms_count, gramm_rules_count, gramm_rule_lenght, gramm_left_or_right);
            if (!gramm.GenerateGrammatic(gramm_type, out degradated_grammatic))
            {
                grammatic_textBox.AppendText("Во время генерации возникла ошибка. Попробуйте снова или с другими параметрами");
                nonterms_count_edit.BackColor   = Color.Red;
                rules_tocount_edit.BackColor    = Color.Red;
                rule_tolength_edit.BackColor    = Color.Red;
                rules_fromcount_edit.BackColor  = Color.Red;
                rules_fromlength_edit.BackColor = Color.Red;
            }
            else
            {
                foreach (string s in degradated_grammatic)
                {
                    grammatic_textBox.AppendText(s + "\n");
                }
                buttonSave.Show();
            }
        }
Ejemplo n.º 11
0
        public async Task <Grammatic> GenerataFile(Guid grammaticId)
        {
            VerifiedGrammars vgDb = FindVerifiedGrammar(grammaticId);

            if (vgDb != null)
            {
                string path = Directory.GetDirectories(Directory.GetCurrentDirectory() + "/Grammatics/").FirstOrDefault(s => s.Contains(vgDb.Title));
                if (path == null)
                {
                    path = Directory.GetCurrentDirectory() + "/Grammatics/" + vgDb.Title;
                }
                Directory.CreateDirectory(path);
                string           strCmdText = "/C coco " + vgDb.Path + " -frames " + Directory.GetCurrentDirectory() + " -o " + path;
                Process          process    = new Process();
                ProcessStartInfo startInfo  = new ProcessStartInfo()
                {
                    FileName  = "cmd.exe",
                    Arguments = strCmdText
                };
                process.StartInfo = startInfo;
                process.Start();

                process.WaitForExit();
                Grammatic grammatic = await FindAsync(grammaticId);

                Grammatics grammaticsDb = _ltContext.Grammatics.Find(grammatic.GrammaticId);
                grammatic.ResultGenerate = GenerateDLL(path, vgDb.Title);
                if (grammatic.ResultGenerate.ResultCode == 1)
                {
                    GeneratedDLLs generatedDLL = _ltContext.GeneratedDLLs.FirstOrDefault(s => s.GrammaticId == grammaticId);
                    if (generatedDLL != null)
                    {
                        generatedDLL.Image                   = grammatic.ResultGenerate.Result;
                        generatedDLL.FromLanguage            = grammatic.FromLanguage;
                        generatedDLL.ToLanguage              = grammatic.ToLanguage;
                        generatedDLL.Title                   = grammatic.Title;
                        _ltContext.Entry(generatedDLL).State = EntityState.Modified;
                    }
                    else
                    {
                        generatedDLL = new GeneratedDLLs()
                        {
                            GeneratedDLLId = Guid.NewGuid(),
                            GrammaticId    = grammaticId,
                            Image          = grammatic.ResultGenerate.Result,
                            Title          = grammatic.Title,
                            FromLanguage   = grammatic.FromLanguage,
                            ToLanguage     = grammatic.ToLanguage
                        };
                        _ltContext.GeneratedDLLs.Add(generatedDLL);
                    }

                    grammaticsDb.IsEdit = false;
                    _ltContext.Entry(grammaticsDb).State = EntityState.Modified;
                    await _ltContext.SaveChangesAsync();
                    await CalculatePath();
                }
                return(grammatic);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 12
0
        protected List <Chain> CompRec2(int min, int max, Grammatic grammatic)
        {
            var index = grammatic.Regulation.FindIndex(x => x.Left == grammatic.Start);
            var tmp   = grammatic.Regulation[index];

            grammatic.Regulation.Remove(tmp);
            grammatic.Regulation.Insert(0, tmp);

            bool         isOne = true;
            List <Chain> list  = new List <Chain>();

            do
            {
                foreach (var regulars in grammatic.Regulation)
                {
                    if (isOne)
                    {
                        foreach (var reg in regulars.Right)
                        {
                            list.Add(new Chain());
                            var str = "";
                            foreach (var r in reg)
                            {
                                str += r;
                            }
                            list.LastOrDefault().Str          = str.Replace("\n", "").Replace("\t", "").Replace("\r", "");
                            list.LastOrDefault().RegularsList = new List <string>()
                            {
                                str
                            };
                        }

                        isOne = false;
                        continue;
                    }
                    //
                    for (var i = 0; i < list.Count; i++)
                    {
                        var listik = list[i];
                        for (int j = 0; j < listik.Str.Length; j++)
                        {
                            if (grammatic.VT.Any(x => x.Equals(listik.Str[j].ToString())))
                            {
                                continue;
                            }

                            if (!listik.Str[j].Equals(regulars.Left[0]))
                            {
                                continue;
                            }

                            var    isOne2     = true;
                            Chain  listTmpOne = new Chain();
                            string str        = "";
                            foreach (var reg in regulars.Right)
                            {
                                str = "";
                                Chain listTmp = list[i];
                                foreach (var ch in reg)
                                {
                                    str += ch;
                                }
                                if (isOne2)
                                {
                                    listTmp    = list[i];
                                    listTmpOne = (Chain)list[i].Clone();
                                }
                                else
                                {
                                    list.Insert(i, new Chain());
                                    listTmp              = list[i];
                                    listTmp.Str          = listTmpOne.Str.ToString();
                                    listTmp.RegularsList = listTmpOne.RegularsList.ToList();
                                    i++;
                                }
                                listTmp.Str = listTmp.Str.Remove(j, 1);
                                listTmp.Str = listTmp.Str.Insert(j, str);
                                listTmp.RegularsList.Add(str);

                                isOne2 = false;
                            }

                            j += str.Length;
                        }
                    }
                }

                for (var i = 0; i < list.Count; i++)
                {
                    var model = list[i];
                    if (model.Count < min && !grammatic.VN.Any(x => x.Equals(model.ToString())))
                    {
                        list.Remove(model);
                        i--;
                        continue;
                    }

                    if (model.Count > max)
                    {
                        list.Remove(model);
                        i--;
                    }
                }

                if (list.Count > 1000)
                {
                    textBox1.Text += "Цепочек более 1000. Выполнение остановленно.";
                    for (var i = 0; i < list.Count; i++)
                    {
                        var item = list[i];
                        for (var index1 = 0; index1 < item.Str.Length; index1++)
                        {
                            var ch = item.Str[index1];
                            if (grammatic.VN.Any(x => x.Equals(ch.ToString())))
                            {
                                list.RemoveAt(i);
                                i--;
                                break;
                            }
                        }
                    }

                    break;
                }
            } while (CheckWhile(list, grammatic.Lambda, grammatic.VN));

            list.ForEach(x => x.Str = x.Str.Replace(grammatic.Lambda, ""));
            return(ChainsDistinct(list).OrderBy(x => x.Count).ToList());
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Create(Grammatic grammatic)
        {
            Guid grammaticGuid = await _ltManager.AddGrammatic(grammatic);

            return(View("Details", await _ltManager.FindAsync(grammaticGuid)));
        }