static void AdjectiveSamples() { { Console.WriteLine("Поиск прилагательного по точному совпадению с автоматическим определением рода, падежа, числа и одушевленности."); CyrAdjective adjective = cyrAdjectiveCollection.Get("пушистая", out GendersEnum gender, out CasesEnum @case, out NumbersEnum number, out AnimatesEnum animate); WriteToConsole(adjective); } { Console.WriteLine("Поиск прилагательного по неточному совпадению с автоматическим определением рода, падежа, числа и одушевленности."); CyrAdjective adjective = cyrAdjectiveCollection.Get("кушистый", out string foundWord, out GendersEnum gender, out CasesEnum @case, out NumbersEnum number, out AnimatesEnum animate); WriteToConsole(adjective, foundWord); } { Console.WriteLine("Поиск прилагательного по точному совпадению с указанием рода, падежа, числа и одушевленности."); CyrAdjective adjective = cyrAdjectiveCollection.Get("пушистого", GendersEnum.Masculine, CasesEnum.Genitive, NumbersEnum.Singular, AnimatesEnum.Animated); WriteToConsole(adjective); } { Console.WriteLine("Поиск прилагательного по неточному совпадению с указанием рода, падежа, числа и одушевленности."); CyrAdjective adjective = cyrAdjectiveCollection.GetOrDefault("кушистого", out string foundWord, GendersEnum.Masculine, CasesEnum.Genitive, NumbersEnum.Singular, AnimatesEnum.Animated); WriteToConsole(adjective, foundWord); } }
private void btnDecline_Click(object sender, EventArgs e) { if (txtWord.Text.IsNullOrEmpty()) { MessageBox.Show("Необходимо ввести слово!"); } CyrAdjective adj; GendersEnum declineToGender = (GendersEnum)(ddlGender.SelectedIndex + 1); AnimatesEnum declineToAnimate = (AnimatesEnum)(ddlAnimate.SelectedIndex + 1); NumbersEnum declineToNumber = (NumbersEnum)(ddlNumber.SelectedIndex + 1); string foundWord; GendersEnum foundGender; CasesEnum foundCase; NumbersEnum foundNumber; AnimatesEnum foundAnimate; CyrResult result = null; try { Stopwatch watch = new Stopwatch(); watch.Start(); adj = cyrCollection.Get(txtWord.Text, out foundWord, out foundGender, out foundCase, out foundNumber, out foundAnimate); if (declineToNumber == NumbersEnum.Singular) { result = adj.Decline(declineToGender, declineToAnimate); } else { result = adj.DeclinePlural(declineToAnimate); } watch.Stop(); this.Log($"Склонение слова {txtWord.Text} заняло {watch.Elapsed}."); } catch (CyrWordNotFoundException) { MessageBox.Show("Данное слово не найдено в коллекции!"); return; } this.SetResult(result); txtCollectionName.Text = foundWord; txtDetails.Text = $"{foundGender}, {foundCase}, {foundNumber}, {foundAnimate}"; if (txtWord.Text == foundWord) { txtCollectionName.BackColor = SystemColors.Control; } else { txtCollectionName.BackColor = SystemColors.Highlight; } }
public ActionResult Adjective(string w) { ViewBag.Page = "Decline.Adjective"; if (string.IsNullOrEmpty(w)) { return(View()); } List <string> errors = new List <string>(); List <CyrAdjectiveDeclineResult> results = new List <CyrAdjectiveDeclineResult>(); CyrAdjectiveCollection collection = this.AdjectiveCollection; foreach (string s in w.Split(' ').Where(val => !string.IsNullOrEmpty(val))) { CyrAdjective word; string foundWord; GendersEnum foundGender; CasesEnum foundCase; NumbersEnum foundNumber; AnimatesEnum foundAnimate; try { word = collection.Get(s, out foundWord, out foundGender, out foundCase, out foundNumber, out foundAnimate); } catch (CyrWordNotFoundException) { errors.Add(string.Format("Слово \"<strong>{0}</strong>\" не найдено в коллекции. Попбробуйте другое слово.", s)); continue; } CyrAdjectiveDeclineResult result = new CyrAdjectiveDeclineResult() { Name = word.Name, OriginalWord = s, FoundWord = foundWord, FoundGender = foundGender, FoundCase = foundCase, FoundNumber = foundNumber, FoundAnimate = foundAnimate, Singular = word.Decline(foundGender == 0 ? GendersEnum.Masculine : foundGender, foundAnimate), Plural = word.DeclinePlural(foundAnimate) }; results.Add(result); } ViewBag.Text = w; ViewBag.Errors = errors; ViewBag.Results = results; ViewBag.Cases = CyrDeclineCase.GetEnumerable().ToArray(); return(View()); }
public static List <string> GetAdjectiveDeclension(string word) { var adjective = _cyrAdjectiveCollection.Get(word, out GendersEnum gender, out CasesEnum @case, out NumbersEnum number, out AnimatesEnum animate); var singular = adjective.Decline(gender, animate).ToArray(); var plural = adjective.DeclinePlural(animate).ToArray(); var result = new List <string>(); result.AddRange(singular.Where(singularWord => !string.IsNullOrEmpty(singularWord))); result.AddRange(plural.Where(singularWord => !string.IsNullOrEmpty(singularWord))); return(result.Distinct().ToList()); }
public string DeclineAdjective(string word, string caseName, string anim = "") { var adj = adjs.Get(word, GetConditionsEnum.Similar); if (!Enum.TryParse(anim, out AnimatesEnum animKind)) { animKind = AnimatesEnum.Inanimated; } var declineRes = adj.Decline(animKind); return(GetDeclensionInCase(declineRes, caseName)); }
public ActionResult Adjective(string w) { ViewBag.Page = "Decline.Adjective"; if (string.IsNullOrEmpty(w)) { return(View()); } List <string> errors = new List <string>(); List <CyrAdjective> words = new List <CyrAdjective>(); List <CyrResult> singulars = new List <CyrResult>(); List <CyrResult> plurals = new List <CyrResult>(); CyrAdjectiveCollection collection = this.AdjectiveCollection; foreach (string s in w.Split(' ').Where(val => !string.IsNullOrEmpty(val))) { CyrAdjective word; try { word = collection.Get(s, GetConditionsEnum.Similar); } catch (CyrWordNotFoundException) { errors.Add(string.Format("Слово \"<strong>{0}</strong>\" не найдено в коллекции. Попбробуйте другое слово.", s)); continue; } words.Add(word); singulars.Add(word.Decline(AnimatesEnum.Animated)); plurals.Add(word.DeclinePlural(AnimatesEnum.Animated)); } ViewBag.Text = w; ViewBag.Errors = errors; ViewBag.Words = words; ViewBag.Singulars = singulars; ViewBag.Plurals = plurals; ViewBag.Cases = CyrDeclineCase.List; return(View()); }
private void btnDecline_Click(object sender, EventArgs e) { if (txtWord.Text.IsNullOrEmpty()) { MessageBox.Show("Необходимо ввести слово!"); } CyrAdjective adj; GendersEnum gender = 0; switch (ddlGender.SelectedIndex) { case 1: gender = GendersEnum.Masculine; break; case 2: gender = GendersEnum.Feminine; break; case 3: gender = GendersEnum.Neuter; break; } try { adj = cyrCollection.Get(txtWord.Text, GetConditionsEnum.Similar, gender); } catch (CyrWordNotFoundException) { MessageBox.Show("Данное слово не найдено в коллекции!"); return; } switch (ddlAction.SelectedIndex) { case 0: this.SetResult(adj.Decline(AnimatesEnum.Animated)); break; case 1: this.SetResult(adj.DeclinePlural(AnimatesEnum.Animated)); break; default: MessageBox.Show("Необходимо выбрать тип склонения!"); return; } txtCollectionName.Text = adj.CollectionName; txtDetails.Text = string.Empty; switch (adj.Gender) { case Cyriller.Model.GendersEnum.Feminine: txtDetails.Text += "женский род"; break; case Cyriller.Model.GendersEnum.Masculine: txtDetails.Text += "мужской род"; break; case Cyriller.Model.GendersEnum.Neuter: txtDetails.Text += "средний род"; break; } if (adj.ExactMatch) { txtCollectionName.BackColor = System.Drawing.SystemColors.Control; } else { txtCollectionName.BackColor = System.Drawing.SystemColors.Highlight; } }