/// <summary> /// Добавляет слово в <see cref="words"/> словарь. /// </summary> /// <param name="line"> /// Строка со словом в формате словаря. /// Смотри /Cyriller/App_Data/nouns.txt. /// </param> protected virtual void AddWordToTheCollection(string line, List <string>[] singularWordCandidates, List <string>[] pluralWordCandidates) { string[] parts = line.Split(' '); CyrNounCollectionRow row = CyrNounCollectionRow.Parse(parts[1]); CyrRule[] rules = this.rules[row.RuleID]; CyrNoun noun = new CyrNoun(parts[0], (GendersEnum)row.GenderID, (AnimatesEnum)row.AnimateID, (WordTypesEnum)row.TypeID, rules); CyrResult singular = noun.Decline(); CyrResult plural = noun.DeclinePlural(); foreach (CasesEnum @case in this.cases) { if (!string.IsNullOrEmpty(singular.Get(@case))) { DictionaryKey key = new DictionaryKey(singular.Get(@case), noun.Gender, @case, NumbersEnum.Singular); singularWordCandidates[(int)@case - 1].Add(singular.Get(@case)); this.words[key] = noun; } if (!string.IsNullOrEmpty(plural.Get(@case))) { DictionaryKey key = new DictionaryKey(plural.Get(@case), noun.Gender, @case, NumbersEnum.Plural); pluralWordCandidates[(int)@case - 1].Add(plural.Get(@case)); this.words[key] = noun; } } }
protected CyrResult Decline(string Phrase, GetConditionsEnum Condition, NumbersEnum Number) { if (Phrase.IsNullOrEmpty()) { return(new CyrResult()); } List <object> words = new List <object>(); string[] parts = Phrase.Split(' ').Select(val => val.Trim()).Where(val => val.IsNotNullOrEmpty()).ToArray(); List <CyrResult> results = new List <CyrResult>(); foreach (string w in parts) { SpeechPartsEnum speech = this.DetermineSpeechPart(w); switch (speech) { case SpeechPartsEnum.Adjective: CyrAdjective adj = this.adjCollection.Get(w, Condition); words.Add(adj); break; case SpeechPartsEnum.Noun: CyrNoun noun = this.nounCollection.Get(w, Condition); words.Add(noun); break; default: throw new ArgumentException("This speech part is not supported yet. Speech part: " + speech.ToString()); } } for (int i = 0; i < words.Count; i++) { CyrNoun noun = words[i] as CyrNoun; if (noun != null) { if (Number == NumbersEnum.Plural) { results.Add(noun.DeclinePlural()); } else { results.Add(noun.Decline()); } continue; } CyrAdjective adj = words[i] as CyrAdjective; noun = this.GetNextPreviousNoun(words, i); if (Number == NumbersEnum.Plural) { if (noun != null) { results.Add(adj.DeclinePlural(noun.Animate)); } else { results.Add(adj.DeclinePlural(AnimatesEnum.Animated)); } } else { if (noun != null) { results.Add(adj.Decline(noun.Animate)); } else { results.Add(adj.Decline(AnimatesEnum.Animated)); } } } CyrResult result = results.First(); for (int i = 1; i < results.Count; i++) { result = result + results[i]; } return(result); }
public Item(CyrNoun Noun) { this.noun = Noun; this.singular = noun.Decline(); this.plural = noun.DeclinePlural(); }