コード例 #1
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);
        }
コード例 #2
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));
        }
コード例 #3
0
 /// <summary>
 /// Добавление деепричастия в текущее подпредложение
 /// </summary>
 /// <param name="deepr">деепричастие</param>
 private void AddDeeprToCurrent(Entity deepr)
 {
     if (CurrentSubSentence.IsExistVerb() && (CurrentType != SubSentenceType.DanglingParticiple))
     /// неверно обособленный деепричастный оборот - отсутствует левая граница
     {
         CreateNewSubSentence(deepr.Previous);
     }
     CurrentSubSentence.Verbs.Add(deepr);
     SetCurrentTypeByVerbForm(deepr);
 }
コード例 #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="verb">глагол</param>
        private void AddVerbToCurrent(Entity verb)
        {
            /// глагол в деепричастном обороте: неверно обособленный деепричастный оборот - отсутствует правая граница
            bool isVerbInDanglingParticiple = (CurrentType == SubSentenceType.DanglingParticiple);

            if (isVerbInDanglingParticiple || (CurrentSubSentence.IsExistVerb() && !IsCompoundVerbInCurrent(verb)))
            {
                CreateNewSubSentenceByVerbForm(verb);
            }
            else
            {
                SetCurrentTypeByVerbForm(verb);
                CurrentSubSentence.Verbs.Add(verb);
            }
        }
コード例 #6
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);
                }
            }
        }
コード例 #7
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);
        }
コード例 #8
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();
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Установка типа подпредложения по форме глагола
        /// </summary>
        /// <param name="verb">форма глагола</param>
        private void SetCurrentTypeByVerbForm(Entity verb)
        {
            switch (verb.Type.EntityType)
            {
            case EntityType.Verb:
                if (!CurrentSubSentence.IsExistVerb() && !CurrentSubSentence.IsContainConjunction)
                {
                    CurrentSubSentence.SubSentence.Type = SubSentenceType.Default;
                }
                break;

            case EntityType.Infinitive:
                if (!CurrentSubSentence.IsExistVerb() && !CurrentSubSentence.IsContainConjunction &&
                    !CurrentSubSentence.Participles.Any())
                {
                    CurrentSubSentence.SubSentence.Type = SubSentenceType.Default;
                }
                break;

            case EntityType.Deepr:
                CurrentSubSentence.SubSentence.Type = SubSentenceType.DanglingParticiple;
                break;

            case EntityType.Participle:
                if (!CurrentSubSentence.IsExistVerb() && !CurrentSubSentence.IsContainConjunction)
                {
                    CurrentSubSentence.SubSentence.Type = SubSentenceType.Participial;
                }
                break;

                #region [.defense.]
            default:
                throw new ArgumentException("entity isn't verb");
                #endregion
            }
        }