Exemple #1
0
 public static void SetAttributeISSUBJECTforAllEntity(this SubjectData subjectData, int value)
 {
     foreach (var st in subjectData.SubjectEssences)
     {
         st.Entity.SetAttributeISSUBJECT(value);
     }
 }
Exemple #2
0
        private SubjectData _GetSubjectData(XElement subsent, XElement breakSearchElement, bool breakByQuote)
        {
            subsent.ThrowIfNotSubsent();

            if (subsent.IsSubsentHasObject() || subsent.IsSubsentInDirectSpeech())
            {
                return(null);
            }

            var tuples = from it in subsent.Elements().TakeWhile(_ => _ != breakSearchElement)
                         where it.IsElementCET() && it.IsVALUEStartsWith(CET_WORDS)

                         let @saaet = GetTuple(it, breakByQuote)
                                      where @saaet.IsNotNull()

                                      where IsFollowingCondition(@saaet.Entity, breakByQuote)
                                      select @saaet;

            var aarray = tuples.ToArray();

            if (!aarray.Any())
            {
                return(null);
            }

            var verbValue       = ENTITY_WORDS.AnyEx() ? CET_WORDS.First() + ' ' + ENTITY_WORDS.First() : null;
            var subjectEssences = new List <SubjectEssence>();

            foreach (var a in aarray)
            {
                subjectEssences.Add(verbValue.IsNotNull() ? new SubjectEssence(a, verbValue)
                                                           : new SubjectEssence(a));
            }

            var subjectData = new SubjectData(subjectEssences, aarray.First().Entity, aarray.Last().Entity);

            return(subjectData);

            #region commented

            /*var a = t.FirstOrDefault();
             * if ( a == null )
             *  return (null);
             *
             * var subjectEssences = new[] { ENTITY_WORDS.AnyEx() ? new SubjectEssence( a, CET_WORDS.First() + ' ' + ENTITY_WORDS.First() )
             *                                                 : new SubjectEssence( a ) };
             * var subjectData = new SubjectData( subjectEssences, a.Entity, a.Entity );
             * return (subjectData);*/
            #endregion
        }
Exemple #3
0
        protected override bool IsParentMatchCondition(SubsentTuple tuple, Language language, out IEnumerable <SubjectData> subjectData)
        {
            subjectData = null;

            if (tuple.CHILD_DP.IsSubsentHasSubject())
            {
                return(false);
            }
            var verb = GetVerb(tuple.CHILD_DP.ElementsVerb(), language);

            if (verb.IsNull())
            {
                return(false);
            }

            var elements = tuple.CHILD_DP.ElementsBeforeSelf();

            if (elements.IsHasSubject())
            {
                return(false);
            }
            var subjects = GetSubjects(elements);

            if (!subjects.AnyEx())
            {
                return(false);
            }


            var subjectEssences = new List <SubjectEssence>();

            foreach (var s in subjects)
            {
                subjectEssences.Add(new SubjectEssence(s, verb));
            }

            var sd = new SubjectData(subjectEssences, subjects.First().Entity, verb);

            subjectData = sd.RepeatOnce();
            return(true);
        }
        public virtual SubjectObjectsTuple Process(SubsentTuple tuple, Language language, int directAndIndirectSpeechGlobalNumber
                                                   , ObjectAllocateMethod objectAllocateMethod, SubjectObjectsTuple DSsubjectObjectsTuple)
        {
            #region [.condition.]
            var subjects = default(IEnumerable <SubjectData>);
            if (!IsParentMatchCondition(tuple, language, out subjects) ||
                !IsChildMatchCondition(tuple, language))
            {
                return(null);
            }
            #endregion

            //проверяем, что субъект высказывания Entity из DS остался тот же
            var e1 = from s1 in DSsubjectObjectsTuple.Subjects
                     from s2 in s1.SubjectEssences
                     select s2.Entity;
            var e2 = from s1 in subjects
                     from s2 in s1.SubjectEssences
                     select s2.Entity;
            if (e2.Except(e1).Any())
            {
                return(null);
            }

            #region [.match condition.]
            MatchActionDebugInfoOutput(this.Id);

            //set 'ISSUBJECT' attribute for subject-entity
            subjects.SetAttributeISSUBJECTforAllEntity(directAndIndirectSpeechGlobalNumber);

            //set 'ISOBJECT' attribute for all object-entity
            var id = subjects.GetAttributeIDForce();

            //allocate objects
            var subsents = tuple.CHILD.AfterAndSelfSubsents().ToArray();
            var objects  = subsents.TryAllocateObjectsInSubsents(objectAllocateMethod, id).ToArray();

            //mark begin-end IndirectSpeech-subsents
            subsents.SetAttributeINDIRECTSPEECH_BEGINEND_4Subsents(directAndIndirectSpeechGlobalNumber);

            //add 2 result
            var v1 = from s1 in DSsubjectObjectsTuple.Subjects
                     from s2 in s1.SubjectEssences
                     select s2.VerbValue;
            var v2 = from s1 in subjects
                     from s2 in s1.SubjectEssences
                     select s2.VerbValue;
            //склеиваем название нескольких (к.п. 2-х) глаголов
            var verbsValues = v1.Concat(v2).Distinct().JoinBy(", ");

            //создем новые пары субъект высказывания Entity - название нескольких (к.п. 2-х) глаголов Verb
            var se = from s1 in DSsubjectObjectsTuple.Subjects
                     from s2 in s1.SubjectEssences
                     select new SubjectEssence(s2, verbsValues);

            //создем новый IEnumerable< SubjectData >
            subjects = new SubjectData
                       (
                se.ToList(),
                DSsubjectObjectsTuple.Subjects.First().LeftExtremeElement,
                subjects.Last().RightExtremeElement
                       )
                       .RepeatOnce();
            //создаем объединенный результат some-rule-DS + IS_ParentChild_DanglingParticipleAfterDS_01
            return(new SubjectObjectsTuple(subjects,
                                           DSsubjectObjectsTuple.Objects.Select(o => o.Entity).Concat(objects),
                                           DSsubjectObjectsTuple.RuleId + " + " + Id));

            #endregion
        }
