/// <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);
        }
Example #2
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);
        }
Example #3
0
 public CyrResult Decline(string Phrase, GetConditionsEnum Condition)
 {
     return(this.Decline(Phrase, Condition, NumbersEnum.Singular));
 }
Example #4
0
 public CyrResult DeclinePlural(string Phrase, GetConditionsEnum Condition)
 {
     return(this.Decline(Phrase, Condition, NumbersEnum.Plural));
 }
Example #5
0
        public CyrNoun Get(string Word, GetConditionsEnum Condition, GendersEnum?GenderID = null, AnimatesEnum?AnimateID = null, WordTypesEnum?TypeID = null)
        {
            string        t    = Word;
            List <string> list = this.GetDetails(t);

            if (list == null || !list.Any())
            {
                t    = Word.ToLower();
                list = this.GetDetails(t);
            }

            if (list == null || !list.Any())
            {
                t    = Word.ToLower().UppercaseFirst();
                list = this.GetDetails(t);
            }

            if (list == null || !list.Any())
            {
                List <int> indexes = new List <int>();
                string     lower   = Word.ToLower();

                for (int i = 0; i < lower.Length; i++)
                {
                    if (lower[i] == 'е')
                    {
                        indexes.Add(i);
                    }
                }

                foreach (int index in indexes)
                {
                    t    = lower.Substring(0, index) + "ё" + lower.Substring(index + 1);
                    list = this.GetDetails(t);

                    if (list != null && list.Any())
                    {
                        break;
                    }
                }
            }

            if ((list == null || !list.Any()) && Condition == GetConditionsEnum.Similar)
            {
                list = this.GetSimilarDetails(Word, out t);
            }

            if (list == null || !list.Any())
            {
                throw new CyrWordNotFoundException(Word);
            }

            IEnumerable <CyrNounCollectionRow> rows   = list.Select(x => CyrNounCollectionRow.Parse(x));
            IEnumerable <CyrNounCollectionRow> filter = rows;

            if (GenderID.HasValue)
            {
                filter = filter.Where(x => x.GenderID == (int)GenderID);
            }

            if (AnimateID.HasValue)
            {
                filter = filter.Where(x => x.AnimateID == (int)AnimateID);
            }

            if (TypeID.HasValue)
            {
                filter = filter.Where(x => x.TypeID == (int)TypeID);
            }

            CyrNounCollectionRow row = filter.FirstOrDefault();

            if (row == null && Condition == GetConditionsEnum.Similar)
            {
                row = rows.FirstOrDefault();
            }

            if (row == null)
            {
                throw new CyrWordNotFoundException(Word);
            }

            string[] parts = this.rules[row.RuleID].Split(new char[] { ',', '|' });

            CyrRule[] rules = parts.Select(val => new CyrRule(val)).ToArray();
            CyrNoun   noun  = new CyrNoun(Word, t, (GendersEnum)row.GenderID, (AnimatesEnum)row.AnimateID, (WordTypesEnum)row.TypeID, rules);

            return(noun);
        }
        public CyrNoun Get(string Word, GetConditionsEnum Condition)
        {
            string t = Word;
            string details = this.GetDetails(t);

            if (details.IsNullOrEmpty())
            {
                t = Word.ToLower();
                details = this.GetDetails(t);
            }

            if (details.IsNullOrEmpty())
            {
                t = Word.ToLower().UppercaseFirst();
                details = this.GetDetails(t);
            }

            if (details.IsNullOrEmpty())
            {
                List<int> indexes = new List<int>();
                string lower = Word.ToLower();

                for (int i = 0; i < lower.Length; i++)
                {
                    if (lower[i] == 'е')
                    {
                        indexes.Add(i);
                    }
                }

                foreach (int index in indexes)
                {
                    t = lower.Substring(0, index) + "ё" + lower.Substring(index + 1);
                    details = this.GetDetails(t);

                    if (details.IsNotNullOrEmpty())
                    {
                        break;
                    }
                }
            }

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

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

            string[] parts = details.Split(',');
            int genderID = int.Parse(parts[0]);
            int animateID = int.Parse(parts[1]);
            int typeID = int.Parse(parts[2]);
            int ruleID = int.Parse(parts[3]);

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

            CyrRule[] rules = parts.Select(val => new CyrRule(val)).ToArray();
            CyrNoun noun = new CyrNoun(Word, t, (GendersEnum)genderID, (AnimatesEnum)animateID, (WordTypesEnum)typeID, rules);

            return noun;
        }
Example #7
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.nouCollection.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;
        }
Example #8
0
 public CyrResult DeclinePlural(string Phrase, GetConditionsEnum Condition)
 {
     return this.Decline(Phrase, Condition, NumbersEnum.Plural);
 }
Example #9
0
 public CyrResult Decline(string Phrase, GetConditionsEnum Condition)
 {
     return this.Decline(Phrase, Condition, NumbersEnum.Singular);
 }