コード例 #1
0
        /**
         * Checks the discourse function of the clause and alters the form of the
         * clause as necessary. The following algorithm is used: <br>
         *
         * <pre>
         * If the clause represents a direct or indirect object then
         *      If form is currently Imperative then
         *           Set form to Infinitive
         *           Suppress the complementiser
         *      If form is currently Gerund and there are no subjects
         *           Suppress the complementiser
         * If the clause represents a subject then
         *      Set the form to be Gerund
         *      Suppress the complementiser
         * </pre>
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         */

        private static void checkDiscourseFunction(PhraseElement phrase)
        {
            List <INLGElement> subjects = phrase.getFeatureAsElementList(InternalFeature.SUBJECTS.ToString());
            var clauseForm     = phrase.getFeature(Feature.FORM.ToString());
            var discourseValue = phrase.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString());

            if (DiscourseFunction.OBJECT.Equals(discourseValue) ||
                DiscourseFunction.INDIRECT_OBJECT.Equals(discourseValue))
            {
                if (Form.IMPERATIVE.Equals(clauseForm))
                {
                    phrase.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true);
                    phrase.setFeature(Feature.FORM.ToString(), Form.INFINITIVE.ToString());
                }
                else if (Form.GERUND.Equals(clauseForm) && subjects.Count == 0)
                {
                    phrase.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true);
                }
            }
            else if (DiscourseFunction.SUBJECT.Equals(discourseValue))
            {
                phrase.setFeature(Feature.FORM.ToString(), Form.GERUND);
                phrase.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true);
            }
        }
コード例 #2
0
        /**
         * Adds a <em>do</em> verb to the realisation of this clause.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param realisedElement
         *            the current realisation of the clause.
         * @param phraseFactory
         *            the phrase factory to be used.
         */

        private static void addDoAuxiliary(PhraseElement phrase,
                                           SyntaxProcessor parent,
                                           NLGFactory phraseFactory,
                                           ListElement realisedElement)
        {
            PhraseElement doPhrase = phraseFactory.createVerbPhrase("do");

            doPhrase.setFeature(Feature.TENSE.ToString(), phrase.getFeatureTense(Feature.TENSE.ToString()));
            doPhrase.setFeature(Feature.PERSON.ToString(), phrase.getFeature(Feature.PERSON.ToString()));
            doPhrase.setFeature(Feature.NUMBER.ToString(), phrase.getFeature(Feature.NUMBER.ToString()));
            realisedElement.addComponent(parent.realise(doPhrase));
        }
コード例 #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);
                }
            }
        }
コード例 #4
0
        /**
         * Adds the subjects to the beginning of the clause unless the clause is
         * infinitive, imperative or passive, or the subjects split the verb.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param realisedElement
         *            the current realisation of the clause.
         * @param splitVerb
         *            an <code>NLGElement</code> representing the subjects that
         *            should split the verb
         */

        private static void addSubjectsToFront(PhraseElement phrase,
                                               SyntaxProcessor parent,
                                               ListElement realisedElement,
                                               INLGElement splitVerb)
        {
            if (!Form.INFINITIVE.Equals(phrase.getFeature(Feature.FORM.ToString())) &&
                !Form.IMPERATIVE.Equals(phrase.getFeature(Feature.FORM.ToString())) &&
                !phrase.getFeatureAsBoolean(Feature.PASSIVE.ToString()) && splitVerb == null)
            {
                realisedElement.addComponents(realiseSubjects(phrase, parent).getChildren());
            }
        }
