コード例 #1
0
        /// <summary>
        /// Добавление в иерархию текущего подпредложения, являющегося причастным или деепричастным оборотом
        /// </summary>
        /// <param name="lastAdded">последнее добавленное подпредложение</param>
        private void AddCurrentDanglingParticipleOrParticipialToHierarchy(SubSentenceInfo lastAdded)
        {
            #region [.defense.]
            if (lastAdded == null)
            {
                throw new ArgumentNullException("lastAdded");
            }
            if ((CurrentSubSentence.SubSentence.Type != SubSentenceType.DanglingParticiple) &&
                (CurrentSubSentence.SubSentence.Type != SubSentenceType.Participial))
            {
                throw new ArgumentException("Current subsentence isn't DanglingParticiple or Participial");
            }
            #endregion

            SubSentenceInfo parent = null;
            if (CurrentSubSentence.IsExistSubject())
            {
                parent = lastAdded;
            }
            else             /// поиск определяемого слово в других подпредложениях в иерархии
            {
                parent = FindParentWithDeterminerUpToHierarchy(lastAdded);
            }

            if ((CurrentSubSentence.IsExistSubject()) &&
                (CurrentSubSentence.SubSentence.Type == parent.SubSentence.Type) &&
                (CurrentSubSentence.SubSentence.Subject == parent.SubSentence.Subject))
            /// определяемое слово совпадает с определяемым словом родительского подпредложения того же типа -
            /// сделаем их подпредложениями одного уровня
            {
                parent = lastAdded.Parent;
            }
            parent.AddChild(CurrentSubSentence);
        }
