Пример #1
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.ElementList != null);
            Debug.Assert(sentence.ElementList.Count > 0);

            foreach (var word in sentence.ElementList.FindAll(x =>
                (x.SyntacticRole.Value == SyntacticRole.DirectObject.Value
                  && !(x.SurfaceSlot.Value == SurfaceSlot.ClauseInfinitiveForModalVerbs.Value)
                  && !(x.SurfaceSlot.Value == SurfaceSlot.ClauseInfinitiveControl.Value)
                )
                ||
                x.SyntacticRole.Value == SyntacticRole.IndirectObject.Value
                ||
                (x.SyntacticRole.Value == SyntacticRole.NonConcordantAttr.Value &&
                  (
                    x.SurfaceSlot.Value == SurfaceSlot.GenitivePostModifier.Value ||
                    x.SurfaceSlot.Value == SurfaceSlot.IdiomaticNominalGenitivePostmodifier.Value
                  )
                )
                ||
                (
                   (x.GrammarInfo.PartOfSpeech.Value == GrammarInfoPartOfSpeech.Noun.Value)
                   && !(x.GrammarInfo.Case.Value == GrammarInfoCase.Nominative.Value)
                   && (x.SurfaceSlot.Value == SurfaceSlot.RelativeGroup.Value)
                )
                ))
            {
                Stage1ResultElement item = new Stage1ResultElement();
                item.CopyFromSourceWord(word);
                Result.Items.Add(item);
            }
        }
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.ElementList != null);
            Debug.Assert(sentence.ElementList.Count > 0);

            foreach (var word in sentence.ElementList.FindAll(x => x.ConjuctedWithId != "-1"))
            {
                Stage1ResultElement item = new Stage1ResultElement();
                item.CopyFromSourceWord(word);
                item.ObjectType = ObjectType.MainWord;

                if (Result.Items.Find(x => x.Id == item.Id) == null)
                    Result.Items.Add(item);

                foreach (var relatedWord in sentence.ElementList.FindAll(x => x.Id == item.ConjuctedWithId))
                {
                    Stage1ResultElement dItem = new Stage1ResultElement();
                    dItem.CopyFromSourceWord(relatedWord);
                    dItem.ObjectType = ObjectType.RelatedWord;

                    if (Result.Items.Find(x => x.Id == dItem.Id) == null)
                        Result.Items.Add(dItem);
                }
            }
        }
Пример #3
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.ElementList != null);
            Debug.Assert(sentence.ElementList.Count > 0);

            foreach (SentenceElement word in sentence.ElementList.FindAll(x =>
                (
                  (x.SyntacticRole.Value == SyntacticRole.Subject.Value)
                  || (
                       (x.GrammarInfo.PartOfSpeech.Value == GrammarInfoPartOfSpeech.Noun.Value)
                       && (x.GrammarInfo.Case.Value == GrammarInfoCase.Nominative.Value)
                       && (x.SurfaceSlot.Value == SurfaceSlot.RelativeGroup.Value)
                     )
                )
                ||
                (
                  (x.SyntacticRole.Value == SyntacticRole.Predicate.Value)
                  && !(x.SurfaceSlot.Value == SurfaceSlot.InternalFiniteVerb.Value)
                )
                ))
            {
                Stage1ResultElement item = new Stage1ResultElement();
                item.CopyFromSourceWord(word);
                Result.Items.Add(item);
            }
        }
Пример #4
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;

            Debug.Assert(sentence.WordList != null);
            Debug.Assert(sentence.WordList.Count > 0);

            foreach (var word in sentence.WordList.FindAll(x =>
                   x.Link.Value == LinkType.KomplNesobst1.Value
                || x.Link.Value == LinkType.KomplNesobst2.Value
                || x.Link.Value == LinkType.KomplNesobst3.Value
                || x.Link.Value == LinkType.NesobstAgent.Value
                || x.Link.Value == LinkType.KvaziAgent1.Value
                || x.Link.Value == LinkType.KvaziAgent.Value
                || x.Link.Value == LinkType.Agent1.Value
                || x.Link.Value == LinkType.Agent.Value
                ||
                (
                    (x.Link.Value == LinkType.Kompl1.Value
                    || x.Link.Value == LinkType.Kompl2.Value
                    || x.Link.Value == LinkType.Kompl3.Value
                    || x.Link.Value == LinkType.Kompl4.Value
                    || x.Link.Value == LinkType.Kompl5.Value
                    ) && x.Representation.Value != Representation.Infinitive.Value
                )
                ))
            {
                Stage1ResultElement item = new Stage1ResultElement();
                item.CopyFromSourceWord(word);
                item.ObjectKind = ObjectKind.Main;

                Result.Items.Add(item);
            }
        }