コード例 #5
0
        /**
         * Realises the specifier 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 realiseSpecifier(PhraseElement phrase,
                                             SyntaxProcessor parent, ListElement realisedElement)
        {
            INLGElement specifierElement = phrase
                                           .getFeatureAsElement(InternalFeature.SPECIFIER.ToString());

            if (specifierElement != null &&
                !phrase.getFeatureAsBoolean(InternalFeature.RAISED.ToString()) &&
                !phrase.getFeatureAsBoolean(Feature.ELIDED.ToString()))
            {
                if (!specifierElement.isA(LexicalCategoryEnum.PRONOUN) &&
                    specifierElement.getCategory().enumType != (int)PhraseCategoryEnum.NOUN_PHRASE)
                {
                    specifierElement.setFeature(Feature.NUMBER.ToString(), phrase
                                                .getFeature(Feature.NUMBER.ToString()));
                }

                var currentElement = parent.realise(specifierElement);

                if (currentElement != null)
                {
                    currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                                              DiscourseFunction.SPECIFIER);
                    realisedElement.addComponent(currentElement);
                }
            }
        }
コード例 #6
0
        /**
         * Realises the complements of this 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 realiseComplements(SyntaxProcessor parent,
                                               PhraseElement phrase, ListElement realisedElement)
        {
            var indirects = new ListElement();
            var directs   = new ListElement();
            var unknowns  = new ListElement();

            foreach (INLGElement complement in phrase.getFeatureAsElementList(InternalFeature.COMPLEMENTS.ToString()))
            {
                var discourseValue = complement
                                     .getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString());
                var currentElement = parent.realise(complement);
                if (currentElement != null)
                {
                    currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                                              DiscourseFunction.COMPLEMENT);

                    if (DiscourseFunction.INDIRECT_OBJECT.Equals(discourseValue))
                    {
                        indirects.addComponent(currentElement);
                    }
                    else if (DiscourseFunction.OBJECT.Equals(discourseValue))
                    {
                        directs.addComponent(currentElement);
                    }
                    else
                    {
                        unknowns.addComponent(currentElement);
                    }
                }
            }
            if (!InterrogativeTypeExtensions.isIndirectObject(phrase
                                                              .getFeature(Feature.INTERROGATIVE_TYPE.ToString())))
            {
                realisedElement.addComponents(indirects.getChildren());
            }
            if (!phrase.getFeatureAsBoolean(Feature.PASSIVE.ToString()))
            {
                if (!InterrogativeTypeExtensions.isAndObject(phrase
                                                             .getFeature(Feature.INTERROGATIVE_TYPE.ToString())))
                {
                    realisedElement.addComponents(directs.getChildren());
                }
                realisedElement.addComponents(unknowns.getChildren());
            }
        }
コード例 #7
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);
            }
        }
コード例 #8
0
        /**
         * Adds <em>to</em> to the end of interrogatives concerning indirect
         * objects. For example, <em>who did John give the flower <b>to</b></em>.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param realisedElement
         *            the current realisation of the clause.
         * @param phraseFactory
         *            the phrase factory to be used.
         */

        private static void addEndingTo(PhraseElement phrase,
                                        SyntaxProcessor parent,
                                        ListElement realisedElement,
                                        NLGFactory phraseFactory)
        {
            if (InterrogativeType.WHO_INDIRECT_OBJECT.Equals(phrase.getFeature(Feature.INTERROGATIVE_TYPE.ToString())))
            {
                var word = phraseFactory.createWord("to", new LexicalCategory_PREPOSITION());
                realisedElement.addComponent(parent.realise(word));
            }
        }
コード例 #9
0
        /**
         * Copies the front modifiers of the clause to the list of post-modifiers of
         * the verb only if the phrase has infinitive form.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         * @param verbElement
         *            the <code>NLGElement</code> representing the verb phrase for
         *            this clause.
         */

        private static void copyFrontModifiers(PhraseElement phrase, INLGElement verbElement)
        {
            var frontModifiers = phrase.getFeatureAsElementList(InternalFeature.FRONT_MODIFIERS.ToString());
            var clauseForm     = phrase.getFeature(Feature.FORM.ToString());

            // bug fix by Chris Howell (Agfa) -- do not overwrite existing post-mods
            // in the VP
            if (verbElement != null)
            {
                List <INLGElement> phrasePostModifiers = phrase.getFeatureAsElementList(InternalFeature.POSTMODIFIERS.ToString());

                if (verbElement is PhraseElement)
                {
                    List <INLGElement> verbPostModifiers =
                        verbElement.getFeatureAsElementList(InternalFeature.POSTMODIFIERS.ToString());

                    foreach (var eachModifier in phrasePostModifiers)
                    {
                        // need to check that VP doesn't already contain the
                        // post-modifier
                        // this only happens if the phrase has already been realised
                        // and later modified, with realiser called again. In that
                        // case, postmods will be copied over twice
                        if (!verbPostModifiers.Contains(eachModifier))
                        {
                            ((PhraseElement)verbElement).addPostModifier(eachModifier);
                        }
                    }
                }
            }

            // if (verbElement != null) {
            // verbElement.setFeature(InternalFeature.POSTMODIFIERS, phrase
            // .getFeature(InternalFeature.POSTMODIFIERS));
            // }

            if (Form.INFINITIVE.Equals(clauseForm))
            {
                phrase.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true);

                foreach (var eachModifier in frontModifiers)
                {
                    if (verbElement is PhraseElement)
                    {
                        ((PhraseElement)verbElement).addPostModifier(eachModifier);
                    }
                }
                phrase.removeFeature(InternalFeature.FRONT_MODIFIERS.ToString());
                if (verbElement != null)
                {
                    verbElement.setFeature(InternalFeature.NON_MORPH.ToString(), true);
                }
            }
        }
