Пример #1
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);
            }
        }
Пример #2
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);
                        }
                    }
                }
            }
        }
Пример #3
0
 /**
  * Utility method to set the discourse function for phrase components,
  * unless set by user
  *
  * @param function
  *            the function
  * @param phrase
  *            the phrase
  */
 private void checkFunction(DiscourseFunction function, NLGElement phrase)
 {
     if (!phrase.hasFeature(InternalFeature.DISCOURSE_FUNCTION))
     {
         phrase.setFeature(InternalFeature.DISCOURSE_FUNCTION, function);
     }
 }
Пример #4
0
 /**
  * Checks to see if the phrase is in imperative, infinitive or bare
  * infinitive form. If it is then no morphology is done on the main verb.
  *
  * @param formValue
  *            the <code>Form</code> of the phrase.
  * @param frontVG
  *            the first verb in the verb group.
  */
 private static void checkImperativeInfinitive(object formValue, NLGElement frontVG)
 {
     if ((Form.IMPERATIVE.Equals(formValue) || Form.INFINITIVE.Equals(formValue) || Form.BARE_INFINITIVE.Equals(formValue)) && frontVG != null)
     {
         frontVG.setFeature(InternalFeature.NON_MORPH, true);
     }
 }
Пример #5
0
        /**
         * Perform aggregation on a single phrase. This method only works on a
         * {@link simplenlg.framework.CoordinatedPhraseElement}, in which case it
         * calls {@link #apply(List)} on the children of the coordinated phrase,
         * returning a coordinated phrase whose children are the result.
         *
         * @param phrase
         * @return aggregated result
         */
        public virtual NLGElement apply(NLGElement phrase)
        {
            NLGElement result = null;

            if (phrase is CoordinatedPhraseElement)
            {
                IList <NLGElement> children   = ((CoordinatedPhraseElement)phrase).Children;
                IList <NLGElement> aggregated = apply(children);

                if (aggregated.Count == 1)
                {
                    result = aggregated[0];
                }
                else
                {
                    result = factory.createCoordinatedPhrase();

                    foreach (NLGElement agg in aggregated)
                    {
                        ((CoordinatedPhraseElement)result).addCoordinate(agg);
                    }
                }
            }


            if (result != null)
            {
                foreach (string feature in phrase.AllFeatureNames)
                {
                    result.setFeature(feature, phrase.getFeature(feature));
                }
            }

            return(result);
        }
Пример #6
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);
                        }
                    }
                }
            }
        }
Пример #7
0
 /**
  * Adds the <em>be</em> verb to the front of the group.
  *
  * @param frontVG
  *            the first verb in the verb group.
  * @param vgComponents
  *            the stack of verb components in the verb group.
  * @param frontForm
  *            the form the current front verb is to take.
  * @return the new element for the front of the group.
  */
 private static NLGElement addBe(NLGElement frontVG, Stack <NLGElement> vgComponents, Form frontForm)
 {
     if (frontVG != null)
     {
         frontVG.setFeature(Feature.FORM, frontForm);
         vgComponents.Push(frontVG);
     }
     return(new InflectedWordElement("be", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)));            //$NON-NLS-1$
 }
Пример #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);
            }
        }
Пример #9
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);
            }
        }
