Exemplo n.º 1
0
        /**
         * Realises the subjects of a passive 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 addPassiveSubjects(PhraseElement phrase,
                                               SyntaxProcessor parent,
                                               ListElement realisedElement,
                                               NLGFactory phraseFactory)
        {
            INLGElement currentElement = null;

            if (phrase.getFeatureAsBoolean(Feature.PASSIVE.ToString()))
            {
                var allSubjects = phrase.getFeatureAsElementList(InternalFeature.SUBJECTS.ToString());

                if (allSubjects.size() > 0 || phrase.hasFeature(Feature.INTERROGATIVE_TYPE.ToString()))
                {
                    realisedElement.addComponent(parent.realise(phraseFactory.createPrepositionPhrase("by")));
                }

                foreach (var subject in allSubjects)
                {
                    subject.setFeature(Feature.PASSIVE.ToString(), true);
                    if (subject.isA(PhraseCategoryEnum.NOUN_PHRASE) || subject is CoordinatedPhraseElement)
                    {
                        currentElement = parent.realise(subject);
                        if (currentElement != null)
                        {
                            currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.SUBJECT);
                            realisedElement.addComponent(currentElement);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /**
         * Realises the complements of the phrase adding <em>and</em> where
         * appropriate.
         *
         * @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         firstProcessed = false;
            INLGElement currentElement = null;

            foreach (INLGElement complement in phrase.getFeatureAsElementList(InternalFeature.COMPLEMENTS.ToString()))
            {
                currentElement = parent.realise(complement);
                if (currentElement != null)
                {
                    currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                                              DiscourseFunction.COMPLEMENT);
                    if (firstProcessed)
                    {
                        realisedElement.addComponent(new InflectedWordElement(
                                                         "and", new LexicalCategory_CONJUNCTION()));
                    }
                    else
                    {
                        firstProcessed = true;
                    }
                    realisedElement.addComponent(currentElement);
                }
            }
        }
Exemplo n.º 3
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.º 4
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);
                }
            }
        }
Exemplo n.º 5
0
        /**
         * The main method for realising noun 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;

            if (phrase != null &&
                !phrase.getFeatureAsBoolean(Feature.ELIDED.ToString()))
            {
                realisedElement = new ListElement();

                if (phrase.getFeatureAsBoolean(Feature.PRONOMINAL.ToString()))
                {
                    realisedElement.addComponent(createPronoun(parent, phrase));
                }
                else
                {
                    realiseSpecifier(phrase, parent, realisedElement);
                    realisePreModifiers(phrase, parent, realisedElement);
                    realiseHeadNoun(phrase, parent, realisedElement);
                    PhraseHelper.realiseList(parent, realisedElement, phrase
                                             .getFeatureAsElementList(InternalFeature.COMPLEMENTS.ToString()),
                                             DiscourseFunction.COMPLEMENT);

                    PhraseHelper.realiseList(parent, realisedElement, phrase
                                             .getPostModifiers(), DiscourseFunction.POST_MODIFIER);
                }
            }

            return(realisedElement);
        }
Exemplo n.º 6
0
        /**
         * Realises the verb part of 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.
         * @param splitVerb
         *            an <code>NLGElement</code> representing the subjects that
         *            should split the verb
         * @param verbElement
         *            the <code>NLGElement</code> representing the verb phrase for
         *            this clause.
         * @param whObj
         *            whether the VP is part of an object WH-interrogative
         */

        private static void realiseVerb(PhraseElement phrase,
                                        SyntaxProcessor parent,
                                        ListElement realisedElement,
                                        INLGElement splitVerb,
                                        INLGElement verbElement,
                                        bool whObj)
        {
            setVerbFeatures(phrase, verbElement);

            var currentElement = parent.realise(verbElement);

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

                    realisedElement.addComponent(currentElement);
                }
                else
                {
                    if (currentElement is ListElement)
                    {
                        var children = currentElement.getChildren();
                        currentElement = children[0];
                        currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.VERB_PHRASE);
                        realisedElement.addComponent(currentElement);
                        realisedElement.addComponent(splitVerb);

                        for (var eachChild = 1; eachChild < children.Count; eachChild++)
                        {
                            currentElement = children[eachChild];
                            currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.VERB_PHRASE);
                            realisedElement.addComponent(currentElement);
                        }
                    }
                    else
                    {
                        currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.VERB_PHRASE);

                        if (whObj)
                        {
                            realisedElement.addComponent(currentElement);
                            realisedElement.addComponent(splitVerb);
                        }
                        else
                        {
                            realisedElement.addComponent(splitVerb);
                            realisedElement.addComponent(currentElement);
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        /**
         * Realises the cue phrase for the clause if it exists.
         *
         * @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 addCuePhrase(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement)
        {
            var currentElement = parent.realise(phrase.getFeatureAsElement(Feature.CUE_PHRASE.ToString()));

            if (currentElement != null)
            {
                currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.CUE_PHRASE);
                realisedElement.addComponent(currentElement);
            }
        }
Exemplo n.º 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));
            }
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
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);
                }
            }
        }
Exemplo n.º 11
0
        /**
         * Realises the auxiliary verbs in the verb group.
         *
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param realisedElement
         *            the current realisation of the noun phrase.
         * @param auxiliaryRealisation
         *            the stack of auxiliary verbs.
         */

        private static void realiseAuxiliaries(SyntaxProcessor parent,
                                               ListElement realisedElement, Stack <INLGElement> auxiliaryRealisation)
        {
            while (!auxiliaryRealisation.isEmpty())
            {
                var aux            = auxiliaryRealisation.pop();
                var currentElement = parent.realise(aux);
                if (currentElement != null)
                {
                    realisedElement.addComponent(currentElement);
                    currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                                              DiscourseFunction.AUXILIARY);
                }
            }
        }