コード例 #10
0
        /**
         * Adds <em>not</em> to the stack if the phrase is negated.
         *
         * @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 hasModal
         *            the phrase has a modal
         * @return the new element for the front of the group.
         */

        private static INLGElement createNot(PhraseElement phrase,
                                             Stack <INLGElement> vgComponents, INLGElement frontVG, bool hasModal)
        {
            var newFront = frontVG;

            if (phrase.getFeatureAsBoolean(Feature.NEGATED.ToString()))
            {
                var factory = phrase.getFactory();

                // before adding "do", check if this is an object WH
                // interrogative
                // in which case, don't add anything as it's already done by
                // ClauseHelper
                var interrType = phrase.getFeature(Feature.INTERROGATIVE_TYPE.ToString());
                var addDo      = !(InterrogativeType.WHAT_OBJECT.Equals(interrType) || InterrogativeType.WHO_OBJECT
                                   .Equals(interrType));

                if (!vgComponents.empty() || frontVG != null && isCopular(frontVG))
                {
                    vgComponents.push(new InflectedWordElement(
                                          "not", new LexicalCategory_ADVERB()));
                }
                else
                {
                    if (frontVG != null && !hasModal)
                    {
                        frontVG.setFeature(Feature.NEGATED.ToString(), true);
                        vgComponents.push(frontVG);
                    }

                    vgComponents.push(new InflectedWordElement(
                                          "not", new LexicalCategory_ADVERB()));

                    if (addDo)
                    {
                        if (factory != null)
                        {
                            newFront = factory.createInflectedWord("do",
                                                                   new LexicalCategory_VERB());
                        }
                        else
                        {
                            newFront = new InflectedWordElement(
                                "do", new LexicalCategory_VERB());
                        }
                    }
                }
            }

            return(newFront);
        }
コード例 #11
0
        /**
         * Pushes the particles of the main verb onto the verb group stack.
         *
         * @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 vgComponents
         *            the stack of verb components in the verb group.
         */

        private static void pushParticles(PhraseElement phrase,
                                          SyntaxProcessor parent, Stack <INLGElement> vgComponents)
        {
            var particle = phrase.getFeature(Feature.PARTICLE.ToString());

            if (particle is string)
            {
                vgComponents.push(new StringElement((string)particle));
            }
            else if (particle is INLGElement)
            {
                vgComponents.push(parent.realise((INLGElement)particle));
            }
        }
コード例 #12
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);
            }
        }
コード例 #13
0
        /**
         * Checks to see if this clause is a subordinate clause. If it is then the
         * complementiser is added as a component to the realised element
         * <b>unless</b> the complementiser has been suppressed.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param realisedElement
         *            the current realisation of the clause.
         */

        private static void addComplementiser(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement)
        {
            INLGElement currentElement;

            if (ClauseStatus.SUBORDINATE.Equals(phrase.getFeature(InternalFeature.CLAUSE_STATUS.ToString())) &&
                !phrase.getFeatureAsBoolean(Feature.SUPRESSED_COMPLEMENTISER.ToString()))
            {
                currentElement = parent.realise(phrase.getFeatureAsElement(Feature.COMPLEMENTISER.ToString()));

                if (currentElement != null)
                {
                    realisedElement.addComponent(currentElement);
                }
            }
        }
コード例 #14
0
        /**
         * Realises the main group of verbs in 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 mainVerbRealisation
         *            the stack of the main verbs in the phrase.
         * @param realisedElement
         *            the current realisation of the noun phrase.
         */

        private static void realiseMainVerb(SyntaxProcessor parent,
                                            PhraseElement phrase, Stack <INLGElement> mainVerbRealisation,
                                            ListElement realisedElement)
        {
            while (!mainVerbRealisation.isEmpty())
            {
                var main = mainVerbRealisation.pop();
                main.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), phrase
                                .getFeature(Feature.INTERROGATIVE_TYPE.ToString()));
                var currentElement = parent.realise(main);

                if (currentElement != null)
                {
                    realisedElement.addComponent(currentElement);
                }
            }
        }
