protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
 {
     return PostProcessingUtils.ChangeSurfaceSlotToKnownValue(Name,
         HelperDataIfConjunctionParetntId.Name
         , Consts.SurfaceSlotDefinedValues.AdjunctConditionClause
         , sourceSentence, data);
 }
示例#2
0
        public static List<PostPropcessingActionInfo> ChangePartOfSpeech(string actionName, string columnName, string newPartOfSpeechValue, Sentence sourceSentence, BaseHelperData data)
        {
            var result = new List<PostPropcessingActionInfo>();
            var words = new List<KeyValuePair<int, string>>();

            foreach (DataRow row in data.Rows)
            {
                var sourceId = row.Field<int>(columnName);

                if (sourceId > 0)
                    words.Add(new KeyValuePair<int, string>(sourceId, newPartOfSpeechValue));
            }

            foreach (var pair in words)
            {
                var wordId = pair.Key;
                var newPartOfSpeech = pair.Value;
                var modifiedWord = sourceSentence.Elements.Find(x => x.Id == wordId);
                var oldModWordPartOfSpeech = modifiedWord.GrammarInfo.PartOfSpeech.Value;

                modifiedWord.GrammarInfo.PartOfSpeech = PartOfSpeech.ReadFromString(newPartOfSpeech);

                result.Add(new PostPropcessingActionInfo(actionName, wordId, nameof(modifiedWord.GrammarInfo.PartOfSpeech), oldModWordPartOfSpeech, modifiedWord.GrammarInfo.PartOfSpeech.Value));
            }

            return result;
        }
 protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
 {
     return PostProcessingUtils.ChangeTextValue(Name,
         HelperDataFalseDirectObjectReconstructionSubstantivatorControllerId.Name
         , HelperDataFalseDirectObjectReconstructionSubstantivatorControllerText.Name
         , sourceSentence, data);
 }
 protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
 {
     return PostProcessingUtils.ChangePartOfSpeech(Name,
         HelperDataFindFalseParticleIIds.Name
         , PartOfSpeech.Conjunction.Value
         , sourceSentence, data);
 }
 protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
 {
     return PostProcessingUtils.ChangeSyntacticParent(Name,
         HelperDataFindFalseConjunctionSParetnForSId.Name
         , HelperDataFindFalseConjunctionSNewGrandParentId.Name
         , sourceSentence, data);
 }
 protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
 {
     return PostProcessingUtils.ChangePartOfSpeech(Name,
         HelperDataColumnElementId.Name
         , PartOfSpeech.Preposition.Value
         , sourceSentence, data);
 }
 protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
 {
     return PostProcessingUtils.ChangeSyntacticParent(Name,
         HelperDataConjunctedWordsForPSSWordId.Name
         , HelperDataConjunctedWordsForPSSConjunctedId.Name
         , sourceSentence, data);
 }
 protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
 {
     return PostProcessingUtils.ChangeSyntacticParent(Name,
         HelperDataUPAdjectiveForElliptedNounPESTrue.Name
         , HelperDataUPAdjectiveForElliptedNounSSPES.Name
         , sourceSentence, data);
 }
        protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
        {
            var result = new List<PostPropcessingActionInfo>();
            var wordPairs = new Dictionary<int, int>();

            var firstGroupingColumnName = HelperDataQuasiUniformPartsAttachmentMainType2ConfirmedNr.Name;
            var secondGroupingColumnName = HelperDataQuasiUniformPartsAttachmentMainType2ParentNr.Name;
            var sourceColumnName = HelperDataQuasiUniformPartsAttachmentMainType2ParentId.Name;
            var destColumnName = HelperDataQuasiUniformPartsAttachmentMainType2ConfirmedId.Name;

            foreach (DataRow row in data.Rows)
            {
                if (row.Field<int>(firstGroupingColumnName) > -1)
                    row.SetField(secondGroupingColumnName, row.Field<int>(firstGroupingColumnName));
                if (row.Field<int>(secondGroupingColumnName) > -1)
                    row.SetField(firstGroupingColumnName, row.Field<int>(secondGroupingColumnName));
            }

            foreach (var group in data.AsEnumerable().GroupBy(grp => grp.Field<int>(firstGroupingColumnName)))
            {
                var parentColValues = group.ToList().Find(x => x.Field<int>(sourceColumnName) > -1);
                var childColValues = group.ToList().Find(x => x.Field<int>(destColumnName) > -1);
                var parentId = parentColValues?.Field<int>(sourceColumnName) ?? -1;
                var childId = childColValues?.Field<int>(destColumnName) ?? -1;

                if (parentId > 0 && childId > 0)
                {
                    wordPairs.Add(parentId, childId);
                }
            }

            PostProcessingUtils.AddConjunctionLink(Name, wordPairs, sourceSentence, result);

            return result;
        }
 public int ConjunctedWordId(Sentence sent)
 {
     // ищем соч связь между прилагательными через соч связь существительных
     if (FalseParentId > -1)
     {
         var falseElement = sent.GetElement(FalseParentId);
         var conjunctedWord = sent.Elements.Find(x => falseElement.ConjunctedWithId == x.Id);
         var firstChild = sent.SyntacticChildren(conjunctedWord).First(x =>
             (x.SyntacticRole.Value == SyntacticRole.AgreedAttribute.Value
              || x.SyntacticRole.Value == SyntacticRole.ConcordantAttr.Value)
             && x.GrammarInfo.IsSingular
             && x.ConjunctedWithId == -1);
         return firstChild.Id;
     }
     else if (SuspectedParentId > -1)
     {
         var suspectedElement = sent.GetElement(SuspectedParentId);
         var conjunctedWord = sent.Elements.Find(x => x.ConjunctedWithId == suspectedElement.Id);
         var firstChild = sent.SyntacticChildren(conjunctedWord).First(x =>
             (x.SyntacticRole.Value == SyntacticRole.AgreedAttribute.Value
              || x.SyntacticRole.Value == SyntacticRole.ConcordantAttr.Value)
             && x.GrammarInfo.IsSingular
             && x.ConjunctedWithId == -1);
         return firstChild.Id;
     }
     return -1;
 }