Пример #10
0
        /**
         * Checks to see if the specifier can be raised and then raises it. In order
         * to be raised the specifier must be the same on all coordinates. For
         * example, <em>the cat and the dog</em> will be realised as
         * <em>the cat and dog</em> while <em>the cat and any dog</em> will remain
         * <em>the cat and any dog</em>.
         *
         * @param children
         *            the <code>List</code> of coordinates in the
         *            <code>CoordinatedPhraseElement</code>
         */
        private static void raiseSpecifier(IList <NLGElement> children)
        {
            bool       allMatch  = true;
            NLGElement child     = children[0];
            NLGElement specifier = null;
            string     test      = null;

            if (child != null)
            {
                specifier = child.getFeatureAsElement(InternalFeature.SPECIFIER);

                if (specifier != null)
                {
                    // AG: this assumes the specifier is an InflectedWordElement or
                    // phrase.
                    // it could be a Wordelement, in which case, we want the
                    // baseform
                    test = (specifier is WordElement) ? ((WordElement)specifier).BaseForm : specifier.getFeatureAsString(LexicalFeature.BASE_FORM);
                }

                if (!ReferenceEquals(test, null))
                {
                    int index = 1;

                    while (index < children.Count && allMatch)
                    {
                        child = children[index];

                        if (child == null)
                        {
                            allMatch = false;
                        }
                        else
                        {
                            specifier = child.getFeatureAsElement(InternalFeature.SPECIFIER);
                            string childForm = (specifier is WordElement) ? ((WordElement)specifier).BaseForm : specifier.getFeatureAsString(LexicalFeature.BASE_FORM);

                            if (!test.Equals(childForm))
                            {
                                allMatch = false;
                            }
                        }
                        index++;
                    }
                    if (allMatch)
                    {
                        for (int eachChild = 1; eachChild < children.Count; eachChild++)
                        {
                            child = children[eachChild];
                            child.setFeature(InternalFeature.RAISED, true);
                        }
                    }
                }
            }
        }
Пример #11
0
        /**
         * Elide the leftmost consitutents in the phrase list, that is, all phrases
         * except the rightmost.
         */
        public virtual void elideLeftmost()
        {
            for (int i = phrases.Count - 2; i >= 0; i--)
            {
                NLGElement phrase = phrases[i];

                if (phrase != null)
                {
                    phrase.setFeature(Feature.ELIDED, true);
                }
            }
        }
Пример #12
0
        /**
         * Elide the rightmost constituents in the phrase list, that is, all phrases
         * except the first.
         */
        public virtual void elideRightmost()
        {
            for (int i = 1; i < phrases.Count; i++)
            {
                NLGElement phrase = phrases[i];

                if (phrase != null)
                {
                    phrase.setFeature(Feature.ELIDED, true);
                }
            }
        }
Пример #13
0
        /**
         * Copies the front modifiers of the clause to the list of post-modifiers of
         * the verb only if the phrase has infinitive form.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         * @param verbElement
         *            the <code>NLGElement</code> representing the verb phrase for
         *            this clause.
         */
        private static void copyFrontModifiers(PhraseElement phrase, NLGElement verbElement)
        {
            IList <NLGElement> frontModifiers = phrase.getFeatureAsElementList(InternalFeature.FRONT_MODIFIERS);
            object             clauseForm     = phrase.getFeature(Feature.FORM);

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

                if (verbElement is PhraseElement)
                {
                    IList <NLGElement> verbPostModifiers = verbElement.getFeatureAsElementList(InternalFeature.POSTMODIFIERS);

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

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

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

                foreach (NLGElement eachModifier in frontModifiers)
                {
                    if (verbElement is PhraseElement)
                    {
                        ((PhraseElement)verbElement).addPostModifier(eachModifier);
                    }
                }
                phrase.removeFeature(InternalFeature.FRONT_MODIFIERS);
                if (verbElement != null)
                {
                    verbElement.setFeature(InternalFeature.NON_MORPH, true);
                }
            }
        }
Пример #14
0
        // intercept and override setFeature, to set VP features as needed

        /**
         * adds a feature, possibly to the underlying VP as well as the SPhraseSpec
         * itself
         *
         * @see simplenlg.framework.NLGElement#setFeature(java.lang.String,
         * java.lang.Object)
         */
        public override void setFeature(string featureName, object featureValue)
        {
            base.setFeature(featureName, featureValue);

            if (vpFeatures.Contains(featureName))
            {
                NLGElement verbPhrase = (NLGElement)getFeatureAsElement(InternalFeature.VERB_PHRASE);
                if (verbPhrase != null || verbPhrase is VPPhraseSpec)
                {
                    verbPhrase.setFeature(featureName, featureValue);
                }
            }
        }
