Beispiel #1
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>.
         */
        internal static NLGElement realise(SyntaxProcessor parent, PhraseElement phrase)
        {
            ListElement realisedElement = null;

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

                if (phrase.getFeatureAsBoolean(Feature.PRONOMINAL))
                {
                    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), DiscourseFunction.COMPLEMENT);

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

            return(realisedElement);
        }
Beispiel #2
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)
        {
            NLGElement currentElement = null;

            if (phrase.getFeatureAsBoolean(Feature.PASSIVE))
            {
                IList <NLGElement> allSubjects = phrase.getFeatureAsElementList(InternalFeature.SUBJECTS);

                if (allSubjects.Any() || phrase.hasFeature(Feature.INTERROGATIVE_TYPE))
                {
                    realisedElement.addComponent(parent.realise(phraseFactory.createPrepositionPhrase("by")));                     //$NON-NLS-1$
                }

                foreach (NLGElement subject in allSubjects)
                {
                    subject.setFeature(Feature.PASSIVE, true);
                    if (subject.isA(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.NOUN_PHRASE)) || subject is CoordinatedPhraseElement)
                    {
                        currentElement = parent.realise(subject);
                        if (currentElement != null)
                        {
                            currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.SUBJECT);
                            realisedElement.addComponent(currentElement);
                        }
                    }
                }
            }
        }
Beispiel #3
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.
         */
        internal static void realiseList(SyntaxProcessor parent, ListElement realisedElement, IList <NLGElement> 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.
            ListElement realisedList   = new ListElement();
            NLGElement  currentElement = null;

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

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

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

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

            if (realisedList.Children.Any())
            {
                realisedElement.addComponent(realisedList);
            }
        }
Beispiel #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, NLGElement splitVerb)
 {
     if (!Form.INFINITIVE.Equals(phrase.getFeature(Feature.FORM)) && !Form.IMPERATIVE.Equals(phrase.getFeature(Feature.FORM)) && !phrase.getFeatureAsBoolean(Feature.PASSIVE) && splitVerb == null)
     {
         realisedElement.addComponents(realiseSubjects(phrase, parent).Children);
     }
 }
Beispiel #5
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)))
     {
         NLGElement word = phraseFactory.createWord("to", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.PREPOSITION));                 //$NON-NLS-1$
         realisedElement.addComponent(parent.realise(word));
     }
 }
Beispiel #6
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");             //$NON-NLS-1$

            doPhrase.setFeature(Feature.TENSE, phrase.getFeature(Feature.TENSE));
            doPhrase.setFeature(Feature.PERSON, phrase.getFeature(Feature.PERSON));
            doPhrase.setFeature(Feature.NUMBER, phrase.getFeature(Feature.NUMBER));
            realisedElement.addComponent(parent.realise(doPhrase));
        }