Пример #5
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.WordList != null);
            Debug.Assert(sentence.WordList.Count > 0);

            // ищем слова с сочинительной связью, добавляем их, а также их потомков, проверяя итоговый список на уникальность
            findWordsWithSochLink();

            // получили некое начальное множество слов. Начинаем процедуру поиска дополнительных слов
            bool allDone = false;
            int lastIterationUniformPartsCount, currentIterationUniformPartsCount;
            while (!allDone)
            {
                currentIterationUniformPartsCount = 0;
                lastIterationUniformPartsCount = getAllUniformPartsIds().Count;

                //ищем предлоги и вспомогательные глаголы в имеющейся выборке
                findPrepositionsAndAuxVerbsStraight();
                findPrepositionsAndAuxVerbs(getAllUniformPartsIds());

                currentIterationUniformPartsCount = getAllUniformPartsIds().Count;
                allDone = currentIterationUniformPartsCount == lastIterationUniformPartsCount;
            }
        }
Пример #6
0
 private static void _checkDataPresence(Sentence sentence, List<string> result)
 {
     _checkCollection(sentence.Subjects, "подлежащие", result);
     _checkCollection(sentence.Predicates, "сказуемые", result);
     _checkCollection(sentence.Uniforms, "однородные члены", result);
     _checkCollection(sentence.ValuableAuxParts, "значимый объект", result);
     _checkCollection(sentence.LinkedChains, result);
 }
Пример #7
0
        public static LinguisticObjectDetectionMetrics MetricsFor(LinguisticObjectMatch objectMatch,
            Sentence targetSentence, Sentence sampleSentence, LinguisticObjectType objectType)
        {
            if (objectMatch.TargetObjects == null) return _metricsForMissedObject(objectMatch, sampleSentence);
            if (objectMatch.SampleObjects == null)
                return _metricsForSurplusTargetObject(objectMatch, sampleSentence, targetSentence, objectType);

            var targetWords = objectMatch.TargetObjects.Words;
            var sampleWords = objectMatch.SampleObjects.Words;
            var detectedWords = _getDetectedWords(targetWords, sampleWords);
            var surplusWords = targetWords.Where(word => !detectedWords.Contains(word)).ToList();
            var missedWords =
                sampleWords.Where(word => targetWords.All(targetWord => targetWord.Text != word.Text)).ToList();

            var essentialSurpluses = surplusWords.Where(word => !word.IsAuxilary).ToList();
            var essentialSurplusText = essentialSurpluses.Select(word => word.Text).ToList();
            var essentialSurplusIndexes = essentialSurpluses.Select(targetSentence.WordIndex).ToList();

            var nonEssentialSurpluses = surplusWords.Where(word => word.IsAuxilary).ToList();
            var nonEssentialSurplusTexts = nonEssentialSurpluses.Select(word => word.Text).ToList();
            var nonEssentialSurplusIndexes = nonEssentialSurpluses.Select(targetSentence.WordIndex).ToList();

            var essentialMises = missedWords.Where(word => !word.IsAuxilary).ToList();
            var essentialMissTexts = essentialMises.Select(word => word.Text).ToList();
            var essentialMissIndexes = essentialMises.Select(sampleSentence.WordIndex).ToList();

            var nonEssentialMises = missedWords.Where(word => word.IsAuxilary).ToList();
            var nonEssentialMissTexts = nonEssentialMises.Select(word => word.Text).ToList();
            var nonEssentialMissIndexes = nonEssentialMises.Select(sampleSentence.WordIndex).ToList();

            return new LinguisticObjectDetectionMetrics
            {
                SampleWords = sampleWords.Select(word => word.Text).ToArray(),
                TargetWords = targetWords.Select(word => word.Text).ToArray(),
                SampleWordsCount = sampleWords.Count,
                SampleWordIndexes = sampleWords.Select(sampleSentence.WordIndex).ToArray(),
                TargetWordsCount = targetWords.Count,
                TargetWordIndexes = targetWords.Select(targetSentence.WordIndex).ToArray(),
                NonEssentialErrors = nonEssentialSurplusTexts.Concat(nonEssentialMissTexts).ToArray(),
                NonEssentialErrorIndexes = nonEssentialSurplusIndexes.Concat(nonEssentialMissIndexes).ToArray(),
                EssentialErrors = essentialSurplusText.Concat(essentialMissTexts).ToArray(),
                EssentialErrorIndexes = essentialSurplusIndexes.Concat(essentialMissIndexes).ToArray(),
                SurplusNonEssentialWords = nonEssentialSurplusTexts.ToArray(),
                SurplusNonEssentialWordIndexes = nonEssentialSurplusIndexes.ToArray(),
                MissedNonEssentialWords = nonEssentialMissTexts.ToArray(),
                MissedNonEssentialWordIndexes = nonEssentialMissIndexes.ToArray(),
                SurplusEssentialWords = essentialSurplusText.ToArray(),
                SurplusEssentialWordIndexes = essentialSurplusIndexes.ToArray(),
                MissedEssentialWords = essentialMissTexts.ToArray(),
                MissedEssentialWordIndexes = essentialMissIndexes.ToArray(),
                CorrectDetectionsCount = detectedWords.Count,
                Type = ErrorType.DetectionDefect,
                DetectionQuality =
                    detectedWords.Any()
                        ? _getQualityMeasure(detectedWords.Count, essentialSurpluses.Count, sampleWords.Count)
                        : 0d
            };
        }
