Пример #1
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);
        }
Пример #2
0
        /**
         * Adds a <em>do</em> verb to the realisation of this clause.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param realisedElement
         *            the current realisation of the clause.
         * @param phraseFactory
         *            the phrase factory to be used.
         */
        private static void addDoAuxiliary(PhraseElement phrase, SyntaxProcessor parent, NLGFactory phraseFactory, ListElement realisedElement)
        {
            PhraseElement doPhrase = phraseFactory.createVerbPhrase("do");             //$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));
        }
Пример #3
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);
                }
            }
        }
Пример #4
0
 public PPPhraseSpec(NLGFactory phraseFactory) : base(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.PREPOSITIONAL_PHRASE))
 {
     Factory = phraseFactory;
 }
Пример #5
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);
        }
Пример #6
0
        public virtual void testSimpleQuestions()
        {
            setUp();
            phraseFactory.Lexicon = lexicon;
            realiser.Lexicon      = lexicon;

            // simple present
            s1 = phraseFactory.createClause(woman, kiss, man);
            s1.setFeature(Feature.TENSE, Tense.PRESENT);
            s1.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);

            NLGFactory      docFactory = new NLGFactory(lexicon);
            DocumentElement sent       = docFactory.createSentence(s1);

            Assert.AreEqual("Does the woman kiss the man?", realiser.realise(sent).Realisation); //$NON-NLS-1$


            // simple past
            // sentence: "the woman kissed the man"
            s1 = phraseFactory.createClause(woman, kiss, man);
            s1.setFeature(Feature.TENSE, Tense.PAST);
            s1.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
            Assert.AreEqual("did the woman kiss the man", realiser.realise(s1).Realisation); //$NON-NLS-1$


            // copular/existential: be-fronting
            // sentence = "there is the dog on the rock"
            s2 = phraseFactory.createClause("there", "be", dog); //$NON-NLS-1$ //$NON-NLS-2$
            s2.addPostModifier(onTheRock);
            s2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
            Assert.AreEqual("is there the dog on the rock", realiser.realise(s2).Realisation); //$NON-NLS-1$


            // perfective
            // sentence -- "there has been the dog on the rock"
            s2 = phraseFactory.createClause("there", "be", dog); //$NON-NLS-1$ //$NON-NLS-2$
            s2.addPostModifier(onTheRock);
            s2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
            s2.setFeature(Feature.PERFECT, true);
            Assert.AreEqual("has there been the dog on the rock", realiser.realise(s2).Realisation); //$NON-NLS-1$


            // progressive
            // sentence: "the man was giving the woman John's flower"
            PhraseElement john = phraseFactory.createNounPhrase("John"); //$NON-NLS-1$

            john.setFeature(Feature.POSSESSIVE, true);
            PhraseElement flower = phraseFactory.createNounPhrase(john, "flower"); //$NON-NLS-1$
            PhraseElement _woman = phraseFactory.createNounPhrase("the", "woman"); //$NON-NLS-1$ //$NON-NLS-2$

            s3 = phraseFactory.createClause(man, give, flower);
            s3.setIndirectObject(_woman);
            s3.setFeature(Feature.TENSE, Tense.PAST);
            s3.setFeature(Feature.PROGRESSIVE, true);
            s3.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
            NLGElement realised = realiser.realise(s3);

            Assert.AreEqual("was the man giving the woman John's flower", realised.Realisation); //$NON-NLS-1$


            // modal
            // sentence: "the man should be giving the woman John's flower"
            setUp();
            john = phraseFactory.createNounPhrase("John");           //$NON-NLS-1$
            john.setFeature(Feature.POSSESSIVE, true);
            flower = phraseFactory.createNounPhrase(john, "flower"); //$NON-NLS-1$
            _woman = phraseFactory.createNounPhrase("the", "woman"); //$NON-NLS-1$ //$NON-NLS-2$
            s3     = phraseFactory.createClause(man, give, flower);
            s3.setIndirectObject(_woman);
            s3.setFeature(Feature.TENSE, Tense.PAST);
            s3.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
            s3.setFeature(Feature.MODAL, "should");            //$NON-NLS-1$
            Assert.AreEqual("should the man have given the woman John's flower",
                            realiser.realise(s3).Realisation); //$NON-NLS-1$


            // complex case with cue phrases
            // sentence: "however, tomorrow, Jane and Andrew will pick up the balls
            // in the shop"
            // this gets the front modifier "tomorrow" shifted to the end
            setUp();
            CoordinatedPhraseElement subjects = new CoordinatedPhraseElement(phraseFactory.createNounPhrase("Jane"),
                                                                             phraseFactory.createNounPhrase("Andrew")); //$NON-NLS-1$ - $NON-NLS-1$

            s4 = phraseFactory.createClause(subjects, "pick up", "the balls");                                          //$NON-NLS-1$ - $NON-NLS-1$
            s4.addPostModifier("in the shop");                                                                          //$NON-NLS-1$
            s4.setFeature(Feature.CUE_PHRASE, "however,");                                                              //$NON-NLS-1$
            s4.addFrontModifier("tomorrow");                                                                            //$NON-NLS-1$
            s4.setFeature(Feature.TENSE, Tense.FUTURE);
            s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
            Assert.AreEqual("however, will Jane and Andrew pick up the balls in the shop tomorrow",
                            realiser.realise(s4).Realisation); //$NON-NLS-1$
        }
