/// <summary>
        ///
        /// </summary>
        /// <param name="Word">Прилагательное</param>
        /// <param name="Condition">Вариант поиска в словаре</param>
        /// <param name="DefaultGender">Пол, в котором указано прилагательное, используется при поиске неточных совпадений</param>
        /// <returns></returns>
        public CyrAdjective Get(string Word, GetConditionsEnum Condition, GendersEnum DefaultGender = GendersEnum.Masculine)
        {
            GendersEnum gender  = GendersEnum.Masculine;
            string      t       = Word;
            string      details = this.GetStrictDetails(ref t, ref gender);

            if (details.IsNullOrEmpty() && Condition == GetConditionsEnum.Similar)
            {
                details = this.GetSimilarDetails(Word, DefaultGender, ref gender, out t);
            }

            if (details.IsNullOrEmpty())
            {
                throw new CyrWordNotFoundException(Word);
            }

            int ruleID = int.Parse(details);

            string[] parts = this.rules[ruleID].Split(',');

            CyrRule[] rules = parts.Select(val => new CyrRule(val)).ToArray();

            if (gender == GendersEnum.Feminine)
            {
                Word = rules[22].Apply(Word);
            }
            else if (gender == GendersEnum.Neuter)
            {
                Word = rules[23].Apply(Word);
            }

            CyrAdjective adj = new CyrAdjective(Word, t, gender, rules);

            return(adj);
        }
        /// <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);
        }
Beispiel #3
0
        public CyrAdjective(CyrAdjective source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            this.Name  = source.Name;
            this.rules = source.rules;
        }
        /// <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);
        }
Beispiel #5
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);
        }
        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);
                }
            }
        }