Exemplo n.º 1
0
        /**
         * Grabs the head verb of the verb phrase and sets it to future tense if the
         * phrase is future tense. It also turns off negation if the group has a
         * modal.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this noun phrase.
         * @param tenseValue
         *            the <code>Tense</code> of the phrase.
         * @param hasModal
         *            <code>true</code> if the verb phrase has a modal.
         * @return the modified head element
         */

        private static INLGElement grabHeadVerb(PhraseElement phrase,
                                                Tense tenseValue, bool hasModal)
        {
            INLGElement frontVG = phrase.getHead();

            if (frontVG != null)
            {
                if (frontVG is WordElement)
                {
                    frontVG = new InflectedWordElement((WordElement)frontVG);
                }


                frontVG.setFeature(Feature.TENSE.ToString(), tenseValue);

                // if (Tense.FUTURE.Equals(tenseValue) && frontVG != null) {
                // frontVG.setFeature(Feature.TENSE, Tense.FUTURE);
                // }

                if (hasModal)
                {
                    frontVG.setFeature(Feature.NEGATED.ToString(), false);
                }
            }

            return(frontVG);
        }
Exemplo n.º 2
0
        /**
         * Realises the head noun of the noun phrase.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this noun phrase.
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param realisedElement
         *            the current realisation of the noun phrase.
         */

        private static void realiseHeadNoun(PhraseElement phrase,
                                            SyntaxProcessor parent, ListElement realisedElement)
        {
            INLGElement headElement = phrase.getHead();

            if (headElement != null)
            {
                headElement.setFeature(Feature.ELIDED.ToString(), phrase
                                       .getFeature(Feature.ELIDED.ToString()));
                headElement.setFeature(LexicalFeature.GENDER, phrase
                                       .getFeature(LexicalFeature.GENDER));
                headElement.setFeature(InternalFeature.ACRONYM.ToString(), phrase
                                       .getFeature(InternalFeature.ACRONYM.ToString()));
                headElement.setFeature(Feature.NUMBER.ToString(), phrase
                                       .getFeature(Feature.NUMBER.ToString()));
                headElement.setFeature(Feature.PERSON.ToString(), phrase
                                       .getFeature(Feature.PERSON.ToString()));
                headElement.setFeature(Feature.POSSESSIVE.ToString(), phrase
                                       .getFeature(Feature.POSSESSIVE.ToString()));
                headElement.setFeature(Feature.PASSIVE.ToString(), phrase
                                       .getFeature(Feature.PASSIVE.ToString()));
                var currentElement = parent.realise(headElement);
                currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                                          DiscourseFunction.SUBJECT);
                realisedElement.addComponent(currentElement);
            }
        }
Exemplo n.º 3
0
        /**
         * Pushes the front verb onto the stack of verb components.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this noun phrase.
         * @param vgComponents
         *            the stack of verb components in the verb group.
         * @param frontVG
         *            the first verb in the verb group.
         * @param formValue
         *            the <code>Form</code> of the phrase.
         * @param interrogative
         *            <code>true</code> if the phrase is interrogative.
         */

        private static void pushFrontVerb(PhraseElement phrase,
                                          Stack <INLGElement> vgComponents, INLGElement frontVG,
                                          object formValue, bool interrogative)
        {
            var interrogType = phrase.getFeature(Feature.INTERROGATIVE_TYPE.ToString());

            if (Form.GERUND.Equals(formValue))
            {
                frontVG.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE);
                vgComponents.push(frontVG);
            }
            else if (Form.PAST_PARTICIPLE.Equals(formValue))
            {
                frontVG.setFeature(Feature.FORM.ToString(), Form.PAST_PARTICIPLE);
                vgComponents.push(frontVG);
            }
            else if (Form.PRESENT_PARTICIPLE.Equals(formValue))
            {
                frontVG.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE);
                vgComponents.push(frontVG);
            }
            else if ((!(formValue == null || Form.NORMAL.Equals(formValue)) || interrogative) &&
                     !isCopular(phrase.getHead()) && vgComponents.isEmpty())
            {
                // AG: fix below: if interrogative, only set non-morph feature in
                // case it's not WHO_SUBJECT OR WHAT_SUBJECT
                if (!(InterrogativeType.WHO_SUBJECT.Equals(interrogType) || InterrogativeType.WHAT_SUBJECT
                      .Equals(interrogType)))
                {
                    frontVG.setFeature(InternalFeature.NON_MORPH.ToString(), true);
                }

                vgComponents.push(frontVG);
            }
            else
            {
                var numToUse = determineNumber(phrase.getParent(),
                                               phrase);
                frontVG.setFeature(Feature.TENSE.ToString(), phrase.getFeatureTense(Feature.TENSE.ToString()));
                frontVG.setFeature(Feature.PERSON.ToString(), phrase
                                   .getFeature(Feature.PERSON.ToString()));
                frontVG.setFeature(Feature.NUMBER.ToString(), numToUse);

                //don't push the front VG if it's a negated interrogative WH object question
                if (!(phrase.getFeatureAsBoolean(Feature.NEGATED.ToString()) && (InterrogativeType.WHO_OBJECT
                                                                                 .Equals(interrogType) ||
                                                                                 InterrogativeType.WHAT_OBJECT
                                                                                 .Equals(interrogType))))
                {
                    vgComponents.push(frontVG);
                }
            }
        }
