public CyrResult DeclinePlural(AnimatesEnum animate) { CyrRule[] rules = this.GetRules(0, NumbersEnum.Plural, animate); CyrResult result = this.GetResult(this.Name, rules); return(result); }
public CyrResult Decline(GendersEnum gender, AnimatesEnum animate) { CyrRule[] rules = this.GetRules(gender, NumbersEnum.Singular, animate); CyrResult result = this.GetResult(this.Name, rules); return(result); }
protected virtual CyrRule[] GetRules(GendersEnum gender, NumbersEnum number, AnimatesEnum animate) { CyrRule[] rules; if (gender == GendersEnum.Masculine) { rules = new CyrRule[] { new CyrRule(string.Empty), this.rules[0], this.rules[1], animate == AnimatesEnum.Animated ? this.rules[2] : new CyrRule(string.Empty), this.rules[3], this.rules[4] }; } else if (gender == GendersEnum.Feminine) { rules = new CyrRule[] { this.rules[5], this.rules[6], this.rules[7], this.rules[8], this.rules[9], this.rules[10] }; } else if (gender == GendersEnum.Neuter) { rules = new CyrRule[] { this.rules[11], this.rules[12], this.rules[13], this.rules[14], this.rules[15], this.rules[16] }; } else if (number == NumbersEnum.Plural) { rules = new CyrRule[] { this.rules[17], this.rules[18], this.rules[19], animate == AnimatesEnum.Animated ? this.rules[20] : this.rules[17], this.rules[21], this.rules[22] }; } else { throw new InvalidOperationException($"Unable to decline adjective with Gender: [{gender}], Number: [{number}], Animate: [{animate}]."); } return(rules); }
public string ToString(decimal Value, CasesEnum Case, Item Item) { long i = (long)Value; StringBuilder sb = new StringBuilder(); //Strings s = new Strings(Case, Item.Gender, Item.Animate); GendersEnum gender = i < Value ? GendersEnum.Feminine : Item.Gender; AnimatesEnum animate = i == Value && i < 20 ? Item.Animate : AnimatesEnum.Inanimated; string[] name; sb.Append(this.ToString(Value, Case, gender, animate)).Append(" "); if (i < Value) { name = Item.GetName(CasesEnum.Nominative, i); sb.Append(name[1]); } else { name = Item.GetName(Case, i); sb.Append(this.Case(i, name[0], name[1], name[2])); } return(sb.ToString()); }
public CyrResult Decline(AnimatesEnum Animate) { CyrResult result; if (this.gender == GendersEnum.Feminine) { result = new CyrResult(this.rules[5].Apply(this.name), this.rules[6].Apply(this.name), this.rules[7].Apply(this.name), this.rules[8].Apply(this.name), this.rules[9].Apply(this.name), this.rules[10].Apply(this.name)); } else if (this.gender == GendersEnum.Neuter) { result = new CyrResult(this.rules[11].Apply(this.name), this.rules[12].Apply(this.name), this.rules[13].Apply(this.name), this.rules[14].Apply(this.name), this.rules[15].Apply(this.name), this.rules[16].Apply(this.name)); } else { result = new CyrResult(this.name, this.rules[0].Apply(this.name), this.rules[1].Apply(this.name), Animate == AnimatesEnum.Animated ? this.rules[2].Apply(this.name) : this.name, this.rules[3].Apply(this.name), this.rules[4].Apply(this.name)); } return result; }
public CyrResult Decline(AnimatesEnum Animate) { CyrResult result; if (this.gender == GendersEnum.Feminine) { result = new CyrResult(this.rules[5].Apply(this.name), this.rules[6].Apply(this.name), this.rules[7].Apply(this.name), this.rules[8].Apply(this.name), this.rules[9].Apply(this.name), this.rules[10].Apply(this.name)); } else if (this.gender == GendersEnum.Neuter) { result = new CyrResult(this.rules[11].Apply(this.name), this.rules[12].Apply(this.name), this.rules[13].Apply(this.name), this.rules[14].Apply(this.name), this.rules[15].Apply(this.name), this.rules[16].Apply(this.name)); } else { result = new CyrResult(this.name, this.rules[0].Apply(this.name), this.rules[1].Apply(this.name), Animate == AnimatesEnum.Animated ? this.rules[2].Apply(this.name) : this.name, this.rules[3].Apply(this.name), this.rules[4].Apply(this.name)); } return(result); }
public DictionaryKey(string name, GendersEnum gender, CasesEnum @case, NumbersEnum number, AnimatesEnum animate) { this.Name = name; this.Gender = gender; this.Case = @case; this.Number = number; this.Animate = animate; }
public CyrNoun(string Name, string CollectionName, GendersEnum Gender, AnimatesEnum Animate, WordTypesEnum Type, CyrRule[] Rules) { this.collectionName = CollectionName; this.name = Name; this.gender = Gender; this.animate = Animate; this.type = Type; this.rules = Rules; }
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 CyrResult DeclinePlural(AnimatesEnum Animate) { CyrResult result = new CyrResult(this.rules[17].Apply(this.name), this.rules[18].Apply(this.name), this.rules[19].Apply(this.name), Animate == AnimatesEnum.Animated ? this.rules[21].Apply(this.name) : this.rules[17].Apply(this.name), this.rules[20].Apply(this.name), this.rules[21].Apply(this.name)); return(result); }
protected virtual string GetAnimatedStringRu(AnimatesEnum animate) { switch (animate) { case AnimatesEnum.Animated: return("одушевленное"); case AnimatesEnum.Inanimated: return("неодушевленное"); default: return(string.Empty); } }
public string ToString(decimal Value, CasesEnum Case, GendersEnum Gender, AnimatesEnum Animate) { string str = Value.ToString(System.Globalization.CultureInfo.InvariantCulture); string[] parts = str.Split('.'); long i = long.Parse(parts[0]); StringBuilder sb = new StringBuilder(); Strings s = new Strings(Case, Gender, Animate); sb.Append(this.ToString(i, Case, Gender, Animate)); if (parts.Length > 1) { parts[1] = parts[1].TrimEnd('0'); } if (parts.Length > 1 && !string.IsNullOrEmpty(parts[1])) { string[] decimals; long d = long.Parse(parts[1]); long dr = long.Parse(string.Join(string.Empty, parts[1].Reverse().ToArray())); if (dr < 10) { decimals = s.DecimalTen; } else if (dr < 100) { decimals = s.DecimalHundred; } else if (dr < 1000) { decimals = s.DecimalThousand; } else if (dr < 1000000) { decimals = s.DecimalMillion; } else { decimals = s.DecimalBillion; } sb.Append(" "); sb.Append(this.Case(i, s.Integer[0], s.Integer[1], s.Integer[2])); sb.Append(" и "); sb.Append(this.ToString(d, Case, Gender, Animate)); sb.Append(" "); sb.Append(this.Case(d, decimals[0], decimals[1], decimals[2])); } return(sb.ToString()); }
public CyrResult Decline(decimal Value, GendersEnum Gender, AnimatesEnum Animate) { CyrResult result = new CyrResult( this.ToString(Value, CasesEnum.Nominative, Gender, Animate), this.ToString(Value, CasesEnum.Genitive, Gender, Animate), this.ToString(Value, CasesEnum.Dative, Gender, Animate), this.ToString(Value, CasesEnum.Accusative, Gender, Animate), this.ToString(Value, CasesEnum.Instrumental, Gender, Animate), this.ToString(Value, CasesEnum.Prepositional, Gender, Animate) ); return(result); }
public AnimateModel(AnimatesEnum value) { this.Value = value; switch (value) { case AnimatesEnum.Animated: this.Name = "Одушевленный предмет"; break; case AnimatesEnum.Inanimated: this.Name = "Неодушевленный предмет"; break; default: this.Name = null; break; } }
public CyrNoun(string name, string collectionName, GendersEnum gender, AnimatesEnum animate, WordTypesEnum type, CyrRule[] rules) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } if (rules == null) { throw new ArgumentNullException(nameof(rules)); } if (rules.Length % rulesPerNoun != 0) { throw new ArgumentException(nameof(rules), $"Noun rules collection must have {rulesPerNoun} * N elements."); } this.Name = name; this.Gender = gender; this.Animate = animate; this.WordType = type; this.rules = rules; }
public Strings(CasesEnum Case, GendersEnum Gender, AnimatesEnum Animate) { switch (Case) { case CasesEnum.Nominative: this.Hundreds = new string[] { "сто", "двести", "триста", "четыреста", "пятьсот", "шестьсот", "семьсот", "восемьсот", "девятьсот" }; this.Tens = new string[] { "десять", "двадцать", "тридцать", "сорок", "пятьдесят", "шестьдесят", "семьдесят", "восемьдесят", "девяносто" }; this.Numbers = new string[] { "один", "два", "три", "четыре", "пять", "шесть", "семь", "восемь", "девять", "десять", "одиннадцать", "двенадцать", "тринадцать", "четырнадцать", "пятнадцать", "шестнадцать", "семнадцать", "восемнадцать", "девятнадцать" }; this.Thousand = new string[] { "тысяча", "тысячи", "тысяч" }; this.Million = new string[] { "миллион", "миллиона", "миллионов" }; this.Billion = new string[] { "миллиард", "миллиарда", "миллиардов" }; this.Zero = "ноль"; if (Gender == GendersEnum.Feminine) { this.Integer = new string[] { "целая", "целые", "целых" }; this.DecimalTen = new string[] { "десятая", "десятые", "десятых" }; this.DecimalHundred = new string[] { "сотая", "сотые", "сотых" }; this.DecimalThousand = new string[] { "тысячная", "тысячные", "тысячных" }; this.DecimalMillion = new string[] { "миллионная", "миллионные", "миллионных" }; this.DecimalBillion = new string[] { "миллиардная", "миллиардные", "миллиардных" }; } else { this.Integer = new string[] { "целый", "целых", "целых" }; this.DecimalTen = new string[] { "десятый", "десятых", "десятых" }; this.DecimalHundred = new string[] { "сотый", "сотых", "сотых" }; this.DecimalThousand = new string[] { "тысячный", "тысячных", "тысячных" }; this.DecimalMillion = new string[] { "миллионный", "миллионных", "миллионных" }; this.DecimalBillion = new string[] { "миллиардный", "миллиардных", "миллиардных" }; } break; case CasesEnum.Genitive: this.Hundreds = new string[] { "ста", "двухсот", "трехсот", "четырехсот", "пятисот", "шестисот", "семисот", "восьмисот", "девятисот" }; this.Tens = new string[] { "десяти", "двадцати", "тридцати", "сорока", "пятидесяти", "шестидесяти", "семидесяти", "весьмидесяти", "девяноста" }; this.Numbers = new string[] { "одного", "двух", "трех", "четырех", "пяти", "шести", "семи", "восьми", "девяти", "десяти", "одиннадцати", "двенадцати", "тринадцати", "четырнадцати", "пятнадцати", "шестнадцати", "семнадцати", "восемнадцати", "девятнадцати" }; this.Thousand = new string[] { "тысячи", "тысячь", "тысячь" }; this.Million = new string[] { "миллиона", "миллионов", "миллионов" }; this.Billion = new string[] { "миллиарда", "миллиардов", "миллиардов" }; this.Zero = "ноля"; if (Gender == GendersEnum.Feminine) { this.Integer = new string[] { "целой", "целыми", "целыми" }; this.DecimalTen = new string[] { "десятой", "десятых", "десятых" }; this.DecimalHundred = new string[] { "сотой", "сотых", "сотых" }; this.DecimalThousand = new string[] { "тысячной", "тысячных", "тысячных" }; this.DecimalMillion = new string[] { "миллионной", "миллионных", "миллионных" }; this.DecimalBillion = new string[] { "миллиардной", "миллиардных", "миллиардных" }; } else { this.Integer = new string[] { "целого", "целых", "целых" }; this.DecimalTen = new string[] { "десятого", "десятых", "десятых" }; this.DecimalHundred = new string[] { "сотого", "сотых", "сотых" }; this.DecimalThousand = new string[] { "тысячного", "тысячных", "тысячных" }; this.DecimalMillion = new string[] { "миллионного", "миллионных", "миллионных" }; this.DecimalBillion = new string[] { "миллиардного", "миллиардных", "миллиардных" }; } break; case CasesEnum.Dative: this.Hundreds = new string[] { "ста", "двумстам", "тремстам", "четыремстам", "пятистам", "шестистам", "семистам", "восьмистам", "девятистам" }; this.Tens = new string[] { "десяти", "двадцати", "тридцати", "сорока", "пятидесяти", "шестидесяти", "семидесяти", "весьмидесяти", "девяноста" }; this.Numbers = new string[] { "одному", "двум", "трем", "четырем", "пяти", "шести", "семи", "восьми", "девяти", "десяти", "одиннадцати", "двенадцати", "тринадцати", "четырнадцати", "пятнадцати", "шестнадцати", "семнадцати", "восемнадцати", "девятнадцати" }; this.Thousand = new string[] { "тысяче", "тысячам", "тысячам" }; this.Million = new string[] { "миллиону", "миллионам", "миллионам" }; this.Billion = new string[] { "миллиарду", "миллиардам", "миллиардам" }; this.Zero = "ноля"; if (Gender == GendersEnum.Feminine) { this.Integer = new string[] { "целой", "целым", "целым" }; this.DecimalTen = new string[] { "десятой", "десятым", "десятым" }; this.DecimalHundred = new string[] { "сотой", "сотым", "сотым" }; this.DecimalThousand = new string[] { "тысячной", "тысячным", "тысячным" }; this.DecimalMillion = new string[] { "миллионной", "миллионным", "миллионным" }; this.DecimalBillion = new string[] { "миллиардной", "миллиардным", "миллиардным" }; } else { this.Integer = new string[] { "целому", "целым", "целым" }; this.DecimalTen = new string[] { "десятому", "десятым", "десятым" }; this.DecimalHundred = new string[] { "сотому", "сотым", "сотым" }; this.DecimalThousand = new string[] { "тысячному", "тысячным", "тысячным" }; this.DecimalMillion = new string[] { "миллионному", "миллионным", "миллионным" }; this.DecimalBillion = new string[] { "миллиардному", "миллиардным", "миллиардным" }; } break; case CasesEnum.Accusative: this.Hundreds = new string[] { "сто", "двести", "триста", "четыреста", "пятьсот", "шестьсот", "семьсот", "восемьсот", "девятьсот" }; this.Tens = new string[] { "десять", "двадцать", "тридцать", "сорок", "пятьдесят", "шестьдесят", "семьдесят", "восемьдесят", "девяносто" }; if (Animate == AnimatesEnum.Animated) { this.Numbers = new string[] { "одного", "двух", "трех", "четырех", "пять", "шести", "семи", "восьми", "девяти", "десяти", "одиннадцати", "двенадцати", "тринадцати", "четырнадцати", "пятнадцати", "шестнадцати", "семнадцати", "восемнадцати", "девятнадцати" }; } else { this.Numbers = new string[] { "один", "два", "три", "четыре", "пять", "шесть", "семь", "восемь", "девять", "десять", "одиннадцать", "двенадцать", "тринадцать", "четырнадцать", "пятнадцать", "шестнадцать", "семнадцать", "восемнадцать", "девятнадцать" }; } this.Thousand = new string[] { "тысячу", "тысячи", "тысяч" }; this.Million = new string[] { "миллион", "миллиона", "миллионов" }; this.Billion = new string[] { "миллиард", "миллиарда", "миллиардов" }; this.Zero = "ноль"; if (Gender == GendersEnum.Feminine) { this.Integer = new string[] { "целую", "целые", "целых" }; this.DecimalTen = new string[] { "десятую", "десятых", "десятых" }; this.DecimalHundred = new string[] { "сотую", "сотых", "сотых" }; this.DecimalThousand = new string[] { "тысячную", "тысячных", "тысячных" }; this.DecimalMillion = new string[] { "миллионную", "миллионныех", "миллионных" }; this.DecimalBillion = new string[] { "миллиардную", "миллиардных", "миллиардных" }; } else { this.Integer = new string[] { "целого", "целых", "целых" }; this.DecimalTen = new string[] { "десятый", "десятых", "десятых" }; this.DecimalHundred = new string[] { "сотый", "сотых", "сотых" }; this.DecimalThousand = new string[] { "тысячный", "тысячных", "тысячных" }; this.DecimalMillion = new string[] { "миллионный", "миллионныех", "миллионных" }; this.DecimalBillion = new string[] { "миллиардный", "миллиардных", "миллиардных" }; } break; case CasesEnum.Instrumental: this.Hundreds = new string[] { "ста", "двумястами", "тремястами", "четырьмястами", "пятьюстами", "шестьюстами", "семьюстами", "восьмьюстами", "девятьюстами" }; this.Tens = new string[] { "десятью", "двадцатью", "тридцатью", "сорока", "пятьюдесятью", "шестьюдесятью", "семьюдесятью", "восьмьюдесятью", "девяноста" }; this.Numbers = new string[] { "одним", "двумя", "тремя", "четырьмя", "пятью", "шестью", "семью", "восемью", "девятью", "десятью", "одиннадцатью", "двенадцатью", "тринадцатью", "четырнадцатью", "пятнадцатью", "шестнадцатью", "семнадцатью", "восемнадцатью", "девятнадцатью" }; this.Thousand = new string[] { "тысячей", "тысячами", "тысячами" }; this.Million = new string[] { "миллионом", "миллионами", "миллионами" }; this.Billion = new string[] { "миллиардом", "миллиардами", "миллиардами" }; this.Zero = "нолем"; if (Gender == GendersEnum.Feminine) { this.Integer = new string[] { "целой", "целыми", "целыми" }; this.DecimalTen = new string[] { "десятой", "десятыми", "десятыми" }; this.DecimalHundred = new string[] { "сотой", "сотыми", "сотыми" }; this.DecimalThousand = new string[] { "тысячной", "тысячными", "тысячными" }; this.DecimalMillion = new string[] { "миллионной", "миллионными", "миллионными" }; this.DecimalBillion = new string[] { "миллиардной", "миллиардными", "миллиардными" }; } else { this.Integer = new string[] { "целым", "целыми", "целыми" }; this.DecimalTen = new string[] { "десятым", "десятыми", "десятыми" }; this.DecimalHundred = new string[] { "сотым", "сотыми", "сотыми" }; this.DecimalThousand = new string[] { "тысячным", "тысячными", "тысячными" }; this.DecimalMillion = new string[] { "миллионным", "миллионными", "миллионными" }; this.DecimalBillion = new string[] { "миллиардным", "миллиардными", "миллиардными" }; } break; case CasesEnum.Prepositional: this.Hundreds = new string[] { "ста", "двухстах", "трехстах", "четырехстах", "пятистах", "шестистах", "семистах", "восьмистах", "девятистах" }; this.Tens = new string[] { "десяти", "двадцати", "тридцати", "сорока", "пятидесяти", "шестидесяти", "семидесяти", "восьмидесяти", "девяноста" }; this.Numbers = new string[] { "одном", "двух", "трех", "четырех", "пяти", "шести", "семи", "восеми", "девяти", "десяти", "одиннадцати", "двенадцати", "тринадцати", "четырнадцати", "пятнадцати", "шестнадцати", "семнадцати", "восемнадцати", "девятнадцати" }; this.Thousand = new string[] { "тысяче", "тысячах", "тысячах" }; this.Million = new string[] { "миллионе", "миллионах", "миллионах" }; this.Billion = new string[] { "миллиарде", "миллиардах", "миллиардах" }; this.Zero = "ноле"; if (Gender == GendersEnum.Feminine) { this.Integer = new string[] { "целой", "целых", "целых" }; this.DecimalTen = new string[] { "десятой", "десятых", "десятых" }; this.DecimalHundred = new string[] { "сотой", "сотых", "сотых" }; this.DecimalThousand = new string[] { "тысячной", "тысячных", "тысячных" }; this.DecimalMillion = new string[] { "миллионной", "миллионных", "миллионных" }; this.DecimalBillion = new string[] { "миллиардной", "миллиардных", "миллиардных" }; } else { this.Integer = new string[] { "целом", "целых", "целых" }; this.DecimalTen = new string[] { "десятом", "десятых", "десятых" }; this.DecimalHundred = new string[] { "сотом", "сотых", "сотых" }; this.DecimalThousand = new string[] { "тысячном", "тысячных", "тысячных" }; this.DecimalMillion = new string[] { "миллионном", "миллионных", "миллионных" }; this.DecimalBillion = new string[] { "миллиардном", "миллиардных", "миллиардных" }; } break; } if (Gender == GendersEnum.Feminine) { switch (Case) { case CasesEnum.Nominative: this.Numbers[0] = "одна"; this.Numbers[1] = "две"; break; case CasesEnum.Genitive: this.Numbers[0] = "одной"; this.Numbers[1] = "двух"; break; case CasesEnum.Dative: this.Numbers[0] = "одной"; this.Numbers[1] = "двум"; break; case CasesEnum.Accusative: this.Numbers[0] = "одну"; if (Animate == AnimatesEnum.Animated) { this.Numbers[1] = "двух"; } else { this.Numbers[1] = "две"; } break; case CasesEnum.Instrumental: this.Numbers[0] = "одной"; this.Numbers[1] = "двумя"; break; case CasesEnum.Prepositional: this.Numbers[0] = "одной"; this.Numbers[1] = "двух"; break; } } else if (Gender == GendersEnum.Neuter) { switch (Case) { case CasesEnum.Nominative: this.Numbers[0] = "одно"; break; case CasesEnum.Genitive: this.Numbers[0] = "одного"; break; case CasesEnum.Dative: this.Numbers[0] = "одному"; break; case CasesEnum.Accusative: this.Numbers[0] = "одно"; break; case CasesEnum.Instrumental: this.Numbers[0] = "одним"; break; case CasesEnum.Prepositional: this.Numbers[0] = "одном"; break; } } }
public CyrNoun(string name, GendersEnum gender, AnimatesEnum animate, WordTypesEnum type, CyrRule[] rules) : this(name, name, gender, animate, type, rules) { }
/// <summary> /// Поиск прилагательного по неточному совпадению с указанием рода, падежа, числа и одушевленности. /// Возвращает null если слово не было найдено. /// </summary> /// <param name="word">Прилагательное.</param> /// <param name="foundWord">Прилагательное, найденное в словаре.</param> /// <param name="gender">Род, в котором указано прилагательное.</param> /// <param name="case">Падеж, в котором указано прилагательное.</param> /// <param name="number">Число, в котором указано прилагательное.</param> /// <param name="animate">Одушевленность прилагательного.</param> /// <returns></returns> public CyrAdjective GetOrDefault(string word, out string foundWord, GendersEnum gender, CasesEnum @case, NumbersEnum number, AnimatesEnum animate) { CyrAdjective adjective = this.GetOrDefault(word, gender, @case, number, animate); if (adjective != null) { foundWord = word; return(new CyrAdjective(adjective)); } foundWord = this.GetSimilar(word, this.AdjectiveMinSameLetters, this.AdjectiveMaxSameLetters); if (string.IsNullOrEmpty(foundWord)) { return(null); } adjective = this.GetOrDefault(foundWord, gender, @case, number, animate); if (adjective != null) { adjective = new CyrAdjective(adjective); adjective.SetName(word, gender, @case, number, animate); return(adjective); } return(null); }
public string ToString(long Value, CasesEnum Case, GendersEnum Gender, AnimatesEnum Animate) { if (Value > 9999999999) { throw new ArgumentOutOfRangeException("The maximum value is 9999999999."); } Strings s = new Strings(Case, Gender, Animate); if (Value == 0) { return(s.Zero); } StringBuilder r = new StringBuilder(); long v; if (Value < 0) { r.Append("минус "); Value = Math.Abs(Value); } v = Value / 1000000000; if (v > 0) { r.Append(this.ToString(v, Case, GendersEnum.Masculine, Animate)).Append(" ").Append(this.Case(v, s.Billion[0], s.Billion[1], s.Billion[2])).Append(" "); Value = Value - 1000000000 * v; } v = Value / 1000000; if (v > 0) { r.Append(this.ToString(v, Case, GendersEnum.Masculine, Animate)).Append(" ").Append(this.Case(v, s.Million[0], s.Million[1], s.Million[2])).Append(" "); Value = Value - 1000000 * v; } v = Value / 1000; if (v > 0) { r.Append(this.ToString(v, Case, GendersEnum.Feminine, Animate)).Append(" ").Append(this.Case(v, s.Thousand[0], s.Thousand[1], s.Thousand[2])).Append(" "); Value = Value - 1000 * v; } v = Value / 100; if (v > 0) { r.Append(s.Hundreds[v - 1]).Append(" "); Value = Value - 100 * v; } if (Value >= 20 || Value == 10) { v = Value / 10; r.Append(s.Tens[v - 1]).Append(" "); Value = Value - v * 10; } if (Value > 0) { r.Append(s.Numbers[Value - 1]); } return(r.ToString().Trim(' ')); }
/// <summary> /// Поиск прилагательного по неточному совпадению с автоматическим определением рода, падежа, числа и одушевленности. /// Выбрасывает <see cref="CyrWordNotFoundException"/> если слово не было найдено. /// </summary> /// <param name="word">Прилагательное в любом роде, числе и падеже.</param> /// <param name="foundWord">Прилагательное, найденное в словаре.</param> /// <param name="gender">Род найденного прилагательного.</param> /// <param name="number">Число найденного прилагательного.</param> /// <param name="case">Падеж найденного прилагательного.</param> /// <returns></returns> public CyrAdjective Get(string word, out string foundWord, out GendersEnum gender, out CasesEnum @case, out NumbersEnum number, out AnimatesEnum animate) { CyrAdjective adjective = this.GetOrDefault(word, out foundWord, out gender, out @case, out number, out animate); if (adjective == null) { throw new CyrWordNotFoundException(word, gender, @case, number, animate); } return(adjective); }
public CyrWordNotFoundException(string word, GendersEnum gender, CasesEnum @case, NumbersEnum number, AnimatesEnum animate) : base($"The word was not found in the collection. Word: [{word}], gender: [{gender}], case: [{@case}], number: [{number}], animte: [{animate}].") { this.Word = word; this.Gender = gender; this.Case = @case; this.Number = number; this.Animate = animate; }
public Strings(CasesEnum Case, GendersEnum Gender, AnimatesEnum Animate) { switch (Case) { case CasesEnum.Nominative: this.Hundreds = new string[] { "сто", "двести", "триста", "четыреста", "пятьсот", "шестьсот", "семьсот", "восемьсот", "девятьсот" }; this.Tens = new string[] { "десять", "двадцать", "тридцать", "сорок", "пятьдесят", "шестьдесят", "семьдесят", "восемьдесят", "девяносто" }; this.Numbers = new string[] { "один", "два", "три", "четыре", "пять", "шесть", "семь", "восемь", "девять", "десять", "одиннадцать", "двенадцать", "тринадцать", "четырнадцать", "пятнадцать", "шестнадцать", "семнадцать", "восемнадцать", "девятнадцать" }; this.Thousand = new string[] { "тысяча", "тысячи", "тысяч" }; this.Million = new string[] { "миллион", "миллиона", "миллионов" }; this.Billion = new string[] { "миллиард", "миллиарда", "миллиардов" }; this.Zero = "ноль"; if (Gender == GendersEnum.Feminine) { this.Integer = new string[] { "целая", "целые", "целых" }; this.DecimalTen = new string[] { "десятая", "десятые", "десятых" }; this.DecimalHundred = new string[] { "сотая", "сотые", "сотых" }; this.DecimalThousand = new string[] { "тысячная", "тысячные", "тысячных" }; this.DecimalMillion = new string[] { "миллионная", "миллионные", "миллионных" }; this.DecimalBillion = new string[] { "миллиардная", "миллиардные", "миллиардных" }; } else { this.Integer = new string[] { "целый", "целых", "целых" }; this.DecimalTen = new string[] { "десятый", "десятых", "десятых" }; this.DecimalHundred = new string[] { "сотый", "сотых", "сотых" }; this.DecimalThousand = new string[] { "тысячный", "тысячных", "тысячных" }; this.DecimalMillion = new string[] { "миллионный", "миллионных", "миллионных" }; this.DecimalBillion = new string[] { "миллиардный", "миллиардных", "миллиардных" }; } break; case CasesEnum.Genitive: this.Hundreds = new string[] { "ста", "двухсот", "трехсот", "четырехсот", "пятисот", "шестисот", "семисот", "восьмисот", "девятисот" }; this.Tens = new string[] { "десяти", "двадцати", "тридцати", "сорока", "пятидесяти", "шестидесяти", "семидесяти", "весьмидесяти", "девяноста" }; this.Numbers = new string[] { "одного", "двух", "трех", "четырех", "пяти", "шести", "семи", "восьми", "девяти", "десяти", "одиннадцати", "двенадцати", "тринадцати", "четырнадцати", "пятнадцати", "шестнадцати", "семнадцати", "восемнадцати", "девятнадцати" }; this.Thousand = new string[] { "тысячи", "тысяч", "тысяч" }; this.Million = new string[] { "миллиона", "миллионов", "миллионов" }; this.Billion = new string[] { "миллиарда", "миллиардов", "миллиардов" }; this.Zero = "ноля"; if (Gender == GendersEnum.Feminine) { this.Integer = new string[] { "целой", "целыми", "целыми" }; this.DecimalTen = new string[] { "десятой", "десятых", "десятых" }; this.DecimalHundred = new string[] { "сотой", "сотых", "сотых" }; this.DecimalThousand = new string[] { "тысячной", "тысячных", "тысячных" }; this.DecimalMillion = new string[] { "миллионной", "миллионных", "миллионных" }; this.DecimalBillion = new string[] { "миллиардной", "миллиардных", "миллиардных" }; } else { this.Integer = new string[] { "целого", "целых", "целых" }; this.DecimalTen = new string[] { "десятого", "десятых", "десятых" }; this.DecimalHundred = new string[] { "сотого", "сотых", "сотых" }; this.DecimalThousand = new string[] { "тысячного", "тысячных", "тысячных" }; this.DecimalMillion = new string[] { "миллионного", "миллионных", "миллионных" }; this.DecimalBillion = new string[] { "миллиардного", "миллиардных", "миллиардных" }; } break; case CasesEnum.Dative: this.Hundreds = new string[] { "ста", "двумстам", "тремстам", "четыремстам", "пятистам", "шестистам", "семистам", "восьмистам", "девятистам" }; this.Tens = new string[] { "десяти", "двадцати", "тридцати", "сорока", "пятидесяти", "шестидесяти", "семидесяти", "весьмидесяти", "девяноста" }; this.Numbers = new string[] { "одному", "двум", "трем", "четырем", "пяти", "шести", "семи", "восьми", "девяти", "десяти", "одиннадцати", "двенадцати", "тринадцати", "четырнадцати", "пятнадцати", "шестнадцати", "семнадцати", "восемнадцати", "девятнадцати" }; this.Thousand = new string[] { "тысяче", "тысячам", "тысячам" }; this.Million = new string[] { "миллиону", "миллионам", "миллионам" }; this.Billion = new string[] { "миллиарду", "миллиардам", "миллиардам" }; this.Zero = "ноля"; if (Gender == GendersEnum.Feminine) { this.Integer = new string[] { "целой", "целым", "целым" }; this.DecimalTen = new string[] { "десятой", "десятым", "десятым" }; this.DecimalHundred = new string[] { "сотой", "сотым", "сотым" }; this.DecimalThousand = new string[] { "тысячной", "тысячным", "тысячным" }; this.DecimalMillion = new string[] { "миллионной", "миллионным", "миллионным" }; this.DecimalBillion = new string[] { "миллиардной", "миллиардным", "миллиардным" }; } else { this.Integer = new string[] { "целому", "целым", "целым" }; this.DecimalTen = new string[] { "десятому", "десятым", "десятым" }; this.DecimalHundred = new string[] { "сотому", "сотым", "сотым" }; this.DecimalThousand = new string[] { "тысячному", "тысячным", "тысячным" }; this.DecimalMillion = new string[] { "миллионному", "миллионным", "миллионным" }; this.DecimalBillion = new string[] { "миллиардному", "миллиардным", "миллиардным" }; } break; case CasesEnum.Accusative: this.Hundreds = new string[] { "сто", "двести", "триста", "четыреста", "пятьсот", "шестьсот", "семьсот", "восемьсот", "девятьсот" }; this.Tens = new string[] { "десять", "двадцать", "тридцать", "сорок", "пятьдесят", "шестьдесят", "семьдесят", "восемьдесят", "девяносто" }; if (Animate == AnimatesEnum.Animated) { this.Numbers = new string[] { "одного", "двух", "трех", "четырех", "пять", "шести", "семи", "восьми", "девяти", "десяти", "одиннадцати", "двенадцати", "тринадцати", "четырнадцати", "пятнадцати", "шестнадцати", "семнадцати", "восемнадцати", "девятнадцати" }; } else { this.Numbers = new string[] { "один", "два", "три", "четыре", "пять", "шесть", "семь", "восемь", "девять", "десять", "одиннадцать", "двенадцать", "тринадцать", "четырнадцать", "пятнадцать", "шестнадцать", "семнадцать", "восемнадцать", "девятнадцать" }; } this.Thousand = new string[] { "тысячу", "тысячи", "тысяч" }; this.Million = new string[] { "миллион", "миллиона", "миллионов" }; this.Billion = new string[] { "миллиард", "миллиарда", "миллиардов" }; this.Zero = "ноль"; if (Gender == GendersEnum.Feminine) { this.Integer = new string[] { "целую", "целые", "целых" }; this.DecimalTen = new string[] { "десятую", "десятых", "десятых" }; this.DecimalHundred = new string[] { "сотую", "сотых", "сотых" }; this.DecimalThousand = new string[] { "тысячную", "тысячных", "тысячных" }; this.DecimalMillion = new string[] { "миллионную", "миллионныех", "миллионных" }; this.DecimalBillion = new string[] { "миллиардную", "миллиардных", "миллиардных" }; } else { this.Integer = new string[] { "целого", "целых", "целых" }; this.DecimalTen = new string[] { "десятый", "десятых", "десятых" }; this.DecimalHundred = new string[] { "сотый", "сотых", "сотых" }; this.DecimalThousand = new string[] { "тысячный", "тысячных", "тысячных" }; this.DecimalMillion = new string[] { "миллионный", "миллионныех", "миллионных" }; this.DecimalBillion = new string[] { "миллиардный", "миллиардных", "миллиардных" }; } break; case CasesEnum.Instrumental: this.Hundreds = new string[] { "ста", "двумястами", "тремястами", "четырьмястами", "пятьюстами", "шестьюстами", "семьюстами", "восьмьюстами", "девятьюстами" }; this.Tens = new string[] { "десятью", "двадцатью", "тридцатью", "сорока", "пятьюдесятью", "шестьюдесятью", "семьюдесятью", "восьмьюдесятью", "девяноста" }; this.Numbers = new string[] { "одним", "двумя", "тремя", "четырьмя", "пятью", "шестью", "семью", "восемью", "девятью", "десятью", "одиннадцатью", "двенадцатью", "тринадцатью", "четырнадцатью", "пятнадцатью", "шестнадцатью", "семнадцатью", "восемнадцатью", "девятнадцатью" }; this.Thousand = new string[] { "тысячей", "тысячами", "тысячами" }; this.Million = new string[] { "миллионом", "миллионами", "миллионами" }; this.Billion = new string[] { "миллиардом", "миллиардами", "миллиардами" }; this.Zero = "нолем"; if (Gender == GendersEnum.Feminine) { this.Integer = new string[] { "целой", "целыми", "целыми" }; this.DecimalTen = new string[] { "десятой", "десятыми", "десятыми" }; this.DecimalHundred = new string[] { "сотой", "сотыми", "сотыми" }; this.DecimalThousand = new string[] { "тысячной", "тысячными", "тысячными" }; this.DecimalMillion = new string[] { "миллионной", "миллионными", "миллионными" }; this.DecimalBillion = new string[] { "миллиардной", "миллиардными", "миллиардными" }; } else { this.Integer = new string[] { "целым", "целыми", "целыми" }; this.DecimalTen = new string[] { "десятым", "десятыми", "десятыми" }; this.DecimalHundred = new string[] { "сотым", "сотыми", "сотыми" }; this.DecimalThousand = new string[] { "тысячным", "тысячными", "тысячными" }; this.DecimalMillion = new string[] { "миллионным", "миллионными", "миллионными" }; this.DecimalBillion = new string[] { "миллиардным", "миллиардными", "миллиардными" }; } break; case CasesEnum.Prepositional: this.Hundreds = new string[] { "ста", "двухстах", "трехстах", "четырехстах", "пятистах", "шестистах", "семистах", "восьмистах", "девятистах" }; this.Tens = new string[] { "десяти", "двадцати", "тридцати", "сорока", "пятидесяти", "шестидесяти", "семидесяти", "восьмидесяти", "девяноста" }; this.Numbers = new string[] { "одном", "двух", "трех", "четырех", "пяти", "шести", "семи", "восеми", "девяти", "десяти", "одиннадцати", "двенадцати", "тринадцати", "четырнадцати", "пятнадцати", "шестнадцати", "семнадцати", "восемнадцати", "девятнадцати" }; this.Thousand = new string[] { "тысяче", "тысячах", "тысячах" }; this.Million = new string[] { "миллионе", "миллионах", "миллионах" }; this.Billion = new string[] { "миллиарде", "миллиардах", "миллиардах" }; this.Zero = "ноле"; if (Gender == GendersEnum.Feminine) { this.Integer = new string[] { "целой", "целых", "целых" }; this.DecimalTen = new string[] { "десятой", "десятых", "десятых" }; this.DecimalHundred = new string[] { "сотой", "сотых", "сотых" }; this.DecimalThousand = new string[] { "тысячной", "тысячных", "тысячных" }; this.DecimalMillion = new string[] { "миллионной", "миллионных", "миллионных" }; this.DecimalBillion = new string[] { "миллиардной", "миллиардных", "миллиардных" }; } else { this.Integer = new string[] { "целом", "целых", "целых" }; this.DecimalTen = new string[] { "десятом", "десятых", "десятых" }; this.DecimalHundred = new string[] { "сотом", "сотых", "сотых" }; this.DecimalThousand = new string[] { "тысячном", "тысячных", "тысячных" }; this.DecimalMillion = new string[] { "миллионном", "миллионных", "миллионных" }; this.DecimalBillion = new string[] { "миллиардном", "миллиардных", "миллиардных" }; } break; } if (Gender == GendersEnum.Feminine) { switch (Case) { case CasesEnum.Nominative: this.Numbers[0] = "одна"; this.Numbers[1] = "две"; break; case CasesEnum.Genitive: this.Numbers[0] = "одной"; this.Numbers[1] = "двух"; break; case CasesEnum.Dative: this.Numbers[0] = "одной"; this.Numbers[1] = "двум"; break; case CasesEnum.Accusative: this.Numbers[0] = "одну"; if (Animate == AnimatesEnum.Animated) { this.Numbers[1] = "двух"; } else { this.Numbers[1] = "две"; } break; case CasesEnum.Instrumental: this.Numbers[0] = "одной"; this.Numbers[1] = "двумя"; break; case CasesEnum.Prepositional: this.Numbers[0] = "одной"; this.Numbers[1] = "двух"; break; } } else if (Gender == GendersEnum.Neuter) { switch (Case) { case CasesEnum.Nominative: this.Numbers[0] = "одно"; break; case CasesEnum.Genitive: this.Numbers[0] = "одного"; break; case CasesEnum.Dative: this.Numbers[0] = "одному"; break; case CasesEnum.Accusative: this.Numbers[0] = "одно"; break; case CasesEnum.Instrumental: this.Numbers[0] = "одним"; break; case CasesEnum.Prepositional: this.Numbers[0] = "одном"; break; } } }
public CyrNoun(string Name, GendersEnum Gender, AnimatesEnum Animate, WordTypesEnum Type, CyrRule[] Rules) : this(Name, Name, Gender, Animate, Type, Rules) { }
public CyrResult DeclinePlural(AnimatesEnum Animate) { CyrResult result = new CyrResult(this.rules[17].Apply(this.name), this.rules[18].Apply(this.name), this.rules[19].Apply(this.name), Animate == AnimatesEnum.Animated ? this.rules[21].Apply(this.name) : this.rules[17].Apply(this.name), this.rules[20].Apply(this.name), this.rules[21].Apply(this.name)); return result; }
public void Decline() { this.InputText = this.inputText?.Trim(); if (string.IsNullOrEmpty(this.InputText)) { return; } CyrAdjective adj = null; string foundWord = null; GendersEnum foundGender = GendersEnum.Undefined; CasesEnum foundCase = CasesEnum.Nominative; string foundCaseName = null; NumbersEnum foundNumber = NumbersEnum.Singular; AnimatesEnum foundAnimate = AnimatesEnum.Animated; if (this.IsStrictSearch && !this.IsManualPropertiesInput) { adj = this.CyrAdjectiveCollection.GetOrDefault(this.InputText, out foundGender, out foundCase, out foundNumber, out foundAnimate); } else if (!this.IsStrictSearch && !this.IsManualPropertiesInput) { adj = this.CyrAdjectiveCollection.GetOrDefault(this.InputText, out foundWord, out foundGender, out foundCase, out foundNumber, out foundAnimate); } else if (this.IsStrictSearch && this.IsManualPropertiesInput) { foundGender = InputGender.Value; foundCase = InputCase.Value; foundNumber = InputNumber.Value; foundAnimate = InputAnimate.Value; adj = this.CyrAdjectiveCollection.GetOrDefault(this.InputText, foundGender, foundCase, foundNumber, foundAnimate); } else if (!this.IsStrictSearch && this.IsManualPropertiesInput) { foundGender = InputGender.Value; foundCase = InputCase.Value; foundNumber = InputNumber.Value; foundAnimate = InputAnimate.Value; adj = this.CyrAdjectiveCollection.GetOrDefault(this.InputText, out foundWord, foundGender, foundCase, foundNumber, foundAnimate); } this.DeclineResult = new List <AdjectiveDeclineResultRowModel>(); this.WordProperties = new List <KeyValuePair <string, string> >(); this.RaisePropertyChanged(nameof(DeclineResult)); this.RaisePropertyChanged(nameof(WordProperties)); if (adj == null) { this.IsDeclineResultVisible = false; this.SearchResultTitle = $"По запросу \"{this.InputText}\" ничего не найдено"; return; } Dictionary <KeyValuePair <GendersEnum, AnimatesEnum>, CyrResult> results = new System.Collections.Generic.Dictionary <KeyValuePair <GendersEnum, AnimatesEnum>, CyrResult>(); foreach (GenderModel gender in this.Genders) { foreach (AnimateModel animate in this.Animates) { KeyValuePair <GendersEnum, AnimatesEnum> key = new KeyValuePair <GendersEnum, AnimatesEnum>(gender.Value, animate.Value); CyrResult value; if (gender.Value == GendersEnum.Undefined) { value = adj.DeclinePlural(animate.Value); } else { value = adj.Decline(gender.Value, animate.Value); } results.Add(key, value); } } foreach (CyrDeclineCase @case in CyrDeclineCase.GetEnumerable()) { if (@case.Value == foundCase) { foundCaseName = @case.NameRu; } AdjectiveDeclineResultRowModel row = new AdjectiveDeclineResultRowModel() { CaseName = @case.NameRu, CaseDescription = @case.Description }; row.SingularMasculineAnimate = results[new KeyValuePair <GendersEnum, AnimatesEnum>(GendersEnum.Masculine, AnimatesEnum.Animated)].Get(@case.Value); row.SingularFeminineAnimate = results[new KeyValuePair <GendersEnum, AnimatesEnum>(GendersEnum.Feminine, AnimatesEnum.Animated)].Get(@case.Value); row.SingularNeuterAnimate = results[new KeyValuePair <GendersEnum, AnimatesEnum>(GendersEnum.Neuter, AnimatesEnum.Animated)].Get(@case.Value); row.SingularMasculineInanimate = results[new KeyValuePair <GendersEnum, AnimatesEnum>(GendersEnum.Masculine, AnimatesEnum.Inanimated)].Get(@case.Value); row.SingularFeminineInanimate = results[new KeyValuePair <GendersEnum, AnimatesEnum>(GendersEnum.Feminine, AnimatesEnum.Inanimated)].Get(@case.Value); row.SingularNeuterInanimate = results[new KeyValuePair <GendersEnum, AnimatesEnum>(GendersEnum.Neuter, AnimatesEnum.Inanimated)].Get(@case.Value); row.PluralAnimate = results[new KeyValuePair <GendersEnum, AnimatesEnum>(GendersEnum.Undefined, AnimatesEnum.Animated)].Get(@case.Value); row.PluralInanimate = results[new KeyValuePair <GendersEnum, AnimatesEnum>(GendersEnum.Undefined, AnimatesEnum.Inanimated)].Get(@case.Value); this.DeclineResult.Add(row); } this.WordProperties.Add(new KeyValuePair <string, string>("Слово в словаре", foundWord)); this.WordProperties.Add(new KeyValuePair <string, string>("Род", new GenderModel(foundGender).Name)); this.WordProperties.Add(new KeyValuePair <string, string>("Падеж", foundCaseName)); this.WordProperties.Add(new KeyValuePair <string, string>("Число", new NumberModel(foundNumber).Name)); this.WordProperties.Add(new KeyValuePair <string, string>("Одушевленность", new AnimateModel(foundAnimate).Name)); this.IsDeclineResultVisible = true; this.SearchResultTitle = $"Результат поиска по запросу \"{this.InputText}\""; }
/// <summary> /// Поиск прилагательного по точному совпадению с указанием рода, падежа, числа и одушевленности. /// Возвращает null если слово не было найдено. /// </summary> /// <param name="word">Прилагательное.</param> /// <param name="gender">Род, в котором указано прилагательное.</param> /// <param name="case">Падеж, в котором указано прилагательное.</param> /// <param name="number">Число, в котором указано прилагательное.</param> /// <param name="animate">Одушевленность прилагательного.</param> /// <returns></returns> public CyrAdjective GetOrDefault(string word, GendersEnum gender, CasesEnum @case, NumbersEnum number, AnimatesEnum animate) { DictionaryKey key = new DictionaryKey(word, gender, @case, number, animate); CyrAdjective adjective; if (this.words.TryGetValue(key, out adjective)) { return(new CyrAdjective(adjective)); } return(null); }
/// <summary> /// Поиск прилагательного по точному совпадению с автоматическим определением рода, падежа, числа и одушевленности. /// Возвращает null если слово не было найдено. /// </summary> /// <param name="word">Прилагательное в любом роде, числе и падеже.</param> /// <param name="gender">Род найденного прилагательного.</param> /// <param name="number">Число найденного прилагательного.</param> /// <param name="case">Падеж найденного прилагательного.</param> /// <returns></returns> public CyrAdjective GetOrDefault(string word, out GendersEnum gender, out CasesEnum @case, out NumbersEnum number, out AnimatesEnum animate) { DictionaryKey key; CyrAdjective adjective; foreach (AnimatesEnum a in this.animates) { foreach (GendersEnum g in this.genders) { foreach (CasesEnum c in this.cases) { key = new DictionaryKey(word, g, c, NumbersEnum.Singular, a); if (this.words.TryGetValue(key, out adjective)) { gender = key.Gender; @case = key.Case; number = key.Number; animate = key.Animate; return(adjective); } } } foreach (CasesEnum c in this.cases) { key = new DictionaryKey(word, 0, c, NumbersEnum.Plural, a); if (this.words.TryGetValue(key, out adjective)) { gender = key.Gender; @case = key.Case; number = key.Number; animate = key.Animate; return(adjective); } } } gender = 0; @case = 0; number = 0; animate = 0; return(null); }
public void SetName(string name, GendersEnum gender, CasesEnum @case, NumbersEnum number, AnimatesEnum animate) { CyrRule[] rules = this.GetRules(gender, number, animate); CyrRule rule = rules[(int)@case - 1]; this.Name = rule.Revert(this.Name, name); }