Пример #1
0
        private Paragraph MoveAdverbUnitBeforeVBOrPASTorPRESUnit(
            Text[] sentenceArray, int adverbIndexPosition)
        {
            int vbPastPresPosition = _sentence.GetPositionOfClosestSpecifiedUnit(
                sentenceArray, adverbIndexPosition, text => text.IsVbPastPres());

            Text[] adverbUnit = GetAdverbUnit(
                sentenceArray, adverbIndexPosition);

            Text[] PastPresUnitAndTag =
                sentenceArray
                .Skip(vbPastPresPosition - 1)
                .Take(vbPastPresPosition + 1).ToArray();

            Text[] beforePastPresent =
                sentenceArray
                .Take(vbPastPresPosition - 1).ToArray();

            Text[] breaker =
                _sentence.GetSentenceBreaker(sentenceArray);

            Text[] shuffledSentence =
                beforePastPresent
                .Concat(adverbUnit)
                .Concat(PastPresUnitAndTag)
                .Concat(breaker).ToArray();

            return(new Paragraph(
                       OpenXmlHelper.BuildWordsIntoOpenXmlElement(shuffledSentence)));
        }
Пример #2
0
        public Paragraph ShuffleSentenceUnit(Paragraph xmlSentenceElement)
        {
            _sentence = new Sentence(xmlSentenceElement);
            Text[] sentenceArray = _sentence.SentenceArray;

            if (_sentence.UnitNotFoundInSentence(
                    sentenceArray,
                    element => element.InnerText.IsPren()))
            {
                return(xmlSentenceElement);
            }

            _sentence.PrenUnitCount = 0;
            var prenUnits = GetPrenUnits(
                sentenceArray).ToArray <IMoveableUnit>();

            Text[] prenUnitsInSerialNumberDescendingOrder =
                _sentence.GetMoveableUnitsInSerialNumberDescendingOrder(
                    _sentence.PrenUnitCount, prenUnits, sentenceArray)
                .RemoveTags("NN");     //TagMarks.Noun;

            Text[] beforePrenUnits =
                sentenceArray.Take(prenUnits[0].StartPosition).ToArray();

            Text[] newSentence = _sentence.RemoveAnyBlankSpaceFromEndOfUnit(
                beforePrenUnits
                .Concat(prenUnitsInSerialNumberDescendingOrder)
                .Concat(_sentence.GetSentenceBreaker(sentenceArray))
                .ToArray()
                .RemoveAnyDoubleSpaces());

            return(new Paragraph(
                       OpenXmlHelper.BuildWordsIntoOpenXmlElement(
                           newSentence)));
        }