Beispiel #7
0
        /**
         * Realises the pre-modifiers of the noun phrase. Before being realised,
         * pre-modifiers undergo some basic sorting based on adjective ordering.
         *
         * @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 realisePreModifiers(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement)
        {
            IList <NLGElement> preModifiers = phrase.PreModifiers;

            if (phrase.getFeatureAsBoolean(Feature.ADJECTIVE_ORDERING))
            {
                preModifiers = sortNPPreModifiers(preModifiers);
            }
            PhraseHelper.realiseList(parent, realisedElement, preModifiers, DiscourseFunction.PRE_MODIFIER);
        }
Beispiel #8
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)
        {
            NLGElement currentElement = parent.realise(phrase.getFeatureAsElement(Feature.CUE_PHRASE));

            if (currentElement != null)
            {
                currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.CUE_PHRASE);
                realisedElement.addComponent(currentElement);
            }
        }
Beispiel #9
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 NLGElement createPronoun(SyntaxProcessor parent, PhraseElement phrase)
        {
            string     pronoun       = "it";   //$NON-NLS-1$
            NLGFactory phraseFactory = phrase.Factory;
            object     personValue   = phrase.getFeature(Feature.PERSON);

            if (Person.FIRST.Equals(personValue))
            {
                pronoun = "I";                 //$NON-NLS-1$
            }
            else if (Person.SECOND.Equals(personValue))
            {
                pronoun = "you";                 //$NON-NLS-1$
            }
            else
            {
                object genderValue = phrase.getFeature(LexicalFeature.GENDER);
                if (Gender.FEMININE.Equals(genderValue))
                {
                    pronoun = "she";                     //$NON-NLS-1$
                }
                else if (Gender.MASCULINE.Equals(genderValue))
                {
                    pronoun = "he";                     //$NON-NLS-1$
                }
            }
            // AG: createWord now returns WordElement; so we embed it in an
            // inflected word element here
            NLGElement element;
            NLGElement proElement = phraseFactory.createWord(pronoun, new LexicalCategory(LexicalCategory.LexicalCategoryEnum.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, ((WordElement)proElement).getFeature(Feature.PERSON));
            }
            else
            {
                element = proElement;
            }

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


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

            return(element);
        }
        /**
         * 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 <NLGElement> vgComponents)
        {
            object particle = phrase.getFeature(Feature.PARTICLE);

            if (particle is string)
            {
                vgComponents.Push(new StringElement((string)particle));
            }
            else if (particle is NLGElement)
            {
                vgComponents.Push(parent.realise((NLGElement)particle));
            }
        }
Beispiel #11
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.
         */
        internal static NLGElement realise(SyntaxProcessor parent, PhraseElement phrase)
        {
            ListElement realisedElement = null;
            NLGFactory  phraseFactory   = phrase.Factory;
            NLGElement  splitVerb       = null;
            bool        interrogObj     = false;

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

                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))
                {
                    object inter = phrase.getFeature(Feature.INTERROGATIVE_TYPE);
                    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), DiscourseFunction.FRONT_MODIFIER);
                }

                addSubjectsToFront(phrase, parent, realisedElement, splitVerb);

                NLGElement 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);
        }
Beispiel #12
0
        /**
         * Performs the realisation for YES/NO types of questions. This may involve
         * adding an optional <em>do</em> auxiliary verb to the beginning of the
         * clause. 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.
         * @param subjects
         *            the <code>List</code> of subjects in the clause.
         * @return an <code>NLGElement</code> representing a subject that should
         *         split the verb
         */
        private static NLGElement realiseYesNo(PhraseElement phrase, SyntaxProcessor parent, NLGElement verbElement, NLGFactory phraseFactory, ListElement realisedElement)
        {
            NLGElement splitVerb = null;

            if (!(verbElement is VPPhraseSpec && VerbPhraseHelper.isCopular(((VPPhraseSpec)verbElement).getVerb())) && !phrase.getFeatureAsBoolean(Feature.PROGRESSIVE) && !phrase.hasFeature(Feature.MODAL) && !Tense.FUTURE.Equals(phrase.getFeature(Feature.TENSE)) && !phrase.getFeatureAsBoolean(Feature.NEGATED) && !phrase.getFeatureAsBoolean(Feature.PASSIVE))
            {
                addDoAuxiliary(phrase, parent, phraseFactory, realisedElement);
            }
            else
            {
                splitVerb = realiseSubjects(phrase, parent);
            }
            return(splitVerb);
        }
Beispiel #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)
        {
            NLGElement currentElement;

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

                if (currentElement != null)
                {
                    realisedElement.addComponent(currentElement);
                }
            }
        }
Beispiel #14
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 NLGElement realiseInterrogative(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement, NLGFactory phraseFactory, NLGElement verbElement)
        {
            NLGElement splitVerb = null;

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

            object type = phrase.getFeature(Feature.INTERROGATIVE_TYPE);

            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(LexicalCategory.LexicalCategoryEnum.PRONOUN), parent, realisedElement, phraseFactory);                      //$NON-NLS-1$
                    phrase.removeFeature(InternalFeature.SUBJECTS);
                    break;

                case InterrogativeType.HOW_MANY:
                    realiseInterrogativeKeyWord("how", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.PRONOUN), parent, realisedElement, phraseFactory);                     //$NON-NLS-1$
                    realiseInterrogativeKeyWord("many", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADVERB), parent, realisedElement, phraseFactory);                     //$NON-NLS-1$
                    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);
        }
