コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        private void _processConfirmedAttach(QuasiUPAttachmentHelperObject confirmedAttach, List<QuasiUPAttachmentHelperObject> additionalAttachments, Sentence sentence, QuasiUniformPartsAttachmentMainHelperData resultHelpData)
        {
            Log.InfoFormat("Обрабатываем подтвержденный КвазиОЧ-Приложение. Тип1: {0}, Тип2: {1}, Текст: {2}, Id: {3}", confirmedAttach.Type1Confirmed, confirmedAttach.Type2Confirmed, confirmedAttach.Text, confirmedAttach.Id);

            var attachParentElement = sentence.SyntacticParent(confirmedAttach);
            if (attachParentElement != null)
            {
                Log.InfoFormat("  Нашли родителя: Текст: {0}, Id: {1}", attachParentElement.Id, attachParentElement.Text);
                if (attachParentElement.GrammarInfo.PartOfSpeech.Value == PartOfSpeech.Noun.Value || attachParentElement.GrammarInfo.PartOfSpeech.Value == PartOfSpeech.Pronoun.Value)
                {
                    Log.InfoFormat("  У родителя часть речи: существительное или местоимение, добавляем квази ОЧ.");
                    var attachParentElementWithHelperInfo = new QuasiUPAttachmentHelperObject(attachParentElement)
                    {
                        SourceNr = -1,
                        Type1Confirmed = confirmedAttach.Type1Confirmed,
                        Type2Confirmed = confirmedAttach.Type2Confirmed,
                        IsInitiallyType1 = confirmedAttach.IsInitiallyType1,
                        IsInitiallyType2 = confirmedAttach.IsInitiallyType2,
                        IsAdditional = true,
                        AddedParent = true,
                        NewNr = confirmedAttach.SourceNr
                    };
                    additionalAttachments.Add(attachParentElementWithHelperInfo);
                }
                else if(attachParentElement.GrammarInfo.PartOfSpeech.Value == PartOfSpeech.Verb.Value)
                {
                    Log.InfoFormat("  У родителя часть речи: глагол, ищем потомков-существительные с таким же падежом, как у обрабатываемого Квази ОЧ.");
                    var parentChildren = sentence.SyntacticChildren(attachParentElement).FindAll(
                                x => x.GUID != confirmedAttach.GUID
                                && x.GrammarInfo.PartOfSpeech.Value == PartOfSpeech.Noun.Value
                                && x.GrammarInfo.Case.Value == confirmedAttach.GrammarInfo.Case.Value);

                    if (parentChildren.Count > 0)
                    {
                        foreach (var child in parentChildren)
                        {
                            Log.InfoFormat("    Добавляем потомка-существительного с падежом {0} к результирующему массиву", confirmedAttach.GrammarInfo.Case.Value);
                            var childWithHelperInfo = new QuasiUPAttachmentHelperObject(child)
                            {
                                SourceNr = -1,
                                Type1Confirmed = confirmedAttach.Type1Confirmed,
                                Type2Confirmed = confirmedAttach.Type2Confirmed,
                                IsInitiallyType1 = confirmedAttach.IsInitiallyType1,
                                IsInitiallyType2 = confirmedAttach.IsInitiallyType2,
                                IsAdditional = true,
                                AddedChildForParent =  true,
                                NewNr = confirmedAttach.SourceNr
                            };
                            additionalAttachments.Add(childWithHelperInfo);
                        }
                    }
                    else
                        Log.InfoFormat("  У родителя с PartOfSpeech = {0} не найдены потомки-существительные в падеже {1}, кроме текущего активного элемента. Ничего не делаем", attachParentElement.GrammarInfo.PartOfSpeech.Value, confirmedAttach.GrammarInfo.Case.Value);
                }
            }
            else
                Log.Error("Для данного ТЭ не найден синтаксический родитель!");
        }