コード例 #15
0
        /**
         * Realises the subjects for the clause.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param realisedElement
         *            the current realisation of the clause.
         */

        private static ListElement realiseSubjects(PhraseElement phrase, SyntaxProcessor parent)
        {
            INLGElement currentElement  = null;
            var         realisedElement = new ListElement();

            foreach (INLGElement subject in phrase.getFeatureAsElementList(InternalFeature.SUBJECTS.ToString()))
            {
                subject.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.SUBJECT);
                if (Form.GERUND.Equals(phrase.getFeature(Feature.FORM.ToString())) &&
                    !phrase.getFeatureAsBoolean(Feature.SUPPRESS_GENITIVE_IN_GERUND.ToString()))
                {
                    subject.setFeature(Feature.POSSESSIVE.ToString(), true);
                }
                currentElement = parent.realise(subject);
                if (currentElement != null)
                {
                    realisedElement.addComponent(currentElement);
                }
            }
            return(realisedElement);
        }
コード例 #16
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);
        }
コード例 #17
0
        /**
         * Realises the complements of passive clauses; also sets number, person for
         * passive
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param realisedElement
         *            the current realisation of the clause.
         * @param verbElement
         *            the <code>NLGElement</code> representing the verb phrase for
         *            this clause.
         */

        private static INLGElement addPassiveComplementsNumberPerson(PhraseElement phrase,
                                                                     SyntaxProcessor parent,
                                                                     ListElement realisedElement,
                                                                     INLGElement verbElement)
        {
            object      passiveNumber  = null;
            object      passivePerson  = null;
            INLGElement currentElement = null;
            INLGElement splitVerb      = null;
            var         verbPhrase     = phrase.getFeatureAsElement(InternalFeature.VERB_PHRASE.ToString());

            // count complements to set plural feature if more than one
            var numComps  = 0;
            var coordSubj = false;

            if (phrase.getFeatureAsBoolean(Feature.PASSIVE.ToString()) && verbPhrase != null &&
                !InterrogativeType.WHAT_OBJECT.Equals(phrase.getFeature(Feature.INTERROGATIVE_TYPE.ToString())))
            {
                // complements of a clause are stored in the VPPhraseSpec
                foreach (var subject in verbPhrase.getFeatureAsElementList(InternalFeature.COMPLEMENTS.ToString()))
                {
                    // AG: complement needn't be an NP
                    // subject.isA(PhraseCategory.NOUN_PHRASE) &&
                    if (DiscourseFunction.OBJECT.Equals(subject.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString())))
                    {
                        subject.setFeature(Feature.PASSIVE.ToString(), true);
                        numComps++;
                        currentElement = parent.realise(subject);

                        if (currentElement != null)
                        {
                            currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.OBJECT);

                            if (phrase.hasFeature(Feature.INTERROGATIVE_TYPE.ToString()))
                            {
                                splitVerb = currentElement;
                            }
                            else
                            {
                                realisedElement.addComponent(currentElement);
                            }
                        }

                        // flag if passive subject is coordinated with an "and"
                        if (!coordSubj && subject is CoordinatedPhraseElement)
                        {
                            var conj = ((CoordinatedPhraseElement)subject).getConjunction();
                            coordSubj = (conj != null && conj.Equals("and"));
                        }

                        if (passiveNumber == null)
                        {
                            passiveNumber = subject.getFeature(Feature.NUMBER.ToString());
                        }
                        else
                        {
                            passiveNumber = NumberAgreement.PLURAL;
                        }

                        if (Person.FIRST.Equals(subject.getFeature(Feature.PERSON.ToString())))
                        {
                            passivePerson = Person.FIRST;
                        }
                        else if (Person.SECOND.Equals(subject.getFeature(Feature.PERSON.ToString())) &&
                                 !Person.FIRST.Equals(passivePerson))
                        {
                            passivePerson = Person.SECOND;
                        }
                        else if (passivePerson == null)
                        {
                            passivePerson = Person.THIRD;
                        }

                        if (Form.GERUND.Equals(phrase.getFeature(Feature.FORM.ToString())) &&
                            !phrase.getFeatureAsBoolean(Feature.SUPPRESS_GENITIVE_IN_GERUND.ToString()))
                        {
                            subject.setFeature(Feature.POSSESSIVE.ToString(), true);
                        }
                    }
                }
            }

            if (verbElement != null)
            {
                if (passivePerson != null)
                {
                    verbElement.setFeature(Feature.PERSON.ToString(), passivePerson);
                    // below commented out. for non-passive, number and person set
                    // by checkSubjectNumberPerson
                    // } else {
                    // verbElement.setFeature(Feature.PERSON, phrase
                    // .getFeature(Feature.PERSON));
                }

                if (numComps > 1 || coordSubj)
                {
                    verbElement.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
                }
                else if (passiveNumber != null)
                {
                    verbElement.setFeature(Feature.NUMBER.ToString(), passiveNumber);
                }
            }
            return(splitVerb);
        }