Exemplo n.º 4
0
        /**
         * The main method for realising verb phrases.
         *
         * @param parent
         *            the <code>SyntaxProcessor</code> that called this method.
         * @param phrase
         *            the <code>PhraseElement</code> to be realised.
         * @return the realised <code>NLGElement</code>.
         */

        public static INLGElement realise(SyntaxProcessor parent, PhraseElement phrase)
        {
            ListElement realisedElement      = null;
            var         mainVerbRealisation  = new Stack <INLGElement>();
            var         auxiliaryRealisation = new Stack <INLGElement>();

            if (phrase != null)
            {
                var vgComponents = createVerbGroup(parent, phrase);
                splitVerbGroup(vgComponents, mainVerbRealisation,
                               auxiliaryRealisation);

                realisedElement = new ListElement();

                if (!phrase.hasFeature(InternalFeature.REALISE_AUXILIARY.ToString()) ||
                    phrase.getFeatureAsBoolean(
                        InternalFeature.REALISE_AUXILIARY.ToString()))
                {
                    realiseAuxiliaries(parent, realisedElement,
                                       auxiliaryRealisation);

                    PhraseHelper.realiseList(parent, realisedElement, phrase
                                             .getPreModifiers(), DiscourseFunction.PRE_MODIFIER);

                    realiseMainVerb(parent, phrase, mainVerbRealisation,
                                    realisedElement);
                }
                else if (isCopular(phrase.getHead()))
                {
                    realiseMainVerb(parent, phrase, mainVerbRealisation,
                                    realisedElement);
                    PhraseHelper.realiseList(parent, realisedElement, phrase
                                             .getPreModifiers(), DiscourseFunction.PRE_MODIFIER);
                }
                else
                {
                    PhraseHelper.realiseList(parent, realisedElement, phrase
                                             .getPreModifiers(), DiscourseFunction.PRE_MODIFIER);
                    realiseMainVerb(parent, phrase, mainVerbRealisation,
                                    realisedElement);
                }
                realiseComplements(parent, phrase, realisedElement);
                PhraseHelper.realiseList(parent, realisedElement, phrase
                                         .getPostModifiers(), DiscourseFunction.POST_MODIFIER);
            }

            return(realisedElement);
        }