Пример #7
0
 private void InitializeInstanceFields()
 {
     docFactory = new NLGFactory(lexicon);
 }
Пример #8
0
 /**
  * Initialise an UnWrapper with a lexicon.
  *
  * @param lexicon
  *            the lexicon to use
  */
 public UnWrapper(Lexicon lexicon)
 {
     factory = new NLGFactory(lexicon);
 }
Пример #9
0
        public void testEnumeratedListWithSeveralLevelsOfNesting()
        {
            var lexicon    = Lexicon.getDefaultLexicon();
            var nlgFactory = new NLGFactory(lexicon);
            var realiser   = new Realiser(lexicon);

            realiser.setFormatter(new TextFormatter());
            var document  = nlgFactory.createDocument("Document");
            var paragraph = nlgFactory.createParagraph();

            // sub item 1
            var subList1Item1     = nlgFactory.createListItem();
            var subList1Sentence1 = nlgFactory.createSentence("sub-list item 1");

            subList1Item1.addComponent(subList1Sentence1);

            // sub sub item 1
            var subSubList1Item1     = nlgFactory.createListItem();
            var subSubList1Sentence1 = nlgFactory.createSentence("sub-sub-list item 1");

            subSubList1Item1.addComponent(subSubList1Sentence1);

            // sub sub item 2
            var subSubList1Item2     = nlgFactory.createListItem();
            var subSubList1Sentence2 = nlgFactory.createSentence("sub-sub-list item 2");

            subSubList1Item2.addComponent(subSubList1Sentence2);

            // sub sub list
            var subSubList1 = nlgFactory.createEnumeratedList();

            subSubList1.addComponent(subSubList1Item1);
            subSubList1.addComponent(subSubList1Item2);

            // sub item 2
            var subList1Item2     = nlgFactory.createListItem();
            var subList1Sentence2 = nlgFactory.createSentence("sub-list item 3");

            subList1Item2.addComponent(subList1Sentence2);

            // sub list 1
            var subList1 = nlgFactory.createEnumeratedList();

            subList1.addComponent(subList1Item1);
            subList1.addComponent(subSubList1);
            subList1.addComponent(subList1Item2);

            // item 2
            var item2     = nlgFactory.createListItem();
            var sentence2 = nlgFactory.createSentence("item 2");

            item2.addComponent(sentence2);

            // item 3
            var item3     = nlgFactory.createListItem();
            var sentence3 = nlgFactory.createSentence("item 3");

            item3.addComponent(sentence3);

            // list
            var list = nlgFactory.createEnumeratedList();

            list.addComponent(subList1);
            list.addComponent(item2);
            list.addComponent(item3);

            paragraph.addComponent(list);

            document.addComponent(paragraph);

            var expectedOutput = "Document\n" +
                                 "\n" +
                                 "1.1 - Sub-list item 1.\n" +
                                 "1.2.1 - Sub-sub-list item 1.\n" +
                                 "1.2.2 - Sub-sub-list item 2.\n" +
                                 "1.3 - Sub-list item 3.\n" +
                                 "2 - Item 2.\n" +
                                 "3 - Item 3.\n" +
                                 "\n\n";

            var realisedOutput = realiser.realise(document).getRealisation();

            Assert.AreEqual(expectedOutput, realisedOutput);
        }
Пример #10
0
 public virtual void tearDown()
 {
     lexicon       = null;
     phraseFactory = null;
     realiser      = null;
 }