Пример #8
0
 public static ComparisonResult Compare(Sentence target, Sentence sample, LinguisticObjectsMap objectsMap)
 {
     return new ComparisonResult
     {
         SampleSantence = sample,
         TargetSentence = target,
         SimpleSentenceStats = (new SamplesProcessor(target, sample))._calculateStats(objectsMap),
         SimpleSentecesComparison = _getStatsFoSS(objectsMap, target, sample)
     };
 }
Пример #9
0
        private SamplesProcessor(Sentence target, Sentence sample)
        {
            _target = target;
            _sample = sample;
            _simpleSentencesStats = new List<SimpleSentenceStats>();

            for (var i = 0; i < Math.Max(target.SimpleSentences.Count, sample.SimpleSentences.Count); ++i)
            {
                _simpleSentencesStats.Add(new SimpleSentenceStats());
            }
        }
Пример #10
0
        public static List<string> Validate(Sentence sentence, int index)
        {
            var result = new List<string>();

            _checkDataPresence(sentence, result);
            _checkLinkedChainMasterExists(sentence, result);
            _checkLinkedChainMaster(sentence, result);
            //_checkLinkedChainMasterIsSingleWord(sentence, result);

            return result.Select(s => String.Format("Предложение {0}: {1}", index + 1, s)).ToList();
        }
Пример #11
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.WordList != null);
            Debug.Assert(sentence.WordList.Count > 0);

            GetDependantResultsForObjectType(ObjectType.MeaningPartDependOn);
            GetDependantResultsForObjectType(ObjectType.SubjectDependOn);
            GetDependantResultsForObjectType(ObjectType.PredicateDependOn);

            // сразу делаем второй этап
            foreach (var word in Result.Items)
                word.IsConfirmed = !(word.Link.Value == LinkType.Sochin.Value);
        }
