Пример #1
0
        public override bool Equals(object obj)
        {
            CyrRule that   = obj as CyrRule;
            bool    equals = this.originalRuleString == that?.originalRuleString;

            return(equals);
        }
Пример #2
0
        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);
        }
Пример #3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="Name">Прилагательное мужского рода в именительном падеже</param>
 /// <param name="CollectionName">Слово найденное в коллекции</param>
 /// <param name="Gender">Пол для склонения</param>
 /// <param name="rules">Правила склонения</param>
 public CyrAdjective(string Name, string CollectionName, GendersEnum Gender, CyrRule[] rules)
 {
     this.name = Name;
     this.collectionName = CollectionName;
     this.gender = Gender;
     this.rules = rules;
 }
Пример #4
0
        public void SetName(string name, CasesEnum @case, NumbersEnum number)
        {
            if (this.rules.Length > rulesPerNoun)
            {
                throw new NotImplementedException($"{nameof(SetName)} is not yet supported for composite nouns.");
            }

            CyrRule[] rules = this.GetRules(number, 0);
            CyrRule   rule  = rules[(int)@case - 1];

            this.Name = rule.Revert(this.Name, name);
        }
Пример #5
0
        protected void Fill()
        {
            foreach (KeyValuePair <string, string> item in this.masculineWords)
            {
                string   rules = this.rules[int.Parse(item.Value)];
                string[] parts = rules.Split(',');
                CyrRule  rule  = new CyrRule(parts[5]);
                string   w     = rule.Apply(item.Key);

                if (!this.feminineWords.ContainsKey(w))
                {
                    this.feminineWords.Add(w, item);
                }

                rule = new CyrRule(parts[11]);
                w    = rule.Apply(item.Key);

                if (!this.neuterWords.ContainsKey(w))
                {
                    this.neuterWords.Add(w, item);
                }
            }
        }
Пример #6
0
        public CyrNounCollection()
        {
            CyrData    data = new CyrData();
            TextReader treader;
            string     line;
            bool       rulesBlock = true;

            treader = data.GetData(NounsResourceName);

            List <string>[] singularWordCandidates = new List <string>[] { new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>() };
            List <string>[] pluralWordCandidates   = new List <string>[] { new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>() };

            while (true)
            {
                line = treader.ReadLine();

                if (line == null)
                {
                    break;
                }
                else if (rulesBlock && line == EndOfTheRulesBlock)
                {
                    rulesBlock = false;
                    continue;
                }
                else if (this.IsSkipLine(line))
                {
                    continue;
                }

                if (rulesBlock)
                {
                    string[]  parts = line.Split(',', '|');
                    CyrRule[] rule  = new CyrRule[parts.Length];

                    for (int i = 0; i < parts.Length; i++)
                    {
                        rule[i] = new CyrRule(parts[i]);
                    }

                    this.rules.Add(rule);
                }
                else
                {
                    this.AddWordToTheCollection(line, singularWordCandidates, pluralWordCandidates);
                }
            }

            treader.Dispose();

            {
                IEnumerable <string> candidates = new string[0];

                foreach (List <string> candidate in singularWordCandidates)
                {
                    candidates = candidates.Concat(candidate);
                }

                foreach (List <string> candidate in pluralWordCandidates)
                {
                    candidates = candidates.Concat(candidate);
                }

                this.wordCandidates = candidates.Distinct().ToList();
            }
        }
Пример #7
0
        /// <summary>
        /// Заполняет список правил (<see cref="rules"/>) склонения.
        /// Заполняет словарь слов (<see cref="words"/>) и коллекцию (<see cref="wordCandidates"/>) для поиска ближайших совпадений.
        /// </summary>
        protected virtual void FillDictionaries()
        {
            bool rulesBlock = true;

            List <KeyValuePair <DictionaryKey, CyrAdjective> > adjectives = new List <KeyValuePair <DictionaryKey, CyrAdjective> >();

            List <string>[] pluralWordCandidates    = new List <string>[] { new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>() };
            List <string>[] masculineWordCandidates = new List <string>[] { new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>() };
            List <string>[] feminineWordCandidates  = new List <string>[] { new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>() };
            List <string>[] neuterWordCandidates    = new List <string>[] { new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>() };

            TextReader treader = this.cyrData.GetData(AdjectivesResourceName);
            string     line;

            while (true)
            {
                line = treader.ReadLine();

                if (line == null)
                {
                    break;
                }
                else if (rulesBlock && line == EndOfTheRulesBlock)
                {
                    rulesBlock = false;
                    continue;
                }
                else if (this.IsSkipLine(line))
                {
                    continue;
                }

                if (rulesBlock)
                {
                    string[]  parts = line.Split(',');
                    CyrRule[] rule  = new CyrRule[parts.Length];

                    for (int i = 0; i < parts.Length; i++)
                    {
                        rule[i] = new CyrRule(parts[i]);
                    }

                    this.rules.Add(rule);
                }
                else
                {
                    this.AddWordToDictionary(line, adjectives, masculineWordCandidates, feminineWordCandidates, neuterWordCandidates, pluralWordCandidates);
                }
            }

            treader.Dispose();

            foreach (KeyValuePair <DictionaryKey, CyrAdjective> pair in adjectives)
            {
                this.words[pair.Key] = pair.Value;
            }

            IEnumerable <string> candidates = null;

            List <string>[][] candidatesCollections = new List <string>[][]
            {
                masculineWordCandidates,
                feminineWordCandidates,
                neuterWordCandidates,
                pluralWordCandidates
            };

            foreach (List <string>[] collection in candidatesCollections)
            {
                for (int i = 0; i < collection.Length; i++)
                {
                    if (candidates == null)
                    {
                        candidates = collection[i];
                    }
                    else
                    {
                        candidates = candidates.Concat(collection[i]);
                    }
                }
            }

            this.wordCandidates = candidates.Distinct().ToList();
        }