Beispiel #15
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, NLGElement splitVerb, NLGElement verbElement, bool whObj)
        {
            setVerbFeatures(phrase, verbElement);

            NLGElement currentElement = parent.realise(verbElement);

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

                    realisedElement.addComponent(currentElement);
                }
                else
                {
                    if (currentElement is ListElement)
                    {
                        IList <NLGElement> children = currentElement.Children;
                        currentElement = children[0];
                        currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.VERB_PHRASE);
                        realisedElement.addComponent(currentElement);
                        realisedElement.addComponent(splitVerb);

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

                        if (whObj)
                        {
                            realisedElement.addComponent(currentElement);
                            realisedElement.addComponent(splitVerb);
                        }
                        else
                        {
                            realisedElement.addComponent(splitVerb);
                            realisedElement.addComponent(currentElement);
                        }
                    }
                }
            }
        }
        /**
         * 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 <NLGElement> auxiliaryRealisation)
        {
            NLGElement aux            = null;
            NLGElement currentElement = null;

            while (auxiliaryRealisation.Any())
            {
                aux            = auxiliaryRealisation.Pop();
                currentElement = parent.realise(aux);
                if (currentElement != null)
                {
                    realisedElement.addComponent(currentElement);
                    currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.AUXILIARY);
                }
            }
        }
        /**
         * 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)
        {
            ListElement indirects      = new ListElement();
            ListElement directs        = new ListElement();
            ListElement unknowns       = new ListElement();
            object      discourseValue = null;
            NLGElement  currentElement = null;

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

                    if (DiscourseFunction.INDIRECT_OBJECT.Equals(discourseValue))
                    {
                        indirects.addComponent(currentElement);
                    }
                    else if (DiscourseFunction.OBJECT.Equals(discourseValue))
                    {
                        directs.addComponent(currentElement);
                    }
                    else
                    {
                        unknowns.addComponent(currentElement);
                    }
                }
            }

            InterrogativeType?interrogativeType = (InterrogativeType?)phrase.getFeature(Feature.INTERROGATIVE_TYPE);

            if (interrogativeType == null || !((InterrogativeType)interrogativeType).isIndirectObject())
            {
                realisedElement.addComponents(indirects.Children);
            }
            if (!phrase.getFeatureAsBoolean(Feature.PASSIVE))
            {
                if (interrogativeType == null || !((InterrogativeType)interrogativeType).isObject())
                {
                    realisedElement.addComponents(directs.Children);
                }
                realisedElement.addComponents(unknowns.Children);
            }
        }
        /**
         * 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 <NLGElement> mainVerbRealisation, ListElement realisedElement)
        {
            NLGElement currentElement = null;
            NLGElement main           = null;

            while (mainVerbRealisation.Any())
            {
                main = mainVerbRealisation.Pop();
                main.setFeature(Feature.INTERROGATIVE_TYPE, phrase.getFeature(Feature.INTERROGATIVE_TYPE));
                currentElement = parent.realise(main);

                if (currentElement != null)
                {
                    realisedElement.addComponent(currentElement);
                }
            }
        }
Beispiel #19
0
        /**
         * The main method for realising 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>.
         */
        internal static NLGElement realise(SyntaxProcessor parent, PhraseElement phrase)
        {
            ListElement realisedElement = null;

            if (phrase != null)
            {
                realisedElement = new ListElement();

                realiseList(parent, realisedElement, phrase.PreModifiers, DiscourseFunction.PRE_MODIFIER);

                realiseHead(parent, phrase, realisedElement);
                realiseComplements(parent, phrase, realisedElement);

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

            return(realisedElement);
        }
Beispiel #20
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)
        {
            NLGElement currentElement = null;

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

                        realisedElement.addComponent(currentElement);
                    }
                }
            }
        }
Beispiel #21
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)
        {
            NLGElement head = phrase.getHead();

            if (head != null)
            {
                if (phrase.hasFeature(Feature.IS_COMPARATIVE))
                {
                    head.setFeature(Feature.IS_COMPARATIVE, phrase.getFeature(Feature.IS_COMPARATIVE));
                }
                else if (phrase.hasFeature(Feature.IS_SUPERLATIVE))
                {
                    head.setFeature(Feature.IS_SUPERLATIVE, phrase.getFeature(Feature.IS_SUPERLATIVE));
                }
                head = parent.realise(head);
                head.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.HEAD);
                realisedElement.addComponent(head);
            }
        }