Пример #11
0
        public void testSimpleQuestions()
        {
            setUp();
            this.phraseFactory.setLexicon(this.lexicon);
            this.realiser.setLexicon(this.lexicon);

            // simple present
            s1 = this.phraseFactory.createClause(this.woman, this.kiss,
                                                 this.man);
            s1.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
            s1.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);

            var docFactory = new NLGFactory(this.lexicon);
            var sent       = docFactory.createSentence(s1);

            Assert.AreEqual("Does the woman kiss the man?", this.realiser
                            .realise(sent).getRealisation());

            // simple past
            // sentence: "the woman kissed the man"
            s1 = this.phraseFactory.createClause(this.woman, this.kiss,
                                                 this.man);
            s1.setFeature(Feature.TENSE.ToString(), Tense.PAST);
            s1.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
            Assert.AreEqual("did the woman kiss the man", this.realiser
                            .realise(s1).getRealisation());

            // copular/existential: be-fronting
            // sentence = "there is the dog on the rock"
            s2 = this.phraseFactory.createClause("there", "be", this.dog);
            s2.addPostModifier(this.onTheRock);
            s2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
            Assert.AreEqual("is there the dog on the rock", this.realiser
                            .realise(s2).getRealisation());

            // perfective
            // sentence -- "there has been the dog on the rock"
            s2 = this.phraseFactory.createClause("there", "be", this.dog);
            s2.addPostModifier(this.onTheRock);
            s2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
            s2.setFeature(Feature.PERFECT.ToString(), true);
            Assert.AreEqual("has there been the dog on the rock",
                            this.realiser.realise(s2).getRealisation());

            // progressive
            // sentence: "the man was giving the woman John's flower"
            var john = this.phraseFactory.createNounPhrase("John");

            john.setFeature(Feature.POSSESSIVE.ToString(), true);
            var flower = this.phraseFactory.createNounPhrase(john,
                                                             "flower");
            var _woman = this.phraseFactory.createNounPhrase(
                "the", "woman");

            s3 = this.phraseFactory.createClause(this.man, this.give, flower);
            s3.setIndirectObject(_woman);
            s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
            s3.setFeature(Feature.PROGRESSIVE.ToString(), true);
            s3.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
            var realised = this.realiser.realise(s3);

            Assert.AreEqual("was the man giving the woman John's flower",
                            realised.getRealisation());

            // modal
            // sentence: "the man should be giving the woman John's flower"
            setUp();
            john = this.phraseFactory.createNounPhrase("John");
            john.setFeature(Feature.POSSESSIVE.ToString(), true);
            flower = this.phraseFactory.createNounPhrase(john, "flower");
            _woman = this.phraseFactory.createNounPhrase("the", "woman");
            s3     = this.phraseFactory.createClause(this.man, this.give, flower);
            s3.setIndirectObject(_woman);
            s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
            s3.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
            s3.setFeature(Feature.MODAL.ToString(), "should");
            Assert.AreEqual(
                "should the man have given the woman John's flower",
                this.realiser.realise(s3).getRealisation());

            // complex case with cue phrases
            // sentence: "however, tomorrow, Jane and Andrew will pick up the balls
            // in the shop"
            // this gets the front modifier "tomorrow" shifted to the end
            setUp();
            var subjects = new CoordinatedPhraseElement(
                this.phraseFactory.createNounPhrase("Jane"),
                this.phraseFactory.createNounPhrase("Andrew"));

            s4 = this.phraseFactory.createClause(subjects, "pick up",
                                                 "the balls");
            s4.addPostModifier("in the shop");
            s4.setFeature(Feature.CUE_PHRASE.ToString(), "however,");
            s4.addFrontModifier("tomorrow");
            s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
            s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
            Assert.AreEqual(
                "however, will Jane and Andrew pick up the balls in the shop tomorrow",
                this.realiser.realise(s4).getRealisation());
        }