Пример #12
0
            public static Sentence Convert(JsonSentence jsonSentence)
            {
                var result = new Sentence();

                result.Words.AddRange(jsonSentence.Words);
                result.SimpleSentences.AddRange(jsonSentence.SimpleSentences.Select(list => wordIndexesToSimpleSentence(list, jsonSentence.Words)));
                result.LinkedChains.AddRange(jsonSentence.LinkedChains.Select(chain => jsonLinkedChainToModelChain(chain, jsonSentence.Words)));
                result.Uniforms.AddRange(wordIndexesListsToWordChains(jsonSentence.Uniforms, jsonSentence.Words));
                result.ValuableAuxParts.AddRange(wordIndexesListsToWordChains(jsonSentence.ValuableAuxParts, jsonSentence.Words));
                result.Subjects.AddRange(wordIndexesListsToWordChains(jsonSentence.Subjects, jsonSentence.Words));
                result.Predicates.AddRange(wordIndexesListsToWordChains(jsonSentence.Predicates, jsonSentence.Words));

                return result;
            }
Пример #13
0
        private static LinguisticObjectsGroup _getStatsFoSS(LinguisticObjectsMap objectsMap, Sentence target, Sentence sample)
        {
            var result = new LinguisticObjectsGroup
            {
                Objects = objectsMap.SimpleSentences.Select(match => _processSimpleSentence(match, target, sample)).ToList()
            };

            _chargePenalties(result.Objects);
            result.Objects.ForEach(o => SimpleSentenceStats.CalculateAverage(result));

            var falsey = result.Objects.Any(o => o.MappedObjects.SampleObjects == null);

            return result;
        }
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.ElementList != null);
            Debug.Assert(sentence.ElementList.Count > 0);

            foreach (SentenceElement word in sentence.ElementList.FindAll(x =>
                                                                    (x.SyntacticRole.Value == SyntacticRole.Predicate.Value)
                                                                    & !(x.SurfaceSlot.Value == SurfaceSlot.InternalFiniteVerb.Value)))
            {
                Stage1ResultElement item = new Stage1ResultElement();
                item.CopyFromSourceWord(word);
                Result.Items.Add(item);
            }
        }
Пример #15
0
            public static JsonSentence Convert(Sentence sentence)
            {
                var result = new JsonSentence
                {
                    Words = sentence.Words.ToArray(),
                    Text = String.Join(" ", sentence.Words.Select(word => word.Text)),
                    SimpleSentences = wordsCahinsToIndexesLists(sentence.SimpleSentences, sentence.Words),
                    Uniforms = wordsCahinsToIndexesLists(sentence.Uniforms, sentence.Words),
                    ValuableAuxParts = wordsCahinsToIndexesLists(sentence.ValuableAuxParts, sentence.Words),
                    Subjects = wordsCahinsToIndexesLists(sentence.Subjects, sentence.Words),
                    Predicates = wordsCahinsToIndexesLists(sentence.Predicates, sentence.Words),
                    LinkedChains = linkedChainsToJsonModel(sentence.LinkedChains, sentence.Words)
                };

                return result;
            }
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.ElementList != null);
            Debug.Assert(sentence.ElementList.Count > 0);
            Stage1Result algorithmResult = Result;

            GetDependantResultsForObjectType(sentence, ObjectType.MeaningPartDependOn, _meaningPartStage4Result.Items.Select(x => x.Id).ToList(), ref algorithmResult);
            GetDependantResultsForObjectType(sentence, ObjectType.SubjectDependOn,
                _mainPartsStage4Result.Items.Where(x => (x.SyntacticRole.Value != SyntacticRole.Predicate.Value)
                || (x.IsQuantativePart == true)
                || (x.IsSubstantivator == true)).Select(x => x.Id).ToList(),
                ref algorithmResult);
            GetDependantResultsForObjectType(sentence, ObjectType.PredicateDependOn,
                _mainPartsStage4Result.Items.Where(x => (x.SyntacticRole.Value == SyntacticRole.Predicate.Value)
                || (x.IsNamePart == true)
                || (x.IsInfinitivePart == true)).Select(x => x.Id).ToList(),
                ref algorithmResult);
        }
Пример #17
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.WordList != null);
            Debug.Assert(sentence.WordList.Count > 0);

            foreach (SentenceWord word in sentence.WordList.FindAll(x =>
                   x.DOM == SentenceWord.DOMRoot
                || x.Link.Value == LinkType.SentSoch.Value
                || x.Link.Value == LinkType.PodchSouz.Value
                || x.Link.Value == LinkType.InfSouz.Value
                || x.Link.Value == LinkType.Eksplet.Value
                || x.Link.Value == LinkType.Relyat.Value
            ))
            {
                Stage1ResultElement item = new Stage1ResultElement();
                item.CopyFromSourceWord(word);
                Result.Items.Add(item);
            }
        }