示例#11
0
        public static List<PredicatePartHelperObject> Analyze(int wordId, PredicatesBFinalResults predicates,
            Sentence sentence)
        {
            Debug.Assert(sentence.Elements.Count > 0);
            if (predicates.All.Count == 0)
                return null;

            Log.InfoFormat("Запущен алгоритм поиска управляющего сказуемого для слова с Id = {0}.", wordId);

            var canContinue = true;
            var parentElement = sentence.SyntacticParent(wordId);

            while (canContinue)
            {
                var rootPredicates = predicates.All.FindAll(x => x.PartType == PredicatePartType.Root);
                if (rootPredicates.Select(x => x.Id).Contains(parentElement.Id))
                    return
                        predicates.Items.Find(
                            x => x.Find(y => y.PartType == PredicatePartType.Root).Id == parentElement.Id);

                parentElement = sentence.SyntacticParent(parentElement);
                canContinue = parentElement != null;
            }

            return null;
        }
 protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
 {
     return PostProcessingUtils.ChangeSyntacticParent(Name
         , HelperDataElliptedNounLinkFeatureCoordinatingConjunctionId.Name
         , HelperDataElliptedNounLinkFeatureSSPESId.Name
         , sourceSentence, data);
 }
 protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
 {
     return PostProcessingUtils.ChangeSurfaceSlotToKnownValue(Name,
         HelperDataThenConjunctionId.Name
         , Consts.SurfaceSlotDefinedValues.CorrelateCondTemp
         , sourceSentence, data);
 }
 protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
 {
     return PostProcessingUtils.ChangeSyntacticParent(Name
         , HelperDataConcordanceResultlSPSSId.Name
         , HelperDataLostConjunctionLinkConjunctedWithSPSSParentId.Name
         , sourceSentence, data);
 }