Beispiel #22
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)
        {
            NLGElement headElement = phrase.getHead();

            if (headElement != null)
            {
                headElement.setFeature(Feature.ELIDED, phrase.getFeature(Feature.ELIDED));
                headElement.setFeature(LexicalFeature.GENDER, phrase.getFeature(LexicalFeature.GENDER));
                headElement.setFeature(InternalFeature.ACRONYM, phrase.getFeature(InternalFeature.ACRONYM));
                headElement.setFeature(Feature.NUMBER, phrase.getFeature(Feature.NUMBER));
                headElement.setFeature(Feature.PERSON, phrase.getFeature(Feature.PERSON));
                headElement.setFeature(Feature.POSSESSIVE, phrase.getFeature(Feature.POSSESSIVE));
                headElement.setFeature(Feature.PASSIVE, phrase.getFeature(Feature.PASSIVE));
                headElement.setFeature(Feature.IS_CAPITALIZED, phrase.getFeature(Feature.IS_CAPITALIZED));
                NLGElement currentElement = parent.realise(headElement);
                currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.SUBJECT);
                realisedElement.addComponent(currentElement);
            }
        }
Beispiel #23
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)
        {
            NLGElement specifierElement = phrase.getFeatureAsElement(InternalFeature.SPECIFIER);

            if (specifierElement != null && !phrase.getFeatureAsBoolean(InternalFeature.RAISED) && !phrase.getFeatureAsBoolean(Feature.ELIDED))
            {
                if (!specifierElement.isA(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.PRONOUN)) && specifierElement.Category != PhraseCategory.PhraseCategoryEnum.NOUN_PHRASE)
                {
                    specifierElement.setFeature(Feature.NUMBER, phrase.getFeature(Feature.NUMBER));
                }

                NLGElement currentElement = parent.realise(specifierElement);

                if (currentElement != null)
                {
                    currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.SPECIFIER);
                    realisedElement.addComponent(currentElement);
                }
            }
        }
Beispiel #24
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)
        {
            NLGElement  currentElement  = null;
            ListElement realisedElement = new ListElement();

            foreach (NLGElement subject in phrase.getFeatureAsElementList(InternalFeature.SUBJECTS))
            {
                subject.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.SUBJECT);
                if (Form.GERUND.Equals(phrase.getFeature(Feature.FORM)) && !phrase.getFeatureAsBoolean(Feature.SUPPRESS_GENITIVE_IN_GERUND))
                {
                    subject.setFeature(Feature.POSSESSIVE, true);
                }
                currentElement = parent.realise(subject);
                if (currentElement != null)
                {
                    realisedElement.addComponent(currentElement);
                }
            }
            return(realisedElement);
        }
        /**
         * The main method for realising verb phrases.
         *
         * @param parent
         *            the <code>SyntaxProcessor</code> that called this method.
         * @param phrase
         *            the <code>PhraseElement</code> to be realised.
         * @return the realised <code>NLGElement</code>.
         */
        internal static NLGElement realise(SyntaxProcessor parent, PhraseElement phrase)
        {
            ListElement        realisedElement      = null;
            Stack <NLGElement> vgComponents         = null;
            Stack <NLGElement> mainVerbRealisation  = new Stack <NLGElement>();
            Stack <NLGElement> auxiliaryRealisation = new Stack <NLGElement>();

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

                realisedElement = new ListElement();

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

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

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

            return(realisedElement);
        }
Beispiel #26
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)
        {
            bool       firstProcessed = false;
            NLGElement currentElement = null;

            foreach (NLGElement complement in phrase.getFeatureAsElementList(InternalFeature.COMPLEMENTS))
            {
                currentElement = parent.realise(complement);
                if (currentElement != null)
                {
                    currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.COMPLEMENT);
                    if (firstProcessed)
                    {
                        realisedElement.addComponent(new InflectedWordElement("and", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.CONJUNCTION)));                         //$NON-NLS-1$
                    }
                    else
                    {
                        firstProcessed = true;
                    }
                    realisedElement.addComponent(currentElement);
                }
            }
        }