Пример #3
0
        public Paragraph ShuffleSentenceUnit(Paragraph xmlSentenceElement)
        {
            _sentence = new Sentence(xmlSentenceElement);
            Text[] sentenceArray = _sentence.SentenceArray;

            if (_sentence.UnitNotFoundInSentence(
                    sentenceArray,
                    element => element.InnerText.IsModifier()))
            {
                return(xmlSentenceElement);
            }

            _sentence.ModifierCount = 0;
            var modifierUnits = GetModifierUnits(
                sentenceArray).ToArray <IMoveableUnit>();

            _sentence.UnderlineJoinedSentenceUnit(
                sentenceArray,
                modifierUnits[0].StartPosition,
                modifierUnits[_sentence.ModifierCount - 1].EndPosition);

            Text[] modifierUnitsInSerialNumberOrder =
                _sentence.GetMoveableUnitsInSerialNumberDescendingOrder(
                    _sentence.ModifierCount, modifierUnits, sentenceArray);

            Text[] newSentence;

            if (_sentence.HasPrenToTheLeft(
                    sentenceArray, modifierUnits[0].StartPosition))
            {
                newSentence = MoveModifierUnitBeforePren(
                    sentenceArray,
                    modifierUnitsInSerialNumberOrder,
                    modifierUnits[0].StartPosition);
            }
            else
            {
                var beforeModifier =
                    sentenceArray.Take(modifierUnits[0].StartPosition);

                newSentence =
                    beforeModifier
                    .Concat(_modifierFormatter.ApplyFormattingRules(
                                modifierUnitsInSerialNumberOrder)).ToArray();
            }

            newSentence = _sentence.RemoveAnyBlankSpaceFromEndOfUnit
                              (newSentence
                              .Concat(
                                  _sentence.GetSentenceBreaker(sentenceArray))
                              .ToArray().RemoveAnyDoubleSpaces());

            return(new Paragraph(
                       OpenXmlHelper.BuildWordsIntoOpenXmlElement(
                           newSentence)));
        }
        public Paragraph ShuffleSentenceUnit(Paragraph xmlSentenceElement)
        {
            Text[] sentenceArray = xmlSentenceElement.Descendants <Text>().ToArray();

            if (Array.Exists(
                    sentenceArray, element => element.InnerText == _clauserTag))
            {
                int clauserIndexPosition =
                    Array.FindIndex(sentenceArray, i => i.InnerText == _clauserTag);

                if (IsClauserUnit(sentenceArray[clauserIndexPosition].Parent)) // what if not? - test for more 2 cs with one false -Sony EricCSon
                {
                    if (clauserIndexPosition == 0)
                    {
                        return(xmlSentenceElement); // no need to shuffle if clauser is already at beginning
                    }
                    if (!CommaFollowingTheClauserUnit(sentenceArray, clauserIndexPosition))
                    {
                        Text[] beforeClauser;
                        Text[] afterClauser;

                        ArrayUtility.SplitArrayAtPosition(sentenceArray, clauserIndexPosition, out beforeClauser, out afterClauser);

                        int nextBKPPosition =
                            GetPositionOfNextBreakerUnit(afterClauser);

                        if (nextBKPPosition == -1)
                        {
                            throw new XmlException("Full stop not found in this sentence");
                        }

                        if (NextBreakerIsAFullStop(afterClauser, nextBKPPosition))  // Future could be ! or ?
                        {
                            afterClauser[nextBKPPosition + 1] = new Text(",");

                            Array.Resize(ref beforeClauser, beforeClauser.Length + 2);
                            beforeClauser[beforeClauser.Length - 2] = new Text(TagMarks.BreakerPunctuation);
                            beforeClauser[beforeClauser.Length - 1] = new Text(".");

                            var arr = afterClauser.Concat(beforeClauser).ToArray();
                            List <OpenXmlElement> wordElements = OpenXmlHelper.BuildWordsIntoOpenXmlElement(arr);

                            xmlSentenceElement = new Paragraph(wordElements);
                            return(xmlSentenceElement);
                        }
                    }
                    else
                    {
                        MoveClauserAndCommaToBeginningOfSentence(sentenceArray, clauserIndexPosition);
                    }
                }
            }

            return(xmlSentenceElement);
        }
Пример #5
0
        private Paragraph MoveSingleAdverbBeforeVBOrPASTorPRESUnit(
            Text[] sentenceArray, int adverbIndexPosition, int adverbBreakerPosition)
        {
            var VbPastPresPosition =
                _sentence.GetPositionOfClosestSpecifiedUnit(
                    sentenceArray, adverbIndexPosition, text => text.IsVbPastPres());

            var adverbUnit =
                sentenceArray
                .Skip(adverbIndexPosition)
                .Take(adverbBreakerPosition - adverbIndexPosition);

            Text[] beforeVbPastPres;
            Text[] afterVbPastPres;

            ArrayUtility.SplitArrayAtPosition(
                sentenceArray, VbPastPresPosition, out beforeVbPastPres, out afterVbPastPres);

            Text[] beforeADV;
            Text[] afterADV;

            ArrayUtility.SplitArrayAtPosition(
                afterVbPastPres, adverbIndexPosition, out beforeADV, out afterADV);

            var vbPastPres =
                OpenXmlTextHelper.RemoveUnitFromOriginalPosition(
                    beforeADV, t => t.IsAdverb());

            var arr =
                beforeVbPastPres
                .Concat(adverbUnit)
                .Concat(vbPastPres)
                .Concat(afterADV).ToArray();

            if (arr[arr.Length - 3].Text == " " &&
                (arr[arr.Length - 4].Text == " " ||
                 arr[arr.Length - 4].Text.EndsWith(" ")))
            {
                arr = arr.RemoveAt(arr.Length - 3);
            }

            var wordElements = OpenXmlHelper.BuildWordsIntoOpenXmlElement(arr);

            return(new Paragraph(wordElements));
        }