Exemplo n.º 5
0
        /**
         * Determines the number agreement for the phrase ensuring that any number
         * agreement on the parent element is inherited by the phrase.
         *
         * @param parent
         *            the parent element of the phrase.
         * @param phrase
         *            the <code>PhraseElement</code> representing this noun phrase.
         * @return the <code>NumberAgreement</code> to be used for the phrase.
         */

        private static NumberAgreement determineNumber(INLGElement parent,
                                                       PhraseElement phrase)
        {
            var             numberValue = phrase.getFeature(Feature.NUMBER.ToString());
            NumberAgreement number;

            if (numberValue != null && numberValue is NumberAgreement)
            {
                number = (NumberAgreement)numberValue;
            }
            else
            {
                number = NumberAgreement.SINGULAR;
            }

            // Ehud Reiter = modified below to force number from VP for WHAT_SUBJECT
            // and WHO_SUBJECT interrogatuves
            if (parent is PhraseElement)
            {
                if (parent.isA(PhraseCategoryEnum.CLAUSE) &&
                    (PhraseHelper.isExpletiveSubject((PhraseElement)parent) ||
                     InterrogativeType.WHO_SUBJECT.Equals(parent
                                                          .getFeature(Feature.INTERROGATIVE_TYPE.ToString())) || InterrogativeType.WHAT_SUBJECT
                     .Equals(parent
                             .getFeature(Feature.INTERROGATIVE_TYPE.ToString()))) &&
                    isCopular(phrase.getHead()))
                {
                    if (hasPluralComplement(phrase
                                            .getFeatureAsElementList(InternalFeature.COMPLEMENTS.ToString())))
                    {
                        number = NumberAgreement.PLURAL;
                    }
                    else
                    {
                        number = NumberAgreement.SINGULAR;
                    }
                }
            }
            return(number);
        }
Exemplo n.º 6
0
        /**
         * Realises the head element of the phrase.
         *
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param phrase
         *            the <code>PhraseElement</code> representing this noun phrase.
         * @param realisedElement
         *            the current realisation of the noun phrase.
         */

        private static void realiseHead(SyntaxProcessor parent,
                                        PhraseElement phrase, ListElement realisedElement)
        {
            INLGElement head = phrase.getHead();

            if (head != null)
            {
                if (phrase.hasFeature(Feature.IS_COMPARATIVE.ToString()))
                {
                    head.setFeature(Feature.IS_COMPARATIVE.ToString(), phrase
                                    .getFeature(Feature.IS_COMPARATIVE.ToString()));
                }
                else if (phrase.hasFeature(Feature.IS_SUPERLATIVE.ToString()))
                {
                    head.setFeature(Feature.IS_SUPERLATIVE.ToString(), phrase
                                    .getFeature(Feature.IS_SUPERLATIVE.ToString()));
                }
                head = parent.realise(head);
                head.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                                DiscourseFunction.HEAD.ToString());
                realisedElement.addComponent(head);
            }
        }
Exemplo n.º 7
0
        /**
         * The main method for controlling the syntax realisation of clauses.
         *
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that called this
         *            method.
         * @param phrase
         *            the <code>PhraseElement</code> representation of the clause.
         * @return the <code>NLGElement</code> representing the realised clause.
         */

        public static INLGElement realise(SyntaxProcessor parent, PhraseElement phrase)
        {
            ListElement realisedElement = null;
            var         phraseFactory   = phrase.getFactory();
            INLGElement splitVerb       = null;
            var         interrogObj     = false;

            if (phrase != null)
            {
                realisedElement = new ListElement();
                var verbElement = phrase.getFeatureAsElement(InternalFeature.VERB_PHRASE.ToString());

                if (verbElement == null)
                {
                    verbElement = phrase.getHead();
                }

                checkSubjectNumberPerson(phrase, verbElement);
                checkDiscourseFunction(phrase);
                copyFrontModifiers(phrase, verbElement);
                addComplementiser(phrase, parent, realisedElement);
                addCuePhrase(phrase, parent, realisedElement);

                if (phrase.hasFeature(Feature.INTERROGATIVE_TYPE.ToString()))
                {
                    var inter = phrase.getFeature(Feature.INTERROGATIVE_TYPE.ToString());
                    interrogObj = (InterrogativeType.WHAT_OBJECT.Equals(inter) ||
                                   InterrogativeType.WHO_OBJECT.Equals(inter) ||
                                   InterrogativeType.HOW_PREDICATE.Equals(inter) ||
                                   InterrogativeType.HOW.Equals(inter) ||
                                   InterrogativeType.WHY.Equals(inter) || InterrogativeType.WHERE.Equals(inter));
                    splitVerb = realiseInterrogative(phrase, parent, realisedElement, phraseFactory, verbElement);
                }
                else
                {
                    PhraseHelper.realiseList(parent,
                                             realisedElement,
                                             phrase.getFeatureAsElementList(InternalFeature.FRONT_MODIFIERS.ToString()),
                                             DiscourseFunction.FRONT_MODIFIER);
                }

                addSubjectsToFront(phrase, parent, realisedElement, splitVerb);

                var passiveSplitVerb = addPassiveComplementsNumberPerson(phrase,
                                                                         parent,
                                                                         realisedElement,
                                                                         verbElement);

                if (passiveSplitVerb != null)
                {
                    splitVerb = passiveSplitVerb;
                }

                // realise verb needs to know if clause is object interrogative
                realiseVerb(phrase, parent, realisedElement, splitVerb, verbElement, interrogObj);
                addPassiveSubjects(phrase, parent, realisedElement, phraseFactory);
                addInterrogativeFrontModifiers(phrase, parent, realisedElement);
                addEndingTo(phrase, parent, realisedElement, phraseFactory);
            }
            return(realisedElement);
        }