Пример #18
0
 public static LinguisticObjectsMap MapLinguisticObjects(Sentence target, Sentence sample)
 {
     var simpleSentencesMap = _mapSimpleSentences(target.SimpleSentences, sample.SimpleSentences);
     return new LinguisticObjectsMap
     {
         Subjects =
             _mapSimpleParts(target.Subjects, sample.Subjects,
                 (targetWords, sampleWords) => _measureLoQuality(targetWords, sampleWords, simpleSentencesMap)),
         Predicates =
             _mapSimpleParts(target.Predicates, sample.Predicates,
                 (targetWords, sampleWords) => _measureLoQuality(targetWords, sampleWords, simpleSentencesMap)),
         Uniforms =
             _mapSimpleParts(target.Uniforms, sample.Uniforms,
                 (targetWords, sampleWords) => _measureLoQuality(targetWords, sampleWords, simpleSentencesMap)),
         MeaningAuxParts =
             _mapSimpleParts(target.ValuableAuxParts, sample.ValuableAuxParts,
                 (targetWords, sampleWords) => _measureLoQuality(targetWords, sampleWords, simpleSentencesMap)),
         LinkedChains =
             _mapLinkedChains(target.LinkedChains, sample.LinkedChains,
                 (targetWords, sampleWords) => _measureLoQuality(targetWords, sampleWords, simpleSentencesMap)),
         SimpleSentences = simpleSentencesMap
     };
 }
Пример #19
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.WordList != null);
            Debug.Assert(sentence.WordList.Count > 0);

            // подлежащие. часть1
            foreach (SentenceWord word in sentence.WordList.FindAll(x =>
                (x.Link.Value == LinkType.Predic.Value
                 || x.Link.Value == LinkType.DatSubject.Value
                )))
            {
                Stage1ResultElement item = new Stage1ResultElement();
                item.CopyFromSourceWord(word);
                item.ObjectType = ObjectType.Subject;
                item.ObjectKind = ObjectKind.Main;
                Result.Items.Add(item);
            }

            //сказуемые
            foreach (SentenceWord word in sentence.WordList.FindAll(x =>
                (x.DOM == SentenceWord.DOMRoot /*&& (x.PartOfSpeech.Value == PartOfSpeech.Verb.Value || x.IsAuxVerb)*/)
                 || x.Link.Value == LinkType.SentSoch.Value
                 || (x.Link.Value == LinkType.PodchSouz.Value && (x.PartOfSpeech.Value == PartOfSpeech.Verb.Value || x.IsAuxVerb))
                 || x.Link.Value == LinkType.InfSouz.Value
                 || x.Link.Value == LinkType.Eksplet.Value
                 || x.Link.Value == LinkType.Relyat.Value
                ))
            {
                Stage1ResultElement item = new Stage1ResultElement();
                item.CopyFromSourceWord(word);
                item.ObjectType = ObjectType.Predicate;
                item.ObjectKind = ObjectKind.Main;
                Result.Items.Add(item);
            }
        }
Пример #20
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.ElementList != null);
            Debug.Assert(sentence.ElementList.Count > 0);
            List<SentenceElement> words = sentence.ElementList;

            // разворачиваем все, что добавили на 3-м этапе в список резльтатов 4-го и после этого плюсуем к ним СЧР
            foreach (var itemStage3 in _meaningPartStage3Result.Items)
            {
                Stage4ResultElement item = new Stage4ResultElement();
                item.CopyFromSourceWord(itemStage3);
                item.AddedWordsCase1 = itemStage3.AddedWordsCase1;
                item.AddedWordsCase2 = itemStage3.AddedWordsCase2;
                Result.Items.Add(item);
            }

            foreach (var itemStage4 in Result.Items)
            {
                itemStage4.ServiceParts.AddRange(words.FindAll(x => (x.SyntacticParentWordId == itemStage4.Id) && (x.IsServicePart)));

                // TODO: провести поиск СЧР для составных частей Add1 и Add2

                // добавляем второй проход по выявленным СЧР, чтобы выявить ситуации "не были удовлетворены" (частица + вспом.глагол + XXX)
                List<SentenceElement> servicePartsSecondLevel = new List<SentenceElement>();
                foreach (var servicePart in itemStage4.ServiceParts)
                    servicePartsSecondLevel.AddRange(words.FindAll(x => (x.SyntacticParentWordId == servicePart.Id) && (x.IsServicePart)));
                itemStage4.ServiceParts.AddRange(servicePartsSecondLevel);
            }
        }