Exemplo n.º 12
0
        /**
         * Realises the key word of the interrogative. For example, <em>who</em>,
         * <em>what</em>
         *
         * @param keyWord
         *            the key word of the interrogative.
         * @param cat
         *            the category (usually pronoun, but not in the case of
         *            "how many")
         * @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 realiseInterrogativeKeyWord(string keyWord,
                                                        ILexicalCategory cat,
                                                        SyntaxProcessor parent,
                                                        ListElement realisedElement,
                                                        NLGFactory phraseFactory)
        {
            if (keyWord != null)
            {
                var question       = phraseFactory.createWord(keyWord, cat);
                var currentElement = parent.realise(question);

                if (currentElement != null)
                {
                    realisedElement.addComponent(currentElement);
                }
            }
        }
Exemplo n.º 13
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());
            }
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 15
0
        /**
         * Adds the front modifiers to the end of the clause when dealing with
         * interrogatives.
         *
         * @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 addInterrogativeFrontModifiers(PhraseElement phrase,
                                                           SyntaxProcessor parent,
                                                           ListElement realisedElement)
        {
            INLGElement currentElement = null;

            if (phrase.hasFeature(Feature.INTERROGATIVE_TYPE.ToString()))
            {
                foreach (var subject in phrase.getFeatureAsElementList(InternalFeature.FRONT_MODIFIERS.ToString()))
                {
                    currentElement = parent.realise(subject);
                    if (currentElement != null)
                    {
                        currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.FRONT_MODIFIER);

                        realisedElement.addComponent(currentElement);
                    }
                }
            }
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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.º 18
0
        /**
         * Iterates through a <code>List</code> of <code>NLGElement</code>s
         * realisation each element and adding it to the on-going realisation of
         * 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 elementList
         *            the <code>List</code> of <code>NLGElement</code>s to be
         *            realised.
         * @param function
         *            the <code>DiscourseFunction</code> each element in the list is
         *            to take. If this is <code>null</code> then the function is not
         *            set and any existing discourse function is kept.
         */

        public static void realiseList(SyntaxProcessor parent,
                                       ListElement realisedElement, List <INLGElement> elementList,
                                       DiscourseFunction function)
        {
            // AG: Change here: the original list structure is kept, i.e. rather
            // than taking the elements of the list and putting them in the realised
            // element, we now add the realised elements to a new list and put that
            // in the realised element list. This preserves constituency for
            // orthography and morphology processing later.
            var         realisedList   = new ListElement();
            INLGElement currentElement = null;

            foreach (var eachElement in elementList)
            {
                currentElement = parent.realise(eachElement);

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

                    if (eachElement.getFeatureAsBoolean(Feature.APPOSITIVE.ToString()))
                    {
                        currentElement.setFeature(Feature.APPOSITIVE.ToString(), true);
                    }

                    // realisedElement.addComponent(currentElement);
                    realisedList.addComponent(currentElement);
                }
            }

            if (!realisedList.getChildren().isEmpty())
            {
                realisedElement.addComponent(realisedList);
            }
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        /**
         * The main method for realising coordinated phrases.
         *
         * @param parent
         *            the <code>SyntaxProcessor</code> that called this method.
         * @param phrase
         *            the <code>CoordinatedPhrase</code> to be realised.
         * @return the realised <code>NLGElement</code>.
         */

        public static INLGElement realise(SyntaxProcessor parent,
                                          CoordinatedPhraseElement phrase)
        {
            ListElement realisedElement = null;

            if (phrase != null)
            {
                realisedElement = new ListElement();
                PhraseHelper.realiseList(parent, realisedElement, phrase
                                         .getPreModifiers(), DiscourseFunction.PRE_MODIFIER);

                var coordinated = new CoordinatedPhraseElement();

                List <INLGElement> children = phrase.getChildren();
                var conjunction             = phrase.getFeatureAsString(Feature.CONJUNCTION.ToString());
                coordinated.setFeature(Feature.CONJUNCTION.ToString(), conjunction);
                coordinated.setFeature(Feature.CONJUNCTION_TYPE.ToString(), phrase
                                       .getFeature(Feature.CONJUNCTION_TYPE.ToString()));

                InflectedWordElement conjunctionElement = null;

                if (children != null && children.size() > 0)
                {
                    if (phrase.getFeatureAsBoolean(Feature.RAISE_SPECIFIER.ToString())
                        )
                    {
                        raiseSpecifier(children);
                    }

                    var child = phrase.getLastCoordinate();
                    if (child is SPhraseSpec)
                    {
                        ((SPhraseSpec)child).setFeature(Feature.POSSESSIVE.ToString(), phrase
                                                        .getFeature(Feature.POSSESSIVE.ToString()));
                    }
                    else
                    {
                        child.setFeature(Feature.POSSESSIVE.ToString(), phrase
                                         .getFeature(Feature.POSSESSIVE.ToString()));
                    }

                    child = children.get(0);

                    setChildFeatures(phrase, child);

                    coordinated.addCoordinate(parent.realise(child));
                    for (var index = 1; index < children.size(); index++)
                    {
                        child = children.get(index);
                        setChildFeatures(phrase, child);
                        if (child is SPhraseSpec)
                        {
                            if (phrase.getFeatureAsBoolean(Feature.AGGREGATE_AUXILIARY.ToString())
                                )
                            {
                                ((SPhraseSpec)child).setFeature(InternalFeature.REALISE_AUXILIARY.ToString(),
                                                                false);
                            }
                        }
                        else
                        {
                            if (phrase.getFeatureAsBoolean(Feature.AGGREGATE_AUXILIARY.ToString())
                                )
                            {
                                child.setFeature(InternalFeature.REALISE_AUXILIARY.ToString(),
                                                 false);
                            }
                        }

                        if (child.isA(PhraseCategoryEnum.CLAUSE))
                        {
                            ((SPhraseSpec)child)
                            .setFeature(
                                Feature.SUPRESSED_COMPLEMENTISER.ToString(),
                                phrase
                                .getFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString()));
                        }

                        //skip conjunction if it's null or empty string
                        if (conjunction != null && conjunction.length() > 0)
                        {
                            conjunctionElement = new InflectedWordElement(
                                conjunction, new LexicalCategory_CONJUNCTION());
                            conjunctionElement.setFeature(
                                InternalFeature.DISCOURSE_FUNCTION.ToString(),
                                DiscourseFunction.CONJUNCTION);
                            coordinated.addCoordinate(conjunctionElement);
                        }

                        coordinated.addCoordinate(parent.realise(child));
                    }
                    realisedElement.addComponent(coordinated);
                }

                PhraseHelper.realiseList(parent, realisedElement, phrase
                                         .getPostModifiers(), DiscourseFunction.POST_MODIFIER);
                PhraseHelper.realiseList(parent, realisedElement, phrase
                                         .getComplements(), DiscourseFunction.COMPLEMENT);
            }
            return(realisedElement);
        }