Exemplo n.º 8
0
        /**
         * Creates a stack of verbs for the verb phrase. Additional auxiliary verbs
         * are added as required based on the features of the verb phrase.
         *
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param phrase
         *            the <code>PhraseElement</code> representing this noun phrase.
         * @return the verb group as a <code>Stack</code> of <code>NLGElement</code>
         *         s.
         */

        public static Stack <INLGElement> createVerbGroup(
            SyntaxProcessor parent, PhraseElement phrase)
        {
            string actualModal   = null;
            var    formValue     = phrase.getFeature(Feature.FORM.ToString());
            Tense  tenseValue    = phrase.getFeatureTense(Feature.TENSE.ToString());
            var    modal         = phrase.getFeatureAsString(Feature.MODAL.ToString());
            var    modalPast     = false;
            var    vgComponents  = new Stack <INLGElement>();
            var    interrogative = phrase.hasFeature(Feature.INTERROGATIVE_TYPE.ToString());

            if (Form.GERUND.Equals(formValue) || Form.INFINITIVE.Equals(formValue))
            {
                tenseValue = Tense.PRESENT;
            }

            if (Form.INFINITIVE.Equals(formValue))
            {
                actualModal = "to";
            }
            else if (formValue == null || Form.NORMAL.Equals(formValue))
            {
                if (Tense.FUTURE.Equals(tenseValue) &&
                    modal == null &&
                    ((!(phrase.getHead() is CoordinatedPhraseElement)) || (phrase
                                                                           .getHead() is CoordinatedPhraseElement &&
                                                                           interrogative)))
                {
                    actualModal = "will";
                }
                else if (modal != null)
                {
                    actualModal = modal;

                    if (Tense.PAST.Equals(tenseValue))
                    {
                        modalPast = true;
                    }
                }
            }

            pushParticles(phrase, parent, vgComponents);
            var frontVG = grabHeadVerb(phrase, tenseValue, modal != null);

            checkImperativeInfinitive(formValue, frontVG);

            if (phrase.getFeatureAsBoolean(Feature.PASSIVE.ToString()))
            {
                frontVG = addBe(frontVG, vgComponents, Form.PAST_PARTICIPLE);
            }

            if (phrase.getFeatureAsBoolean(Feature.PROGRESSIVE.ToString()))
            {
                frontVG = addBe(frontVG, vgComponents, Form.PRESENT_PARTICIPLE);
            }

            if (phrase.getFeatureAsBoolean(Feature.PERFECT.ToString()) ||
                modalPast)
            {
                frontVG = addHave(frontVG, vgComponents, modal, tenseValue);
            }

            frontVG = pushIfModal(actualModal != null, phrase, frontVG,
                                  vgComponents);
            frontVG = createNot(phrase, vgComponents, frontVG, modal != null);

            if (frontVG != null)
            {
                pushFrontVerb(phrase, vgComponents, frontVG, formValue,
                              interrogative);
            }

            pushModal(actualModal, phrase, vgComponents);
            return(vgComponents);
        }