Пример #21
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.ElementList != null);
            Debug.Assert(sentence.ElementList.Count > 0);

            _stage3Result.Items.GroupBy(uniform => uniform.RowId)
               .Aggregate(_modelBuilder,
                   (builder, uniforms) => builder.AddUniforms(uniforms.OrderBy(uniform => uniform.Order)));

            Result.Items.AddRange(_modelBuilder.Sentence.Uniforms.Select(uniforms => new StageComparisonResultElement(uniforms)));
        }
Пример #22
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.ElementList != null);
            Debug.Assert(sentence.ElementList.Count > 0);

            // необходимо найти все атомарные ряды ОЧ во всех простых предложениях
            int restoredRowId = -1;
            int normalRowId = 1;
            foreach (var lastConjuctedItem in _uniformPartsStage2Result.FindAll(x => (x.IsConfirmed) && (x.ConjuctedWithId == "-1")))
            {
                // выбрали все слова, которые находятся на самом низком уровне сочинительной свзяи для ОЧ
                // идем наверх, добавляя items в результаты с текущим rowId
                var currentItem = lastConjuctedItem;

                while (currentItem != null)
                {
                    Stage3ResultElement item = new Stage3ResultElement();
                    item.CopyFromSourceWord(currentItem);
                    item.ObjectType = currentItem.ObjectType;
                    // отделяем восстановленные ОЧ
                    if (item.IsRestored)
                        item.RowId = restoredRowId;
                    else
                        item.RowId = normalRowId;

                    currentItem = _uniformPartsStage2Result.Find(x => (x.IsConfirmed) && (x.ConjuctedWithId == currentItem.Id));
                    Result.Items.Add(item);
                }

                if (Result.Items.Last().IsRestored)
                    restoredRowId--;
                else
                    normalRowId++;
            }

            foreach (var itemStage3 in Result.Items)
            {
                itemStage3.SeviceParts.AddRange(sentence.ElementList.FindAll(x => (x.SyntacticParentWordId == itemStage3.Id) && (x.IsServicePart)));

                // добавляем второй проход по выявленным СЧР, чтобы выявить ситуации "не были удовлетворены" (частица + вспом.глагол + XXX)
                List<SentenceElement> servicePartsSecondLevel = new List<SentenceElement>();
                foreach (var servicePart in itemStage3.SeviceParts)
                    servicePartsSecondLevel.AddRange(sentence.ElementList.FindAll(x => (x.SyntacticParentWordId == servicePart.Id) && (x.IsServicePart)));
                itemStage3.SeviceParts.AddRange(servicePartsSecondLevel);
            }
        }