Пример #6
0
        private Paragraph MoveAdverbUnitBetweenTheVBAAndPASTPRES(Text[] sentenceArray, int adverbIndexPosition)
        {
            //get VBA pos
            Text[] beforeAdverb;
            var    VBAPosition = _sentence.GetVBAPosition(out beforeAdverb, sentenceArray, adverbIndexPosition);

            Text[] adverbUnit = GetAdverbUnit(sentenceArray, adverbIndexPosition);

            int pastPresPosition =
                _sentence.GetFirstPastPresPositionAfterVBA(beforeAdverb, VBAPosition);

            Text[] sentenceToVBA    = sentenceArray.Take(VBAPosition + 2).ToArray();
            Text[] pastPresUnit     = sentenceArray.Skip(pastPresPosition - 1).Take(pastPresPosition + 1).ToArray();
            Text[] breaker          = sentenceArray.Skip(sentenceArray.Length - 3).ToArray();
            var    shuffledSentence = sentenceToVBA.Concat(adverbUnit).Concat(pastPresUnit).Concat(breaker).ToArray();

            return(new Paragraph(OpenXmlHelper.BuildWordsIntoOpenXmlElement(shuffledSentence)));
        }
Пример #7
0
        public Paragraph ShuffleSentenceUnit(Paragraph xmlSentenceElement)
        {
            _sentence = new Sentence(xmlSentenceElement);
            Text[] sentenceArray = _sentence.SentenceArray;

            if (_sentence.UnitNotFoundInSentence(
                    sentenceArray,
                    element => element.InnerText.IsTimer()))
            {
                return(xmlSentenceElement);
            }

            _sentence.TimerUnitCount = 0;
            var timerUnits = GetTimerUnits(
                sentenceArray).ToArray <IMoveableUnit>();

            _sentence.UnderlineJoinedSentenceUnit(
                sentenceArray,
                timerUnits[0].StartPosition,
                timerUnits[_sentence.TimerUnitCount - 1].EndPosition);

            Text[] timerUnitsInSerialNumberOrder =
                _sentence.GetMoveableUnitsInSerialNumberDescendingOrder(
                    _sentence.TimerUnitCount, timerUnits, sentenceArray);

            Text[] newSentence;

            if (_sentence.HasVbVbaPastToTheLeft(
                    sentenceArray, timerUnits[0].StartPosition))
            {
                newSentence = MoveTimerUnitBeforeVbVbaPast(
                    sentenceArray,
                    timerUnitsInSerialNumberOrder,
                    timerUnits[0].StartPosition);
            }
            else if (_sentence.HasDGToTheLeft(
                         sentenceArray, timerUnits[0].StartPosition))
            {
                int dGIndexPosition =
                    Array.FindIndex(sentenceArray, i => i.IsDG());

                newSentence = MoveTimerUnitBeforeDGUnit(
                    sentenceArray,
                    dGIndexPosition,
                    timerUnitsInSerialNumberOrder);
            }
            else
            {
                var beforeTimer =
                    sentenceArray.Take(timerUnits[0].StartPosition);

                newSentence =
                    beforeTimer.Concat(timerUnitsInSerialNumberOrder).ToArray();
            }

            newSentence = _sentence.RemoveAnyBlankSpaceFromEndOfUnit
                              (newSentence
                              .Concat(
                                  _sentence.GetSentenceBreaker(sentenceArray)).ToArray());

            return(new Paragraph(
                       OpenXmlHelper.BuildWordsIntoOpenXmlElement(
                           newSentence)));
        }