public InsertBlock(Tuple<int, int> enumerationInfo, List<SentenceElement> sentenceElements) { _elements = new SortedList<int, SentenceElement>(); _mainWord = null; foreach (var element in sentenceElements.FindAll(x => (x.Order >= enumerationInfo.Item1 && x.Order <= enumerationInfo.Item2))) _elements.Add(element.Order, element); var elementsList = _elements.Select(x => x.Value).ToList(); foreach (var element in _elements) { var mainWordElement = sentenceElements.Find(x => elementsList.Find(y => y.Id == x.Id) == null && elementsList.Find(y => y.Id == x.ConjuctedWithId) != null); if (mainWordElement != null) _mainWord = mainWordElement; } }
public static (SentenceElement Element, bool Modified) ApplyPostProcessors(SentenceElement sentenceElement) { var children = sentenceElement.Children.ConvertAll(ApplyPostProcessors); var modified = children.Any(child => child.Modified); if (modified) { sentenceElement = sentenceElement with { Children = children.ConvertAll(it => it.Element) }; } // 'то', распознанное как ПРИЛАГАТЕЛЬНОЕ 'тот' с ПАДЕЖ:ИМ; ЧИСЛО:ЕД; РОД:СР; СТЕПЕНЬ:АТРИБ, // может быть СОЮЗОМ 'то' if (sentenceElement.LemmaVersions.Count == 1 && sentenceElement.LemmaVersions.Single() is var lemmaVersion && Impl.RussianIgnoreCase.Equals(lemmaVersion.Lemma, "тот") && lemmaVersion.Characteristics is AdjectiveCharacteristics charcteristics && charcteristics.Case == Case.Именительный && charcteristics.Number == Number.Единственное && charcteristics.Gender == Gender.Средний && charcteristics.ComparisonForm == ComparisonForm.Атрибут) { sentenceElement = sentenceElement with { LemmaVersions = sentenceElement.LemmaVersions .Concat( new LemmaVersion( "то", 1074167235, PartOfSpeech.Союз, new NullGrammarCharacteristics()).ToImmutable()) .AsImmutable() }; modified = true; } return(sentenceElement, modified); } } }
protected virtual SentenceElement GetOutPut(string inputText) { inputText = Regex.Replace(inputText, @"\r\n", " "); inputText = Regex.Replace(inputText, @",", " "); var setences = inputText.Split(new[] { '.' }).Where(a => !string.IsNullOrWhiteSpace(a)).Select((s) => { var words = s.Split(new[] { ' ' }).Where(a => !string.IsNullOrWhiteSpace(a)).OrderBy(o => o).ToArray(); var sentence = new WordElement { Words = words }; return(sentence); }).ToArray(); var text = new SentenceElement { Sentences = setences }; return(text); }
public override void ProcessSentence(Sentence sentence) { _sentence = sentence; Debug.Assert(sentence.ElementList != null); Debug.Assert(sentence.ElementList.Count > 0); List<SentenceElement> words = sentence.ElementList; // подлежащие foreach (var subjectStage1 in _mainPartsStage1Result.Items.FindAll(x => x.SyntacticRole.Value != SyntacticRole.Predicate.Value)) { Stage3ResultElement item = new Stage3ResultElement(); item.CopyFromSourceWord(subjectStage1); List<SentenceElement> AddedWords1 = item.AddedWordsCase1; List<SentenceElement> AddedWords2 = item.AddedWordsCase2; // количественная группа LWSUtils.FindQuantativeGroup(item.Id, ref AddedWords1, ref words); item.AddedWordsCase1 = AddedWords1; // субстантиватор LWSUtils.FindSubstantivatorInfo(item.Id, ref AddedWords2, ref words); item.AddedWordsCase2 = AddedWords2; Result.Items.Add(item); } // сказуемые foreach (var predicateStage1 in _mainPartsStage1Result.Items.FindAll(x => x.SyntacticRole.Value == SyntacticRole.Predicate.Value)) { Stage3ResultElement item = new Stage3ResultElement(); item.CopyFromSourceWord(predicateStage1); //Результатом являются слова, относящиеся к составному именному сказуемому. foreach (var childWordId in predicateStage1.ChildWordsIds.Nodes) { foreach (var dependantWord in words.FindAll(x => (x.SyntacticRole.Value == SyntacticRole.Complement.Value) && (x.SyntacticParentWordId == item.Id) && (x.Id == childWordId.Data) )) { SentenceElement wordToAdd = new SentenceElement(); wordToAdd.CopyFromSourceWord(words.Find(x => x.Id == dependantWord.Id)); item.AddedWordsCase1.Add(wordToAdd); } } // инфинитивная часть foreach (var childWordId in predicateStage1.ChildWordsIds.Nodes) { foreach (var dependantWord in words.FindAll(x => (x.SyntacticRole.Value == SyntacticRole.DirectObject.Value) && ( (x.SurfaceSlot.Value == SurfaceSlot.ClauseInfinitiveControl.Value) || (x.SurfaceSlot.Value == SurfaceSlot.ClauseInfinitiveForModalVerbs.Value) ) && (x.SyntacticParentWordId == item.Id) && (x.Id == childWordId.Data) )) { SentenceElement wordToAdd = new SentenceElement(); wordToAdd.CopyFromSourceWord(words.Find(x => x.Id == dependantWord.Id)); item.AddedWordsCase2.Add(wordToAdd); } } Result.Items.Add(item); } }