Пример #23
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.ElementList != null);
            Debug.Assert(sentence.ElementList.Count > 0);

            foreach (var stage1Result in _uniformPartsStage1Result)
            {
                Stage2ResultElement item = new Stage2ResultElement();
                item.CopyFromSourceWord(stage1Result);
                item.ObjectType = stage1Result.ObjectType;
                item.SubjectIdForCompare = "-1";

                // Все пред. ОЧ, которые не имеют Predicate тэга, подтверждаем.
                if (item.SyntacticRole.Value == SyntacticRole.Predicate.Value)
                {
                    // Если у некоторого сказуемого нет подлежащего, оно также удаляется из предварительного списка ОЧ.
                    if (sentence.ElementList.Find(x => (x.SyntacticParentWordId == stage1Result.Id) && (x.SyntacticRole.Value == SyntacticRole.Subject.Value)) == null)
                    {
                        item.IsConfirmed = false;
                        Result.Items.Add(item);
                        continue;
                    }
                    else
                    {
                        // У сказуемого есть подлежащее, находим его ID
                        SentenceElement subjectForPredicate = sentence.ElementList.Find(x => (x.SyntacticParentWordId == stage1Result.Id) && (x.SyntacticRole.Value == SyntacticRole.Subject.Value));
                        if (subjectForPredicate != null)
                            item.SubjectIdForCompare = subjectForPredicate.Id;
                        // надо проверять, если такая ситуация возникнет!!!
                        else item.SubjectIdForCompare = "-1000";

                        // если подлежащее - субстантиватор, то в Id ставим Id которым он контролируется
                        SentenceElement substanSubject = (sentence.ElementList.Find(x =>
                                (x.Id == item.SubjectIdForCompare) &&
                                (x.ControllerNodes.Find(y => y.ConnectionType.Value == ControllerConnectionType.Ellipsis.Value) != null)));
                        if (substanSubject != null)
                            item.SubjectIdForCompare = substanSubject.ControllerNodes.Find(y => y.ConnectionType.Value == ControllerConnectionType.Ellipsis.Value).OriginalWordId;

                        //если подлежащее восстановлено, то надо взять первый дочерний его элемент
                        if (item.IsRestored)
                        {
                            SentenceElement firstChildWord = sentence.ElementList.Find(x => x.SyntacticParentWordId == item.Id && x.SyntacticRole.Value != SyntacticRole.Subject.Value);
                            if (firstChildWord != null)
                                item.CopyFromSourceWord(firstChildWord);
                        }

                        Result.Items.Add(item);
                    }
                }
                else
                {
                    item.IsConfirmed = true;
                    Result.Items.Add(item);
                    continue;
                }
            }

            foreach (var stage2Result in Result.Items.FindAll(x => x.SubjectIdForCompare != "-1"))
                stage2Result.IsConfirmed = Result.Items.FindAll(x => x.SubjectIdForCompare == stage2Result.SubjectIdForCompare).Count > 1;
        }
Пример #24
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(_meaningPartStage4Result != null);
            Debug.Assert(_mainPartsStage4Result != null);
            Debug.Assert(_stage1Result != null);
            List<SentenceWord> words = sentence.WordList;

            int[] excludeIds = _getMainIds().ToArray();

            foreach (var stage1Item in _stage1Result.Items.FindAll(x => x.IsConfirmed))
                CreateDependantChain(stage1Item.DOM, stage1Item, excludeIds, stage1Item.ObjectType, null);

            foreach (var item in Result.Items.FindAll(x => x.IsConjuction))
            {
                if (item.ChainWordsIds.Count > 0)
                {
                    int firstChildId = item.ChainWordsIds.All.Values.First();

                    int domId = item.DOM;
                    ObjectType type = item.ObjectType;
                    var itemChainWords = item.ChainWordsIds;

                    item.CopyFromSourceWord(_sentence.WordList.Find(x => x.Id == firstChildId));

                    item.DOM = domId;
                    item.ObjectType = type;
                    item.ChainWordsIds = itemChainWords;
                    item.ChainWordsIds.Remove(firstChildId);

                }
                else
                    Result.Items.Remove(item);
            }

            foreach (var item in Result.Items)
                shrinkResultBySimpleSentence(item);
        }
Пример #25
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(_stage3Result != null);

            _stage3Result.Items.Aggregate(_modelBuilder, (builder, element) => builder.AddLinkedChain(_sentence.WordList.Find(x => x.Id == element.DOM), dependantWords(element)));

            Result.Items.AddRange(_modelBuilder.Sentence.LinkedChains.Select(chain => new StageComparisonResultElement(chain)));
        }