示例#15
0
 public void Process(Sentence sourceSentence, BaseHelperData data)
 {
     Results = DoProcess(sourceSentence, data);
     if (Results.Count > 0)
         Log.InfoFormat("Выполнены действия по модификации лога:{0}{1}", Environment.NewLine, _dumpPostProcessingResults(Results));
     else
         Log.InfoFormat("Действий по модификации лога не было выполнено. [{0}] ", Name);
 }
 protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
 {
     return PostProcessingUtils.ChangeSurfaceSlot(Name,
         HelperDataQuasiUniformPartsAttachmentMainType2ConfirmedId.Name
         , HelperDataQuasiUniformPartsAttachmentMainType2ParentId.Name
         , HelperDataQuasiUniformPartsAttachmentMainType2ConfirmedNr.Name
         , HelperDataQuasiUniformPartsAttachmentMainType2ParentNr.Name
         , sourceSentence, data);
 }
        protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
        {
            var predicateValues = data.ColumnIntPositiveValues(HelperDataNearestPredicateAfterThenPredicateId.Name);
            var predicateValue = -1;
            if (predicateValues.Any())
                predicateValue = predicateValues.First();

            return PostProcessingUtils.ChangeSyntacticParentForKnownValue(Name,
                    HelperDataIfConjunctionParetntId.Name,
                    predicateValue
                    , sourceSentence, data);
        }
示例#18
0
        public void ApplyAlgorithms(string initialText,
            Action<AlgorithmsStageType, BaseSentenceAlgorithm, BaseSentenceAlgorithmData> singleAlgorithmCompleteCallback,
            Action<AlgorithmsStageType, BaseSentenceAlgorithm> singleAlgorithmStartCallback)
        {
            // сначала просто парсим, а потом применяем потоком все добавленные алгоритмы
            Log.InfoFormat("Применяем базовый алгоритм: {0}", _baseAlgorithm.Info.InternalName);
            (_baseAlgorithm as ComprenoSentenceParseAlgorithm).InitialText = initialText;

            var algResult = _baseAlgorithm.Process(null, true);
            InitialSentece = algResult.Sentence;

            _doApplyAlgorithms(singleAlgorithmCompleteCallback, singleAlgorithmStartCallback);
        }
示例#19
0
        protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
        {
            var result = new List<PostPropcessingActionInfo>();

            var wordPairs = new Dictionary<int, int>();

            // добавляем сочинительную связь между ССПСС и ПСС
            foreach (DataRow row in data.Rows)
                if (row.Field<int>(HelperDataConjunctedWordsForPSSConjunctedId.Name) > 0)
                wordPairs.Add(row.Field<int>(HelperDataConjunctedWordsForPSSConjunctedId.Name), row.Field<int>(HelperDataConjunctedWordsForPSSWordId.Name));

            PostProcessingUtils.AddConjunctionLink(Name, wordPairs, sourceSentence, result);

            return result;
        }
        protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
        {
            var result = new List<PostPropcessingActionInfo>();
            var words = new List<int>();

            foreach (DataRow row in data.Rows)
            {
                var sspWordId = row.Field<int>(HelperDataFindElliptedNounIntermedaiteFalseUpId.Name);
                if (sspWordId > 0)
                    words.Add(sspWordId);
            }

            PostProcessingUtils.DeleteConjunctionLink(Name, words, sourceSentence, result);

            return result;
        }
        protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
        {
            var result = new List<PostPropcessingActionInfo>();
            var words = new List<int>();

            foreach (DataRow row in data.Rows)
            {
                var suspectedId = row.Field<int>(HelperDataBetweenAndISuspectedId.Name);
                if (suspectedId > 0)
                    words.Add(suspectedId);
            }

            PostProcessingUtils.DeleteConjunctionLink(Name, words, sourceSentence, result);

            return result;
        }
        protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
        {
            var result = new List<PostPropcessingActionInfo>();
            var words = new List<KeyValuePair<int, string>>();

            foreach (DataRow row in data.Rows)
            {
                var parentForS = row.Field<int>(HelperDataFindFalseConjunctionSParetnForSId.Name);
                if (parentForS > 0)
                    words.Add(new KeyValuePair<int, string>(parentForS, SyntacticRole.IndirectObject.Value));
            }

            PostProcessingUtils.ChangeSyntacticRole(Name, words, sourceSentence, result);

            return result;
        }
示例#23
0
        public static Sentence Copy(Sentence sourceSentence)
        {
            var result = new Sentence
            {
                ParsingResult = ParsingResult.ReadFromString(sourceSentence.ParsingResult.Value),
                Text = sourceSentence.Text,
                XML = sourceSentence.XML,
            };

            foreach (var element in sourceSentence.Elements)
                result.Elements.Add(SentenceElement.Copy(element));

            result.Version++;

            return result;
        }