Пример #12
0
        /**
         * @param args
         */
        public static void Main(string[] args)
        {
            // below is a simple complete example of using simplenlg V4
            // afterwards is an example of using simplenlg just for morphology

            // set up
            Lexicon    lexicon    = new XMLLexicon();        // default simplenlg lexicon
            NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon

            // create sentences
            //  "John did not go to the bigger park. He played football there."
            NPPhraseSpec  thePark = nlgFactory.createNounPhrase("the", "park"); // create an NP
            AdjPhraseSpec bigp    = nlgFactory.createAdjectivePhrase("big");    // create AdjP

            bigp.setFeature(Feature.IS_COMPARATIVE, true);                      // use comparative form ("bigger")
            thePark.addModifier(bigp);                                          // add adj as modifier in NP
            // above relies on default placement rules.  You can force placement as a premodifier
            // (before head) by using addPreModifier
            PPPhraseSpec toThePark = nlgFactory.createPrepositionPhrase("to"); // create a PP

            toThePark.setObject(thePark);                                      // set PP object
            // could also just say nlgFactory.createPrepositionPhrase("to", the Park);

            SPhraseSpec johnGoToThePark = nlgFactory.createClause("John", "go", toThePark); // create sentence

            johnGoToThePark.setFeature(Feature.TENSE, Tense.PAST);                          // set tense
            johnGoToThePark.setFeature(Feature.NEGATED, true);                              // set negated

            // note that constituents (such as subject and object) are set with setXXX methods
            // while features are set with setFeature

            DocumentElement sentence = nlgFactory.createSentence(johnGoToThePark);


            // below creates a sentence DocumentElement by concatenating strings
            StringElement hePlayed = new StringElement("he played");
            StringElement there    = new StringElement("there");
            WordElement   football = new WordElement("football");

            DocumentElement sentence2 = nlgFactory.createSentence();

            sentence2.addComponent(hePlayed);
            sentence2.addComponent(football);
            sentence2.addComponent(there);

            // now create a paragraph which contains these sentences
            DocumentElement paragraph = nlgFactory.createParagraph();

            paragraph.addComponent(sentence);
            paragraph.addComponent(sentence2);

            // create a realiser.  Note that a lexicon is specified, this should be
            // the same one used by the NLGFactory
            Realiser realiser = new Realiser(lexicon);
            //realiser.setDebugMode(true);     // uncomment this to print out debug info during realisation
            NLGElement realised = realiser.realise(paragraph);

            Console.WriteLine(realised.Realisation);

            // end of main example

            // second example - using simplenlg just for morphology
            // below is clumsy as direct access to morphology isn't properly supported in V4.2
            // hopefully will be better supported in later versions

            // get word element for "child"
            WordElement word = (WordElement)nlgFactory.createWord("child",
                                                                  new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN));
            // create InflectedWordElement from word element
            InflectedWordElement inflectedWord = new InflectedWordElement(word);

            // set the inflected word to plural
            inflectedWord.Plural = true;
            // realise the inflected word
            string result = realiser.realise(inflectedWord).Realisation;

            Console.WriteLine(result);
        }
Пример #13
0
 /**
  * {@inheritDoc}
  */
 public override void initialise()
 {
     _rules   = new List <AggregationRule>();
     _factory = new NLGFactory();
 }
Пример #14
0
 public override void initialise()
 {
     _syntax  = new SyntaxProcessor();
     _factory = new NLGFactory();
 }
Пример #15
0
 /**
  * Creates a new instance of AggregationRule
  */
 public AggregationRule()
 {
     factory = new NLGFactory();
 }
Пример #16
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));
     }
 }
Пример #17
0
 public virtual void setUp()
 {
     lexicon    = Lexicon.DefaultLexicon;
     nlgFactory = new NLGFactory(lexicon);
     realiser   = new Realiser(lexicon);
 }
Пример #18
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);
                        }
                    }
                }
            }
        }
Пример #19
0
 /**
  * <p>
  * This class defines a adjective phrase.  It is essentially
  * a wrapper around the <code>PhraseElement</code> class, with methods
  * for setting common constituents such as preModifier.
  * For example, the <code>setAdjective</code> method in this class sets
  * the head of the element to be the specified adjective
  *
  * From an API perspective, this class is a simplified version of the AdjPhraseSpec
  * class in simplenlg V3.  It provides an alternative way for creating syntactic
  * structures, compared to directly manipulating a V4 <code>PhraseElement</code>.
  *
  * Methods are provided for setting and getting the following constituents:
  * <UL>
  * <LI>PreModifier		(eg, "very")
  * <LI>Adjective        (eg, "happy")
  * </UL>
  *
  * NOTE: AdjPhraseSpec do not usually have (user-set) features
  *
  * <code>AdjPhraseSpec</code> are produced by the <code>createAdjectivePhrase</code>
  * method of a <code>PhraseFactory</code>
  * </p>
  *
  *
  * @author E. Reiter, University of Aberdeen.
  * @version 4.1
  *
  *      public AdjPhraseSpec(NLGFactory phraseFactory)
  *      {
  *          super(PhraseCategory.ADJECTIVE_PHRASE);
  *          this.setFactory(phraseFactory);
  *      }
  *
  *      /** sets the adjective (head) of the phrase
  * @param adjective
  */
 public AdjPhraseSpec(NLGFactory phraseFactory) : base(new PhraseCategory_ADJECTIVE_PHRASE())
 {
     // set default feature value
     setFeature(Feature.ELIDED.ToString(), false);
     this.setFactory(phraseFactory);
 }