Пример #15
0
        public virtual void testTwoPossessiveFeature_PastTense()
        {
            phraseFactory.Lexicon = lexicon;

            // Create the pronoun 'she'
            NLGElement she =
                phraseFactory.createWord("she", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.PRONOUN));

            // Set possessive on the pronoun to make it 'her'
            she.setFeature(Feature.POSSESSIVE, true);

            // Create a noun phrase with the subject lover and the determiner as she
            PhraseElement herLover = phraseFactory.createNounPhrase(she, "lover");

            herLover.Plural = true;

            // Create the pronoun 'he'
            NLGElement he =
                phraseFactory.createNounPhrase(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.PRONOUN), "he");

            he.Plural = true;

            // Create a clause to say 'they be her lovers'
            PhraseElement clause = phraseFactory.createClause(he, "be", herLover);

            clause.setFeature(Feature.POSSESSIVE, true);

            // Add the cue phrase need the comma as orthography
            // currently doesn't handle this.
            // This could be expanded to be a noun phrase with determiner
            // 'two' and noun 'week', set to plural and with a premodifier of
            // 'after'
            clause.setFeature(Feature.CUE_PHRASE, "after two weeks,");

            // Add the 'for a fortnight' as a post modifier. Alternatively
            // this could be added as a prepositional phrase 'for' with a
            // complement of a noun phrase ('a' 'fortnight')
            clause.addPostModifier("for a fortnight");

            // Set 'be' to 'was' as past tense
            clause.setFeature(Feature.TENSE, Tense.PAST);

            // Add the clause to a sentence.
            DocumentElement sentence1 = docFactory.createSentence(clause);

            // Realise the sentence
            NLGElement realised = realiser.realise(sentence1);

            Assert.AreEqual("After two weeks, they were her lovers for a fortnight.",
                            realised.Realisation); //$NON-NLS-1$
        }
Пример #16
0
 private void recursiveElide(NLGElement component)
 {
     if (component is ListElement)
     {
         foreach (NLGElement subcomponent in component.getFeatureAsElementList(InternalFeature.COMPONENTS))
         {
             recursiveElide(subcomponent);
         }
     }
     else
     {
         component.setFeature(Feature.ELIDED, true);
     }
 }
Пример #17
0
 /*
  * (non-Javadoc)
  *
  * @see simplenlg.framework.NLGElement#setFeature(java.lang.String, boolean)
  */
 public override void setFeature(string featureName, bool featureValue)
 {
     base.setFeature(featureName, featureValue);
     if (vpFeatures.Contains(featureName))
     {
         //PhraseElement verbPhrase = (PhraseElement) getFeatureAsElement(InternalFeature.VERB_PHRASE);
         //AG: bug fix: VP could be coordinate phrase, so cast to NLGElement not PhraseElement
         NLGElement verbPhrase = (NLGElement)getFeatureAsElement(InternalFeature.VERB_PHRASE);
         if (verbPhrase != null || verbPhrase is VPPhraseSpec)
         {
             verbPhrase.setFeature(featureName, featureValue);
         }
     }
 }
Пример #18
0
        /**
         * Pushes the front verb on to the stack if the phrase has a modal.
         *
         * @param hasModal
         *            the phrase has a modal
         * @param phrase
         *            the <code>PhraseElement</code> representing this noun phrase.
         * @param frontVG
         *            the first verb in the verb group.
         * @param vgComponents
         *            the stack of verb components in the verb group.
         * @return the new element for the front of the group.
         */
        private static NLGElement pushIfModal(bool hasModal, PhraseElement phrase, NLGElement frontVG, Stack <NLGElement> vgComponents)
        {
            NLGElement newFront = frontVG;

            if (hasModal && !phrase.getFeatureAsBoolean(InternalFeature.IGNORE_MODAL))
            {
                if (frontVG != null)
                {
                    frontVG.setFeature(InternalFeature.NON_MORPH, true);
                    vgComponents.Push(frontVG);
                }
                newFront = null;
            }
            return(newFront);
        }
