public override bool TryReadFromString(string gramString, out GramTabLine gramLine) { if (!base.TryReadFromString(gramString, out gramLine)) { return(false); } //Applying rules! // неизменяемые слова как будто принадлежат всем падежам if ( !((RussianGrammaticalCategories.Indeclinable & gramLine.Grammems).IsUnknown) && (gramLine.PartOfSpeech != RussianPartOfSpeeches.Predicate) ) { gramLine.Grammems = gramLine.Grammems | RussianGrammaticalCategories.AllCases; } if ( !((RussianGrammaticalCategories.Indeclinable & gramLine.Grammems).IsUnknown) && (gramLine.PartOfSpeech == RussianPartOfSpeeches.PronounAdjective) ) { gramLine.Grammems = gramLine.Grammems | RussianGrammaticalCategories.AllGenders | RussianGrammaticalCategories.AllNumbers; } // слова общего рода ('сирота') могут использованы как // слова м.р., так и как слова ж.р. if (!(RussianGrammaticalCategories.MascFem & gramLine.Grammems).IsUnknown) { gramLine.Grammems = gramLine.Grammems | RussianGrammaticalCategories.Masculinum | RussianGrammaticalCategories.Feminum; } // слово 'пальто' не изменяется по числам, поэтому может // быть использовано в обоих числах if (gramLine.PartOfSpeech != RussianPartOfSpeeches.Predicate) { if (!(RussianGrammaticalCategories.Indeclinable & gramLine.Grammems).IsUnknown && (RussianGrammaticalCategories.Singular & gramLine.Grammems).IsUnknown) { gramLine.Grammems = gramLine.Grammems | RussianGrammaticalCategories.Plural | RussianGrammaticalCategories.Singular; } } return(true); }
public virtual bool TryReadFromString(string gramString, out GramTabLine gramLine) { gramLine = new GramTabLine(); if (gramString == null || (gramString = gramString.Trim()) == string.Empty) { throw new Exception("Non empty string expected"); } //Reading part of speach int indexOfSpace = gramString.IndexOf(' '); indexOfSpace = indexOfSpace != -1 ? indexOfSpace : gramString.Length; string partOfSpeach = gramString.Substring(0, indexOfSpace); gramLine.PartOfSpeech = _partOfSpeecheConverter(partOfSpeach); //Moving "iterator" gramString = gramString.Substring(indexOfSpace).Trim(); if (gramString == string.Empty) { return(true); } //Reading grammems foreach (string grammem in gramString.Split(new char[] { ',' })) { string temp = grammem.Trim(); if (_gammaticalCategoriesConverter(temp) != GrammaticalCategory.Unknown) { gramLine.Grammems = gramLine.Grammems | _gammaticalCategoriesConverter(temp); } else if (IsAdditionalGrammem(temp)) { ProcessAdditionalGrammem(temp, ref gramLine); } else { return(false); // throw new Exception("Unsupported Grammatic category"); } } return(true); }
protected override bool ProcessAdditionalGrammem(string grammem, ref GramTabLine gramLine) { if (gramLine.PartOfSpeech == RussianPartOfSpeeches.Verb) { if (grammem == "прч") { gramLine.PartOfSpeech = RussianPartOfSpeeches.Participle; } else if (grammem == "дпр") { gramLine.PartOfSpeech = RussianPartOfSpeeches.AdverbParticiple; } else if (grammem == "инф") { gramLine.PartOfSpeech = RussianPartOfSpeeches.Infinitive; } } return(true); }
protected virtual bool ProcessAdditionalGrammem(string grammem, ref GramTabLine gramLine) { return(false); }