Пример #20
0
        /**
         * This is the main controlling method for handling interrogative clauses.
         * The actual steps taken are dependent on the type of question being asked.
         * The method also determines if there is a subject that will split the verb
         * group of the clause. For example, the clause
         * <em>the man <b>should give</b> the woman the flower</em> has the verb
         * group indicated in <b>bold</b>. The phrase is rearranged as yes/no
         * question as
         * <em><b>should</b> the man <b>give</b> the woman the flower</em> with the
         * subject <em>the man</em> splitting the verb group.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param realisedElement
         *            the current realisation of the clause.
         * @param phraseFactory
         *            the phrase factory to be used.
         * @param verbElement
         *            the <code>NLGElement</code> representing the verb phrase for
         *            this clause.
         * @return an <code>NLGElement</code> representing a subject that should
         *         split the verb
         */
        private static 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);
        }
Пример #21
0
 public override void tearDown()
 {
     base.tearDown();
     docFactory = null;
 }
Пример #22
0
        public virtual void testEnumeratedListWithSeveralLevelsOfNesting()
        {
            Lexicon    lexicon    = Lexicon.DefaultLexicon;
            NLGFactory nlgFactory = new NLGFactory(lexicon);
            Realiser   realiser   = new Realiser(lexicon);

            realiser.Formatter = new TextFormatter();
            DocumentElement document  = nlgFactory.createDocument("Document");
            DocumentElement paragraph = nlgFactory.createParagraph();

            // sub item 1
            DocumentElement subList1Item1     = nlgFactory.createListItem();
            DocumentElement subList1Sentence1 = nlgFactory.createSentence("sub-list item 1");

            subList1Item1.addComponent(subList1Sentence1);

            // sub sub item 1
            DocumentElement subSubList1Item1     = nlgFactory.createListItem();
            DocumentElement subSubList1Sentence1 = nlgFactory.createSentence("sub-sub-list item 1");

            subSubList1Item1.addComponent(subSubList1Sentence1);

            // sub sub item 2
            DocumentElement subSubList1Item2     = nlgFactory.createListItem();
            DocumentElement subSubList1Sentence2 = nlgFactory.createSentence("sub-sub-list item 2");

            subSubList1Item2.addComponent(subSubList1Sentence2);

            // sub sub list
            DocumentElement subSubList1 = nlgFactory.createEnumeratedList();

            subSubList1.addComponent(subSubList1Item1);
            subSubList1.addComponent(subSubList1Item2);

            // sub item 2
            DocumentElement subList1Item2     = nlgFactory.createListItem();
            DocumentElement subList1Sentence2 = nlgFactory.createSentence("sub-list item 3");

            subList1Item2.addComponent(subList1Sentence2);

            // sub list 1
            DocumentElement subList1 = nlgFactory.createEnumeratedList();

            subList1.addComponent(subList1Item1);
            subList1.addComponent(subSubList1);
            subList1.addComponent(subList1Item2);

            // item 2
            DocumentElement item2     = nlgFactory.createListItem();
            DocumentElement sentence2 = nlgFactory.createSentence("item 2");

            item2.addComponent(sentence2);

            // item 3
            DocumentElement item3     = nlgFactory.createListItem();
            DocumentElement sentence3 = nlgFactory.createSentence("item 3");

            item3.addComponent(sentence3);

            // list
            DocumentElement list = nlgFactory.createEnumeratedList();

            list.addComponent(subList1);
            list.addComponent(item2);
            list.addComponent(item3);

            paragraph.addComponent(list);

            document.addComponent(paragraph);

            string expectedOutput = "Document\n" +
                                    "\n" +
                                    "1.1 - Sub-list item 1.\n" +
                                    "1.2.1 - Sub-sub-list item 1.\n" +
                                    "1.2.2 - Sub-sub-list item 2.\n" +
                                    "1.3 - Sub-list item 3.\n" +
                                    "2 - Item 2.\n" +
                                    "3 - Item 3.\n" +
                                    "\n\n";

            string realisedOutput = realiser.realise(document).Realisation;

            Assert.AreEqual(expectedOutput, realisedOutput);
        }