Пример #26
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.ElementList != null);
            Debug.Assert(sentence.ElementList.Count > 0);

            // Необходимо подтвердить, что родителем значимого объекта является главный член. Если это не так, то это не значимый член.
            foreach (var resultStage1 in _meaningPartStage1Result.Items)
            {
                Stage2ResultElement item = new Stage2ResultElement();
                item.CopyFromSourceWord(resultStage1);
                item.IsWordConfirmed = false;

                item.IsWordConfirmed = _mainPartsStage4Result.Items.Find(x => x.Id == item.SyntacticParentWordId) != null;

                // также надо проверить все составные части сказуемых и подлежащих
                foreach (var mainResultStage4 in _mainPartsStage4Result.Items)
                {
                    foreach (var addedWord in (mainResultStage4.AddedWordsCase1.Concat(mainResultStage4.AddedWordsCase2).Concat(mainResultStage4.ServiceParts)))
                        item.IsWordConfirmed = item.IsWordConfirmed || addedWord.Id == item.SyntacticParentWordId;
                }
                Result.Items.Add(item);
            }
        }
Пример #27
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(sentence.ElementList != null);
            Debug.Assert(sentence.ElementList.Count > 0);

            foreach (var resultStage2 in _meaningPartStage2Result.Items.FindAll(x => x.IsWordConfirmed))
            {
                Stage3ResultElement item = new Stage3ResultElement();
                item.CopyFromSourceWord(resultStage2);
                List<SentenceElement> words = sentence.ElementList;

                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);
            }
        }
Пример #28
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(_stage4Result != null);

            _stage4Result.Items.FindAll(x => !x.IsRestored).Select(_compileMeaningPart).
                Aggregate(_modelBuilder, (builder, meaningPart) => builder.AddMeaningPart(meaningPart));

            Result.Items.AddRange(_modelBuilder.Sentence.ValuableAuxParts.Select(chain => new StageComparisonResultElement(chain)));
        }
Пример #29
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(_stage3Result != null);

            // ищем частицы
            List<SentenceWord> particles = sentence.WordList.Where(x => x.PartOfSpeech.Value == PartOfSpeech.Particle.Value).ToList();

            foreach (var itemStage3 in _stage3Result.Items)
            {
                Stage4ResultElement item = new Stage4ResultElement();
                item.CopyFromSourceWord(itemStage3);

                SentenceWord particle;

                particle = particles.Find(x => x.DOM == item.Id);
                if (particle != null)
                {
                    SentenceWord word = new SentenceWord();
                    word.CopyFromSourceWord(particle);
                    item.ServiceParts.Add(word);
                }

                particle = particles.Find(x => item.ServiceParts.Select(y => y.Id).ToList().Contains(x.DOM));
                if (particle != null)
                {
                    SentenceWord word = new SentenceWord();
                    word.CopyFromSourceWord(particle);
                    item.ServiceParts.Add(word);
                }

                Result.Items.Add(item);
            }
        }
Пример #30
0
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(_stage1Result != null);

            // формируем список элементов этапа №1, которые либо сами являются началом цепочки однородности (conjuctedwith == -1), либо имеют таковые СЧР
            List<Stage1ResultElement> firstElements = _stage1Result.Items.Where(x => (x.ConjuctedWithId == -1
                || x.ServiceParts.Where(y => y.ConjuctedWithId == -1).Count() > 0)
                ).ToList();
            int rowId = 1;

            foreach (var lastConjuctedItem in firstElements)
            {
                // выбрали все слова, которые находятся на самом низком уровне сочинительной связи для ОЧ
                // идем наверх, добавляя items в результаты с текущим rowId
                // при этом понимаем, что связи могут быть древовидными
                var currentItem = lastConjuctedItem;

                while (currentItem != null)
                    currentItem = _searchForAnotherItemAndAddIt(currentItem, rowId);

                rowId++;

                // удаляем союзы
                Result.Items.RemoveAll(x => x.IsConjuction);
                foreach (var sp in Result.Items)
                    sp.ServiceParts.RemoveAll(x => x.IsConjuction);
            }

            // найдем номера ПП для каждого из полученных ОЧ
            foreach (var item in Result.Items)
            {
                item.SimpleSentenceNr = -1;
                SimpleSentences.Algorithms.Stage3ResultElement ss = _simpleSentencesStage3Result.Items.Find(x => x.Id == item.Id || x.ChainWordsIds.All.Values.Contains(item.Id));
                if (ss != null)
                    item.SimpleSentenceNr = ss.SimpleSentenceNr;
            }
        }