コード例 #18
0
        /**
         * Checks the subjects of the phrase to determine if there is more than one
         * subject. This ensures that the verb phrase is correctly set. Also set
         * person correctly
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         * @param verbElement
         *            the <code>NLGElement</code> representing the verb phrase for
         *            this clause.
         */

        private static void checkSubjectNumberPerson(PhraseElement phrase, INLGElement verbElement)
        {
            INLGElement        currentElement = null;
            List <INLGElement> subjects       = phrase.getFeatureAsElementList(InternalFeature.SUBJECTS.ToString());
            var pluralSubjects = false;
            var person         = Person.FIRST;
            var personSet      = false;

            if (subjects != null)
            {
                switch (subjects.size())
                {
                case 0:
                    break;

                case 1:
                    currentElement = subjects.get(0);
                    // coordinated NP with "and" are plural (not coordinated NP with
                    // "or")
                    if (currentElement is CoordinatedPhraseElement &&
                        ((CoordinatedPhraseElement)currentElement).checkIfPlural())
                    {
                        pluralSubjects = true;
                    }
                    else if ((currentElement.getFeature(Feature.NUMBER.ToString())?.ToString() == NumberAgreement.PLURAL.ToString()) &&
                             !(currentElement is SPhraseSpec))        // ER mod-
                    // clauses
                    // are
                    // singular
                    // as
                    // NPs,
                    // even
                    // if
                    // they
                    // are
                    // plural
                    // internally
                    {
                        pluralSubjects = true;
                    }
                    else if (currentElement.isA(PhraseCategoryEnum.NOUN_PHRASE))
                    {
                        INLGElement currentHead = currentElement.getFeatureAsElement(InternalFeature.HEAD.ToString());

                        var p = currentElement.getFeature(Feature.PERSON.ToString());
                        if (p != null)
                        {
                            personSet = true;
                            person    = p.ToPerson();
                        }

                        if (currentHead == null)
                        {
                            // subject is null and therefore is not gonna be plural
                            pluralSubjects = false;
                        }
                        else if (currentHead.getFeature(Feature.NUMBER.ToString()) == NumberAgreement.PLURAL.ToString())
                        {
                            pluralSubjects = true;
                        }
                        else if (currentHead is ListElement)
                        {
                            pluralSubjects = true;

                            /*
                             * } else if (currentElement is
                             * CoordinatedPhraseElement &&
                             * "and".Equals(currentElement.getFeatureAsString(
                             *  Feature.CONJUNCTION))) { pluralSubjects
                             * = true;
                             */
                        }
                    }
                    break;

                default:
                    pluralSubjects = true;
                    break;
                }
            }
            if (verbElement != null)
            {
                verbElement.setFeature(Feature.NUMBER.ToString(), pluralSubjects
                    ? NumberAgreement.PLURAL
                    : phrase.getFeature(Feature.NUMBER.ToString()));
                if (personSet)
                {
                    verbElement.setFeature(Feature.PERSON.ToString(), person);
                }
            }
        }
コード例 #19
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);
        }