Beispiel #27
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>.
         */
        internal static NLGElement realise(SyntaxProcessor parent, CoordinatedPhraseElement phrase)
        {
            ListElement realisedElement = null;

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

                CoordinatedPhraseElement coordinated = new CoordinatedPhraseElement();

                IList <NLGElement> children    = phrase.Children;
                string             conjunction = phrase.getFeatureAsString(Feature.CONJUNCTION);
                coordinated.setFeature(Feature.CONJUNCTION, conjunction);
                coordinated.setFeature(Feature.CONJUNCTION_TYPE, phrase.getFeature(Feature.CONJUNCTION_TYPE));

                InflectedWordElement conjunctionElement = null;

                if (children != null && children.Any())
                {
                    if (phrase.getFeatureAsBoolean(Feature.RAISE_SPECIFIER))
                    {
                        raiseSpecifier(children);
                    }

                    NLGElement child = phrase.LastCoordinate;
                    child.setFeature(Feature.POSSESSIVE, phrase.getFeature(Feature.POSSESSIVE));

                    child = children[0];

                    setChildFeatures(phrase, child);

                    coordinated.addCoordinate(parent.realise(child));
                    for (int index = 1; index < children.Count; index++)
                    {
                        child = children[index];
                        setChildFeatures(phrase, child);
                        if (phrase.getFeatureAsBoolean(Feature.AGGREGATE_AUXILIARY))
                        {
                            child.setFeature(InternalFeature.REALISE_AUXILIARY, false);
                        }

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

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

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

                PhraseHelper.realiseList(parent, realisedElement, phrase.PostModifiers, DiscourseFunction.POST_MODIFIER);
                PhraseHelper.realiseList(parent, realisedElement, phrase.Complements, DiscourseFunction.COMPLEMENT);
            }
            return(realisedElement);
        }
Beispiel #28
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, LexicalCategory cat, SyntaxProcessor parent, ListElement realisedElement, NLGFactory phraseFactory)
        {
            if (!ReferenceEquals(keyWord, null))
            {
                NLGElement question       = phraseFactory.createWord(keyWord, cat);
                NLGElement currentElement = parent.realise(question);

                if (currentElement != null)
                {
                    realisedElement.addComponent(currentElement);
                }
            }
        }
Beispiel #29
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 NLGElement addPassiveComplementsNumberPerson(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement, NLGElement verbElement)
        {
            object     passiveNumber  = null;
            object     passivePerson  = null;
            NLGElement currentElement = null;
            NLGElement splitVerb      = null;
            NLGElement verbPhrase     = phrase.getFeatureAsElement(InternalFeature.VERB_PHRASE);

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

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

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

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

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

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

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

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

            if (verbElement != null)
            {
                if (passivePerson != null)
                {
                    verbElement.setFeature(Feature.PERSON, 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, NumberAgreement.PLURAL);
                }
                else if (passiveNumber != null)
                {
                    verbElement.setFeature(Feature.NUMBER, passiveNumber);
                }
            }
            return(splitVerb);
        }
Beispiel #30
0
        /**
         * Controls the realisation of <em>wh</em> object questions.
         *
         * @param keyword
         *            the wh word
         * @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 subjects
         *            the <code>List</code> of subjects in the clause.
         * @return an <code>NLGElement</code> representing a subject that should
         *         split the verb
         */
        private static NLGElement realiseObjectWHInterrogative(string keyword, PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement, NLGFactory phraseFactory)
        {
            NLGElement splitVerb = null;

            realiseInterrogativeKeyWord(keyword, new LexicalCategory(LexicalCategory.LexicalCategoryEnum.PRONOUN), parent, realisedElement, phraseFactory);             //$NON-NLS-1$


            // if (!Tense.FUTURE.equals(phrase.getFeature(Feature.TENSE)) && !copular) {
            if (!hasAuxiliary(phrase) && !VerbPhraseHelper.isCopular(phrase))
            {
                addDoAuxiliary(phrase, parent, phraseFactory, realisedElement);
            }
            else if (!phrase.getFeatureAsBoolean(Feature.PASSIVE))
            {
                splitVerb = realiseSubjects(phrase, parent);
            }

            return(splitVerb);
        }