示例#24
0
        protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
        {
            var result = new List<PostPropcessingActionInfo>();
            var wordPairs = new Dictionary<int, int>();

            foreach (DataRow row in data.Rows)
            {
                var pesId = row.Field<int>(HelperDataUPAdjectiveForElliptedNounPESTrue.Name);
                var sspesId = row.Field<int>(HelperDataUPAdjectiveForElliptedNounSSPES.Name);

                if (pesId > -1 && sspesId > -1)
                    wordPairs.Add(pesId, sspesId);
            }

            // добавляем сочинительную связь между ССПСС и ПСС
            PostProcessingUtils.AddConjunctionLink(Name, wordPairs, sourceSentence, result);

            return result;
        }
示例#25
0
        protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
        {
            var result = new List<PostPropcessingActionInfo>();
            var wordPairs = new Dictionary<int, int>();
            foreach (DataRow row in data.Rows)
            {
                var parentId = row.Field<int>(HelperDataLostConjunctionLinkConjunctedWithSPSSId.Name);
                var childId = row.Field<int>(HelperDataConcordanceResultlSPSSId.Name);
                if (parentId > 0 && childId > 0)
                {
                    wordPairs.Add(parentId, childId);
                }

            }

            PostProcessingUtils.AddConjunctionLink(Name, wordPairs, sourceSentence, result);

            return result;
        }
示例#26
0
        private object[] _processParticiple(SentenceElement element, Sentence sentence, UniformPartsFinalResults upRows)
        {
            var participleId = element.Id;

            var hasChildrenNotServicePart = sentence.SyntacticChildren(participleId).Any(x =>
                x.SyntacticRole.Value != SyntacticRole.ParticleNegative.Value
                && x.SyntacticRole.Value != SyntacticRole.CoordinatingConjunction.Value
                && x.SyntacticRole.Value != SyntacticRole.Particle.Value);
            if (hasChildrenNotServicePart)
            {
                Log.InfoFormat("  Обнаружили потомка не СЧР. Причастие -- Причастие Финальное 1");
                var finalParticiple1 = participleId;
                return new object[] {participleId, finalParticiple1, -1, finalParticiple1, -1};
            }

            Log.InfoFormat("Причастие - Причастие - предварительное 2)");

            if (!upRows.All.Any(x => x.Id == participleId))
            {
                Log.InfoFormat("  Причастие не принадлежит ни одному из рядов. Причастие -- Признак 1");
                var participleFeature = participleId;
                return new object[] {participleId, -1, -1, -1, participleFeature};
            }

            var rowNr = upRows.All.Find(x => x.Id == participleId).RowNr;
            Log.InfoFormat("  Причастие принадлежит к ряду ОЧ {0}. Причастие - предваритиельное 3", rowNr);

            if (sentence.Elements.FindAll(x => upRows.All.Select(y => y.Id).Contains(x.SyntacticParentWordId)).Any(x =>
                x.SyntacticRole.Value != SyntacticRole.ParticleNegative.Value
                && x.SyntacticRole.Value != SyntacticRole.CoordinatingConjunction.Value
                && x.SyntacticRole.Value != SyntacticRole.Particle.Value))
            {
                Log.InfoFormat("  У сочиненных с рассматриваемым причастий нет потомков не СЧР. Причастие -- Признак 2");
                var participleFeature = participleId;
                return new object[] { participleId, -1, -1, -1, participleFeature };
            }
            else
            {
                Log.InfoFormat("  У сочиненных с рассматриваемым причастий есть хотя бы один потомок не СЧР. Причастие -- Финальное 2");
                var participleFinal2 = participleId;
                return new object[] { participleId, -1, participleFinal2, participleFinal2, -1 };
            }
        }