Exemple #5
0
        public override SubjectObjectsTuple Process(SubsentPair pair, Language language
                                                    , ref int directAndIndirectSpeechGlobalNumber, ObjectAllocateMethod objectAllocateMethod)
        {
            #region [.condition.]
            SubjectData sd = null;

            var u = inderectspeech1.GetElementUByCondition(pair.SUBSENT1.Elements());
            if (u.IsNull())
            {
                return(null);
            }

            sd = pattern1.GetSubjectData(u.ElementsAfterSelf(), language);
            if (sd.IsNull())
            {
                return(null);
            }

            var u2 = inderectspeech1.GetElementUByCondition(sd.RightExtremeElement.ElementsAfterSelf());
            if (u2.IsNull())
            {
                return(null);
            }
            #endregion

            #region [.match condition.]
            //allocate objects
            var subsents2 = (SubsentsIsSwaped ? pair.SUBSENT2.BeforeAndSelfSubsents() :
                             pair.SUBSENT2.AfterAndSelfSubsents()
                             ).ToArray();

            if (sd.HasAnySubjectEntityAncestorInAnySubsents(subsents2))
            {
                return(null);
            }

            MatchActionDebugInfoOutput(this.Id);

            //growup global IndirectSpeech-subsent number
            directAndIndirectSpeechGlobalNumber++;

            //set 'ISSUBJECT' attribute for subject-entity
            sd.SetAttributeISSUBJECTforAllEntity(directAndIndirectSpeechGlobalNumber);

            //set 'ISOBJECT' attribute for all object-entity
            var id = sd.FirstEntity().GetAttributeIDForce();

            //allocate objects in IndirectSpeech-subsents-2
            var objects2 = subsents2.TryAllocateObjectsInSubsents(objectAllocateMethod, id).ToArray();

            //mark begin-end IndirectSpeech-subsents-2
            subsents2.SetAttributeINDIRECTSPEECH_BEGINEND_4Subsents(directAndIndirectSpeechGlobalNumber);

            var objects1 = pair.SUBSENT1.ElementsExceptT().TakeWhile(e => e != u).TryAllocateObjects(objectAllocateMethod, id).ToArray();
            //mark begin-end IndirectSpeech-subsent-1
            pair.SUBSENT1.Elements().TakeWhile(e => e != u).SetAttributeINDIRECTSPEECH_BEGINEND(directAndIndirectSpeechGlobalNumber);

            //build all objects
            var objects = objects1
                          .Concat
                          (
                objects2
                          )
                          .ToArray();

            //add 2 result
            return(new SubjectObjectsTuple(sd.RepeatOnce(), objects, Id));

            #endregion
        }
Exemple #6
0
 public static XElement FirstEntity(this SubjectData subjectData)
 {
     return(subjectData.SubjectEssences.First().Entity);
 }