示例#1
0
        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);
        }
示例#2
0
 public Item(CyrNoun Noun)
 {
     this.noun     = Noun;
     this.singular = noun.Decline();
     this.plural   = noun.DeclinePlural();
 }
示例#3
0
        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;
        }
示例#4
0
        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;
        }
示例#5
0
 public void Add(CyrResult Result, string Separator = "-")
 {
     this.case1 += Separator + Result.case1;
     this.case2 += Separator + Result.case2;
     this.case3 += Separator + Result.case3;
     this.case4 += Separator + Result.case4;
     this.case5 += Separator + Result.case5;
     this.case6 += Separator + Result.case6;
 }
示例#6
0
        protected virtual void AddWordToDictionary
        (
            string line,
            List <KeyValuePair <DictionaryKey, CyrAdjective> > adjectives,
            List <string>[] masculineWordCandidates,
            List <string>[] feminineWordCandidates,
            List <string>[] neuterWordCandidates,
            List <string>[] pluralWordCandidates
        )
        {
            string[] parts = line.Split(' ');

            int ruleIndex = int.Parse(parts[1]);

            CyrRule[]    rules     = this.rules[ruleIndex];
            CyrAdjective adjective = new CyrAdjective(parts[0], rules);

            // Женский и средний род склоняются одинаково для одушевленных и неодушевленных предметов.
            {
                CyrResult result = adjective.Decline(GendersEnum.Feminine, AnimatesEnum.Animated);

                foreach (CasesEnum @case in cases)
                {
                    feminineWordCandidates[(int)@case - 1].Add(result[(int)@case]);

                    foreach (AnimatesEnum animate in this.animates)
                    {
                        DictionaryKey key = new DictionaryKey(result[(int)@case], GendersEnum.Feminine, @case, NumbersEnum.Singular, animate);
                        adjectives.Add(new KeyValuePair <DictionaryKey, CyrAdjective>(key, adjective));
                    }
                }
            }
            {
                CyrResult result = adjective.Decline(GendersEnum.Neuter, AnimatesEnum.Animated);

                foreach (CasesEnum @case in cases)
                {
                    neuterWordCandidates[(int)@case - 1].Add(result[(int)@case]);

                    foreach (AnimatesEnum animate in this.animates)
                    {
                        DictionaryKey key = new DictionaryKey(result[(int)@case], GendersEnum.Neuter, @case, NumbersEnum.Singular, animate);
                        adjectives.Add(new KeyValuePair <DictionaryKey, CyrAdjective>(key, adjective));
                    }
                }
            }

            // Мужской род и множественное число склоняются по-разному для одушевленных и неодушевленных предметов.
            foreach (AnimatesEnum animate in animates)
            {
                CyrResult result = adjective.Decline(GendersEnum.Masculine, animate);

                foreach (CasesEnum @case in cases)
                {
                    DictionaryKey key = new DictionaryKey(result[(int)@case], GendersEnum.Masculine, @case, NumbersEnum.Singular, animate);
                    adjectives.Add(new KeyValuePair <DictionaryKey, CyrAdjective>(key, adjective));
                    masculineWordCandidates[(int)@case - 1].Add(key.Name);
                }

                result = adjective.DeclinePlural(animate);

                foreach (CasesEnum @case in cases)
                {
                    DictionaryKey key = new DictionaryKey(result[(int)@case], 0, @case, NumbersEnum.Plural, animate);
                    adjectives.Add(new KeyValuePair <DictionaryKey, CyrAdjective>(key, adjective));
                    pluralWordCandidates[(int)@case - 1].Add(key.Name);
                }
            }
        }