コード例 #20
0
        /**
         * This is the main controlling method for handling interrogative clauses.
         * The actual steps taken are dependent on the type of question being asked.
         * The method also determines if there is a subject that will split the verb
         * group of the clause. For example, the clause
         * <em>the man <b>should give</b> the woman the flower</em> has the verb
         * group indicated in <b>bold</b>. The phrase is rearranged as yes/no
         * question as
         * <em><b>should</b> the man <b>give</b> the woman the flower</em> with the
         * subject <em>the man</em> splitting the verb group.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param realisedElement
         *            the current realisation of the clause.
         * @param phraseFactory
         *            the phrase factory to be used.
         * @param verbElement
         *            the <code>NLGElement</code> representing the verb phrase for
         *            this clause.
         * @return an <code>NLGElement</code> representing a subject that should
         *         split the verb
         */

        private static INLGElement realiseInterrogative(PhraseElement phrase,
                                                        SyntaxProcessor parent,
                                                        ListElement realisedElement,
                                                        NLGFactory phraseFactory,
                                                        INLGElement verbElement)
        {
            INLGElement splitVerb = null;

            if (phrase.getParent() != null)
            {
                phrase.getParent().setFeature(InternalFeature.INTERROGATIVE.ToString(), true);
            }

            var type = phrase.getFeature(Feature.INTERROGATIVE_TYPE.ToString());

            if (type is InterrogativeType)
            {
                switch ((InterrogativeType)type)
                {
                case InterrogativeType.YES_NO:
                    splitVerb = realiseYesNo(phrase, parent, verbElement, phraseFactory, realisedElement);
                    break;

                case InterrogativeType.WHO_SUBJECT:
                case InterrogativeType.WHAT_SUBJECT:
                    realiseInterrogativeKeyWord(((InterrogativeType)type).getString(),
                                                new LexicalCategory_PRONOUN(),
                                                parent,
                                                realisedElement,
                                                phraseFactory);
                    phrase.removeFeature(InternalFeature.SUBJECTS.ToString());
                    break;

                case InterrogativeType.HOW_MANY:
                    realiseInterrogativeKeyWord("how", new LexicalCategory_PRONOUN(), parent, realisedElement,

                                                phraseFactory);
                    realiseInterrogativeKeyWord("many", new LexicalCategory_ADVERB(), parent, realisedElement,

                                                phraseFactory);
                    break;

                case InterrogativeType.HOW:
                case InterrogativeType.WHY:
                case InterrogativeType.WHERE:
                case InterrogativeType.WHO_OBJECT:
                case InterrogativeType.WHO_INDIRECT_OBJECT:
                case InterrogativeType.WHAT_OBJECT:
                    splitVerb = realiseObjectWHInterrogative(((InterrogativeType)type).getString(),
                                                             phrase,
                                                             parent,
                                                             realisedElement,
                                                             phraseFactory);
                    break;

                case InterrogativeType.HOW_PREDICATE:
                    splitVerb = realiseObjectWHInterrogative("how", phrase, parent, realisedElement, phraseFactory);
                    break;

                default:
                    break;
                }
            }

            return(splitVerb);
        }
コード例 #21
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);
        }
コード例 #22
0
        /**
         * Creates the appropriate pronoun if the subject of the noun phrase is
         * pronominal.
         *
         * @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 <code>NLGElement</code> representing the pronominal.
         */

        private static INLGElement createPronoun(SyntaxProcessor parent,
                                                 PhraseElement phrase)
        {
            var pronoun       = "it";
            var phraseFactory = phrase.getFactory();
            var personValue   = phrase.getFeature(Feature.PERSON.ToString());

            if (Person.FIRST.Equals(personValue))
            {
                pronoun = "I";
            }
            else if (Person.SECOND.Equals(personValue))
            {
                pronoun = "you";
            }
            else
            {
                var genderValue = phrase.getFeature(LexicalFeature.GENDER);
                if (Gender.FEMININE.Equals(genderValue))
                {
                    pronoun = "she";
                }
                else if (Gender.MASCULINE.Equals(genderValue))
                {
                    pronoun = "he";
                }
            }
            // AG: createWord now returns WordElement; so we embed it in an
            // inflected word element here
            INLGElement element;
            var         proElement = phraseFactory.createWord(pronoun,
                                                              new LexicalCategory_PRONOUN());

            if (proElement is WordElement)
            {
                element = new InflectedWordElement((WordElement)proElement);
                element.setFeature(LexicalFeature.GENDER, ((WordElement)proElement).getFeature(LexicalFeature.GENDER));
                // Ehud - also copy over person
                element.setFeature(Feature.PERSON.ToString(), ((WordElement)proElement).getFeature(Feature.PERSON.ToString()));
            }
            else
            {
                element = proElement;
            }

            element.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                               DiscourseFunction.SPECIFIER);
            element.setFeature(Feature.POSSESSIVE.ToString(), phrase
                               .getFeature(Feature.POSSESSIVE.ToString()));
            element
            .setFeature(Feature.NUMBER.ToString(), phrase.getFeature(Feature.NUMBER.ToString()));


            if (phrase.hasFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()))
            {
                element.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), phrase
                                   .getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()));
            }

            return(element);
        }