コード例 #2
0
        /// <summary>
        /// Проверка, что текущее подпредложение должно быть частью предыдущего подпредложения
        /// </summary>
        /// <param name="previous">предыдущее подпредложение</param>
        /// <returns>результат проверки</returns>
        private bool IsCurrentPartOfPrevious(SubSentenceInfo previous)
        {
            #region [.defense.]
            if (CurrentSubSentence.IsContainConjunction)
            {
                throw new InvalidOperationException("Current subsentence have conjunction");
            }
            #endregion

            bool result = false;
            switch (previous.SubSentence.Type)
            {
            case SubSentenceType.DanglingParticiple:
            case SubSentenceType.Participial:
                result = !(CurrentSubSentence.IsExistVerb() || CurrentSubSentence.IsExistSubject());
                break;

            case SubSentenceType.Default:
            case SubSentenceType.Subordinate:
                result = !(CurrentSubSentence.IsExistVerb() && previous.IsExistVerb()) &&
                         !((CurrentSubSentence.IsHasLingvisticEntity() || CurrentSubSentence.SubSentence.Children.Any()) &&
                           (previous.IsHasLingvisticEntity() || previous.SubSentence.Children.Any()));
                break;
            }
            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Получение подпредложения, расположенного на том же уровне, куда надо вставлять текущее
        /// дополнительно указывается флаг, следует ли соединить это подпредложение с текущим
        /// </summary>
        /// <param name="brother">результирующее подпредложение</param>
        /// <param name="lastAdded">последнее добавленное подпредложение</param>
        /// <returns>флаг, следует ли соединить результирующее подпредложение с текущим</returns>
        private bool GetCurrentBrother(ref SubSentenceInfo brother, SubSentenceInfo lastAdded)
        {
            if (brother.Parent != null)
            {
                SubSentenceInfo previousSubSentence = GetRightBorderSubSentence(brother.Parent);
                if (!CurrentSubSentence.IsExistSubject())
                {
                    bool isPartOfPrevious = IsCurrentPartOfPrevious(previousSubSentence, lastAdded);
                    if (isPartOfPrevious || CurrentSubSentence.IsExistSubject())
                    {
                        brother = previousSubSentence;
                        return(isPartOfPrevious);
                    }
                }

                if (CurrentSubSentence.IsContainConjunction && (previousSubSentence != null))
                {
                    brother = previousSubSentence;
                    return(false);
                }

                brother = brother.Parent;
                if (IsConjunctionSeria(previousSubSentence))
                {
                    return(true);
                }
                else
                {
                    return(GetCurrentBrother(ref brother, lastAdded));
                }
            }
            return(IsCurrentPartOfPrevious(brother, lastAdded));
        }
コード例 #4
0
        /// <summary>
        /// Поиск вверх по иерархии родительского подпредложения, в котором содержится определяемое слово для текущего
        /// </summary>
        /// <param name="parent">первое возможное родительское подпредложение</param>
        /// <returns>родительское подпредложение</returns>
        private SubSentenceInfo FindParentWithDeterminerUpToHierarchy(SubSentenceInfo parent)
        {
            SubSentenceInfo result = parent;

            while (!CurrentSubSentence.IsExistSubject() && (result.Parent != null))
            {
                SetCurrentDeterminer(result.Parent);
                result = result.Parent;
            }
            return(CurrentSubSentence.IsExistSubject() ? result : parent);
        }
コード例 #5
0
        /// <summary>
        /// Установка определяемого слова для текущего подпредложения, являющегося причастным оборотом
        /// </summary>
        /// <param name="parent">родительское подпредложение</param>
        private void SetCurrentParticipialDeterminer(SubSentenceInfo parent)
        {
            Entity participle = CurrentSubSentence.Participles.First();
            Entity lastEntity = (Entity)parent.SubSentence.Units.LastOrDefault(_ => _.UnitTextType == UnitTextType.ENTITY);

            if (lastEntity != null)
            {
                CurrentSubSentence.SubSentence.Subject = GetConsistencyEntity(lastEntity, participle);
            }
            if (!CurrentSubSentence.IsExistSubject() && (parent.SubSentence.Type == SubSentenceType.Participial))
            {
                if (IsConsistency(parent.Participles.First(), participle))
                {
                    CurrentSubSentence.SubSentence.set_SubjectSubSentence(parent.SubSentence);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Проверка, что текущее подпредложение должно быть частью предыдущего подпредложения
        /// </summary>
        /// <param name="previous">предыдущее подпредложение</param>
        /// <param name="lastAdded">последнее добавленное подпредложение</param>
        /// <returns>результат проверки</returns>
        private bool IsCurrentPartOfPrevious(SubSentenceInfo previous, SubSentenceInfo lastAdded)
        {
            if ((previous != null) && !CurrentSubSentence.IsExistSubject())
            {
                bool isPossiblePart = true;
                if (previous == lastAdded)
                {
                    UnitTextBase firstUnit = CurrentSubSentence.SubSentence.Units.FirstOrDefault(_ => !_.IsEmptyText());
                    if ((firstUnit != null) && !DictionaryResource.IsHomogeneousConjunction(firstUnit.Text))
                    /// подпредложения не будут соединены
                    {
                        isPossiblePart = false;

                        UnitTextBase secondUnit = firstUnit.GetNonEmptyNext();
                        if (IsAnyType(previous.SubSentence, SubSentenceType.Subordinate) && !(CurrentSubSentence.IsContainConjunction ||
                                                                                              (firstUnit.IsSeparator(",") && (secondUnit != null) && DictionaryResource.IsHomogeneousConjunction(secondUnit.Text))))
                        /// не пытаемся восстановить подлежащее
                        {
                            return(false);
                        }
                    }
                }

                if (IsAnyType(previous.SubSentence, SubSentenceType.Default, SubSentenceType.Subordinate))
                {
                    if (IsCurrentSubject(previous.SubSentence.Subject))
                    {
                        if (CurrentSubSentence.IsContainConjunction || (CurrentSubSentence.IsExistVerb() && previous.IsExistVerb()))
                        {
                            CurrentSubSentence.SubSentence.set_SubjectSubSentence(previous.SubSentence);
                        }
                        else
                        {
                            return(isPossiblePart);
                        }
                    }
                }
                else if (!CurrentSubSentence.IsContainConjunction)
                {
                    return(isPossiblePart && IsCurrentPartOfPrevious(previous));
                }
            }
            return(false);
        }
コード例 #7
0
        /// <summary>
        /// Установка подлежащего для текущего подпредложения
        /// </summary>
        private void SetCurrentSubject()
        {
            List <Entity> subjects = new List <Entity>();

            foreach (UnitTextBase unit in CurrentSubSentence.SubSentence.Units.Where(_ => _.IsEntity))
            {
                Entity entity = (Entity)unit;
                if (entity.IsSentenceMember() && IsCurrentSubject(entity))
                {
                    subjects.Add(entity);
                }
            }
            if (subjects.Any())
            {
                CurrentSubSentence.SubSentence.Subject = subjects.FirstOrDefault(_ => _.IsSubject());
                if (!CurrentSubSentence.IsExistSubject())
                {
                    CurrentSubSentence.SubSentence.Subject = subjects.FirstOrDefault();
                }
            }
        }