Пример #19
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 <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);
                }
            }
        }
Пример #20
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 <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);
                }
            }
        }
Пример #21
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)
        {
            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);
            }
        }
Пример #22
0
        /**
         * Adds <em>have</em> to the stack.
         *
         * @param frontVG
         *            the first verb in the verb group.
         * @param vgComponents
         *            the stack of verb components in the verb group.
         * @param modal
         *            the modal to be used.
         * @param tenseValue
         *            the <code>Tense</code> of the phrase.
         * @return the new element for the front of the group.
         */
        private static NLGElement addHave(NLGElement frontVG, Stack <NLGElement> vgComponents, string modal, Tense tenseValue)
        {
            NLGElement newFront = frontVG;

            if (frontVG != null)
            {
                frontVG.setFeature(Feature.FORM, Form.PAST_PARTICIPLE);
                vgComponents.Push(frontVG);
            }
            newFront = new InflectedWordElement("have", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB));             //$NON-NLS-1$
            newFront.setFeature(Feature.TENSE, tenseValue);
            if (!ReferenceEquals(modal, null))
            {
                newFront.setFeature(InternalFeature.NON_MORPH, true);
            }
            return(newFront);
        }
Пример #23
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);
            }
        }
Пример #24
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);
                    }
                }
            }
        }
Пример #25
0
        /**
         * Adds <em>not</em> to the stack if the phrase is negated.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this noun phrase.
         * @param vgComponents
         *            the stack of verb components in the verb group.
         * @param frontVG
         *            the first verb in the verb group.
         * @param hasModal
         *            the phrase has a modal
         * @return the new element for the front of the group.
         */
        private static NLGElement createNot(PhraseElement phrase, Stack <NLGElement> vgComponents, NLGElement frontVG, bool hasModal)
        {
            NLGElement newFront = frontVG;

            if (phrase.getFeatureAsBoolean(Feature.NEGATED))
            {
                NLGFactory factory = phrase.Factory;

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

                if (vgComponents.Any() || frontVG != null && isCopular(frontVG))
                {
                    vgComponents.Push(new InflectedWordElement("not", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADVERB)));                     //$NON-NLS-1$
                }
                else
                {
                    if (frontVG != null && !hasModal)
                    {
                        frontVG.setFeature(Feature.NEGATED, true);
                        vgComponents.Push(frontVG);
                    }

                    vgComponents.Push(new InflectedWordElement("not", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADVERB)));                     //$NON-NLS-1$

                    if (addDo)
                    {
                        if (factory != null)
                        {
                            newFront = factory.createInflectedWord("do", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB));
                        }
                        else
                        {
                            newFront = new InflectedWordElement("do", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB));                             //$NON-NLS-1$
                        }
                    }
                }
            }

            return(newFront);
        }
Пример #26
0
        /**
         * Pushes the front verb onto the stack of verb components.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this noun phrase.
         * @param vgComponents
         *            the stack of verb components in the verb group.
         * @param frontVG
         *            the first verb in the verb group.
         * @param formValue
         *            the <code>Form</code> of the phrase.
         * @param interrogative
         *            <code>true</code> if the phrase is interrogative.
         */
        private static void pushFrontVerb(PhraseElement phrase, Stack <NLGElement> vgComponents, NLGElement frontVG, object formValue, bool interrogative)
        {
            object interrogType = phrase.getFeature(Feature.INTERROGATIVE_TYPE);

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

                vgComponents.Push(frontVG);
            }
            else
            {
                NumberAgreement?numToUse = determineNumber(phrase.Parent, phrase);
                frontVG.setFeature(Feature.TENSE, phrase.getFeature(Feature.TENSE));
                frontVG.setFeature(Feature.PERSON, phrase.getFeature(Feature.PERSON));
                frontVG.setFeature(Feature.NUMBER, numToUse);

                //don't push the front VG if it's a negated interrogative WH object question
                if (!(phrase.getFeatureAsBoolean(Feature.NEGATED) && (InterrogativeType.WHO_OBJECT.Equals(interrogType) || InterrogativeType.WHAT_OBJECT.Equals(interrogType))))
                {
                    vgComponents.Push(frontVG);
                }
            }
        }