示例#27
0
        public static void AddConjunctionLink(string actionName, Dictionary<int, int> wordPairs, Sentence sourceSentence, List<PostPropcessingActionInfo> results)
        {
            foreach (var pair in wordPairs)
            {
                var leftWord = sourceSentence.Elements.Find(x => x.Id == pair.Key);
                var rightWord = sourceSentence.Elements.Find(x => x.Id == pair.Value);
                if (leftWord != null && rightWord != null)
                {
                    var oldLeftWordConjuctedWithId = leftWord.ConjunctedWithId;
                    var oldLeftWordConjuctedWithGUID = leftWord.ConjunctedWithGUID;

                    leftWord.ConjunctedWithId = rightWord.Id;
                    leftWord.ConjunctedWithGUID = rightWord.GUID;

                    results.Add(new PostPropcessingActionInfo(actionName, pair.Key, nameof(leftWord.ConjunctedWithId), oldLeftWordConjuctedWithId.ToString(), leftWord.ConjunctedWithId.ToString()));
                    results.Add(new PostPropcessingActionInfo(actionName, pair.Key, nameof(leftWord.ConjunctedWithGUID), oldLeftWordConjuctedWithGUID, leftWord.ConjunctedWithGUID));
                }

            }
        }
        protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
        {
            var result = new List<PostPropcessingActionInfo>();
            var words = new List<int>();

            foreach (DataRow row in data.Rows)
            {
                var sspWordId = row.Field<int>(HelperDataSubjectAndPredicateConjunctionSubjectIdSSP.Name);
                if (sspWordId > 0)
                    words.Add(sspWordId);

                var pssWordId = row.Field<int>(HelperDataSubjectAndPredicateConjunctionPredicateIdPSS.Name);
                if (pssWordId > 0)
                    words.Add(pssWordId);
            }

            PostProcessingUtils.DeleteConjunctionLink(Name, words, sourceSentence, result);

            return result;
        }
        private void _prepareData(DataRowCollection attachInfos, List<QuasiUPAttachmentHelperObject> attachments, Sentence sentence)
        {
            if (attachInfos.Count <= 0) return;

            foreach (DataRow attachInfo in attachInfos)
            {
                // 3.6
                var attachIdType1 =
                    attachInfo.Field<int>(HelperDataQuasiUniformPartsAttachmentPreliminaryIdType1.Name);
                // 3.2
                var attachIdType2 =
                    attachInfo.Field<int>(HelperDataQuasiUniformPartsAttachmentPreliminaryIdType2.Name);
                // 102
                var attachNr = attachInfo.Field<int>(HelperDataQuasiUniformPartsAttachmentPreliminaryNr.Name);

                if (attachIdType1 > 0)
                {
                    var newAttach = new QuasiUPAttachmentHelperObject(sentence.Elements.Find(x => x.Id == attachIdType1))
                    {
                        IsInitiallyType1 = true,
                        IsInitiallyType2 = false,
                        SourceNr = attachNr
                    };
                    Log.InfoFormat($"Создан КвазиОЧ Т1: Id: {newAttach.Id}, Текст: {newAttach.Text}");

                    attachments.Add(newAttach);
                }
                else if (attachIdType2 > 0)
                {
                    var newAttach = new QuasiUPAttachmentHelperObject(sentence.Elements.Find(x => x.Id == attachIdType2))
                    {
                        IsInitiallyType2 = true,
                        IsInitiallyType1 = false,
                        SourceNr = attachNr
                    };
                    Log.InfoFormat($"Создан КвазиОЧ Т2: Id: {newAttach.Id}, Текст: {newAttach.Text}");

                    attachments.Add(newAttach);
                }
            }
        }
        protected override List<PostPropcessingActionInfo> DoProcess(Sentence sourceSentence, BaseHelperData data)
        {
            var result = new List<PostPropcessingActionInfo>();

            var wordPairsgroups =
                data.Rows.Cast<DataRow>().GroupBy(grp => grp.Field<int>(HelperDataParticleISourceId.Name));

            var wordPairs = new Dictionary<int, int>();
            foreach (var group in wordPairsgroups)
            {
                wordPairs.Add(
                    group.Select(x => x.Field<int>(HelperDataParticleIParentConjuctedWordId.Name)).First(x => x > -1),
                    group.Select(x => x.Field<int>(HelperDataParticleIParentWordId.Name)).First(x => x > -1)
                    );
            }

            // добавляем сочинительную связь между родитилем И, и текстовым элементом, имеющим такую синт роль
            PostProcessingUtils.AddConjunctionLink(Name, wordPairs, sourceSentence, result);

            return result;
        }