Пример #27
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);
                }
            }
        }
Пример #28
0
        public virtual void correctPluralizationWithPossessives()
        {
            NPPhraseSpec sisterNP = nlgFactory.createNounPhrase("sister");
            NLGElement   word     = nlgFactory.createInflectedWord("Albert Einstein",
                                                                   new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN));

            word.setFeature(LexicalFeature.PROPER, true);
            NPPhraseSpec possNP = nlgFactory.createNounPhrase(word);

            possNP.setFeature(Feature.POSSESSIVE, true);
            sisterNP.setSpecifier(possNP);
            Assert.AreEqual("Albert Einstein's sister", realiser.realise(sisterNP).Realisation);
            sisterNP.Plural = true;
            Assert.AreEqual("Albert Einstein's sisters", realiser.realise(sisterNP).Realisation);
            sisterNP.Plural = false;
            possNP.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
            possNP.setFeature(Feature.PRONOMINAL, true);
            Assert.AreEqual("his sister", realiser.realise(sisterNP).Realisation);
            sisterNP.Plural = true;
            Assert.AreEqual("his sisters", realiser.realise(sisterNP).Realisation);
        }
Пример #29
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);
                }
            }
        }
Пример #30
0
        public override NLGElement realise(NLGElement element)
        {
            StringBuilder debug = new StringBuilder();

            if (this.debug)
            {
                Console.WriteLine("INITIAL TREE\n");                 //$NON-NLS-1$
                Console.WriteLine(element.printTree(null));
                debug.Append("INITIAL TREE<br/>");
                debug.Append(element.printTree("&nbsp;&nbsp;").Replace("\n", "<br/>"));
            }

            NLGElement postSyntax = syntax.realise(element);

            if (this.debug)
            {
                Console.WriteLine("<br/>POST-SYNTAX TREE<br/>");                 //$NON-NLS-1$
                Console.WriteLine(postSyntax.printTree(null));
                debug.Append("<br/>POST-SYNTAX TREE<br/>");
                debug.Append(postSyntax.printTree("&nbsp;&nbsp;").Replace("\n", "<br/>"));
            }

            NLGElement postMorphology = morphology.realise(postSyntax);

            if (this.debug)
            {
                Console.WriteLine("\nPOST-MORPHOLOGY TREE\n");                 //$NON-NLS-1$
                Console.WriteLine(postMorphology.printTree(null));
                debug.Append("<br/>POST-MORPHOLOGY TREE<br/>");
                debug.Append(postMorphology.printTree("&nbsp;&nbsp;").Replace("\n", "<br/>"));
            }

            NLGElement postOrthography = orthography.realise(postMorphology);

            if (this.debug)
            {
                Console.WriteLine("\nPOST-ORTHOGRAPHY TREE\n");                 //$NON-NLS-1$
                Console.WriteLine(postOrthography.printTree(null));
                debug.Append("<br/>POST-ORTHOGRAPHY TREE<br/>");
                debug.Append(postOrthography.printTree("&nbsp;&nbsp;").Replace("\n", "<br/>"));
            }

            NLGElement postFormatter = null;

            if (formatter != null)
            {
                postFormatter = formatter.realise(postOrthography);
                if (this.debug)
                {
                    Console.WriteLine("\nPOST-FORMATTER TREE\n");                     //$NON-NLS-1$
                    Console.WriteLine(postFormatter.printTree(null));
                    debug.Append("<br/>POST-FORMATTER TREE<br/>");
                    debug.Append(postFormatter.printTree("&nbsp;&nbsp;").Replace("\n", "<br/>"));
                }
            }
            else
            {
                postFormatter = postOrthography;
            }

            if (this.debug)
            {
                postFormatter.setFeature("debug", debug.ToString());
            }

            return(postFormatter);
        }