예제 #1
0
        public void novelliTest()
        {
            // Nicole Novelli's test
            SPhraseSpec p = SetupForExternalTest.phraseFactory.createClause(
                "Mary", "chase", "George");

            PPPhraseSpec pp = SetupForExternalTest.phraseFactory.createPrepositionPhrase(
                "in", "the park");

            p.addPostModifier(pp);

            Assert.AreEqual("Mary chases George in the park", SetupForExternalTest.realiser
                            .realise(p).getRealisation());

            // another question from Nicole
            SPhraseSpec run = SetupForExternalTest.phraseFactory.createClause(
                "you", "go", "running");

            run.setFeature(Feature.MODAL.ToString(), "should");
            run.addPreModifier("really");
            SPhraseSpec think = SetupForExternalTest.phraseFactory.createClause("I", "think");

            think.setObject(run);
            run.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true);

            var text = SetupForExternalTest.realiser.realise(think).getRealisation();

            Assert.AreEqual("I think you should really go running", text);
        }
예제 #2
0
        public void dwightTest()
        {
            // Rachel Dwight's test
            SetupForExternalTest.phraseFactory.setLexicon(SetupForExternalTest.lexicon);

            NPPhraseSpec noun4 = SetupForExternalTest.phraseFactory
                                 .createNounPhrase("FGFR3 gene in every cell");

            noun4.setSpecifier("the");

            PPPhraseSpec prep1 = SetupForExternalTest.phraseFactory.createPrepositionPhrase(
                "of", noun4);

            NPPhraseSpec noun1 = SetupForExternalTest.phraseFactory.createNounPhrase(
                "the", "patient's mother");

            NPPhraseSpec noun2 = SetupForExternalTest.phraseFactory.createNounPhrase(
                "the", "patient's father");

            NPPhraseSpec noun3 = SetupForExternalTest.phraseFactory
                                 .createNounPhrase("changed copy");

            noun3.addPreModifier("one");
            noun3.addComplement(prep1);

            var coordNoun1 = new CoordinatedPhraseElement(
                noun1, noun2);

            coordNoun1.setConjunction("or");

            VPPhraseSpec verbPhrase1 = SetupForExternalTest.phraseFactory.createVerbPhrase("have");

            verbPhrase1.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);

            SPhraseSpec sentence1 = SetupForExternalTest.phraseFactory.createClause(coordNoun1,
                                                                                    verbPhrase1, noun3);

            Assert
            .AreEqual(
                "the patient's mother or the patient's father has one changed copy of the FGFR3 gene in every cell",

                SetupForExternalTest.realiser.realise(sentence1).getRealisation());

            // Rachel's second test
            noun3       = SetupForExternalTest.phraseFactory.createNounPhrase("a", "gene test");
            noun2       = SetupForExternalTest.phraseFactory.createNounPhrase("an", "LDL test");
            noun1       = SetupForExternalTest.phraseFactory.createNounPhrase("the", "clinic");
            verbPhrase1 = SetupForExternalTest.phraseFactory.createVerbPhrase("perform");

            var coord1 = new CoordinatedPhraseElement(noun2,
                                                      noun3);

            sentence1 = SetupForExternalTest.phraseFactory.createClause(noun1, verbPhrase1, coord1);
            sentence1.setFeature(Feature.TENSE.ToString(), Tense.PAST);

            Assert
            .AreEqual(
                "the clinic performed an LDL test and a gene test", SetupForExternalTest.realiser
                .realise(sentence1).getRealisation());
        }
예제 #3
0
        public virtual void xmlLexiconImmutabilityTest()
        {
            NLGFactory factory  = new NLGFactory(lexicon);
            Realiser   realiser = new Realiser(lexicon);

            // "wall" is singular.
            NPPhraseSpec wall = factory.createNounPhrase("the", "wall");

            Assert.AreEqual(NumberAgreement.SINGULAR, wall.getFeature(Feature.NUMBER));

            // Realise a sentence with plural form of "wall"
            wall.Plural = true;
            SPhraseSpec sentence = factory.createClause("motion", "observe");

            sentence.setFeature(Feature.TENSE, Tense.PAST);
            PPPhraseSpec pp = factory.createPrepositionPhrase("in", wall);

            sentence.addPostModifier(pp);
            realiser.realiseSentence(sentence);

            // Create a new 'the wall' NP and check to make sure that the syntax processor has
            // not propagated plurality to the canonical XMLLexicon WordElement object.
            wall = factory.createNounPhrase("the", "wall");
            Assert.AreEqual(NumberAgreement.SINGULAR, wall.getFeature(Feature.NUMBER));
        }
예제 #4
0
        public virtual void testSPhraseSpec()
        {
            // simple test of methods
            SPhraseSpec c1 = (SPhraseSpec)phraseFactory.createClause();

            c1.setVerb("give");
            c1.setSubject("John");
            c1.setObject("an apple");
            c1.setIndirectObject("Mary");
            c1.setFeature(Feature.TENSE, Tense.PAST);
            c1.setFeature(Feature.NEGATED, true);

            // check getXXX methods
            Assert.AreEqual("give", getBaseForm(c1.getVerb()));
            Assert.AreEqual("John", getBaseForm(c1.getSubject()));
            Assert.AreEqual("an apple", getBaseForm(c1.getObject()));
            Assert.AreEqual("Mary", getBaseForm(c1.getIndirectObject()));

            Assert.AreEqual("John did not give Mary an apple", realiser.realise(c1).Realisation); //$NON-NLS-1$


            // test modifier placement
            SPhraseSpec c2 = (SPhraseSpec)phraseFactory.createClause();

            c2.setVerb("see");
            c2.setSubject("the man");
            c2.setObject("me");
            c2.addModifier("fortunately");
            c2.addModifier("quickly");
            c2.addModifier("in the park");
            // try setting tense directly as a feature
            c2.setFeature(Feature.TENSE, Tense.PAST);
            Assert.AreEqual("fortunately the man quickly saw me in the park",
                            realiser.realise(c2).Realisation); //$NON-NLS-1$
        }
        public virtual void testCommaSeparatedFrontModifiers()
        {
            NPPhraseSpec subject = phraseFactory.createNounPhrase("I");
            NPPhraseSpec @object = phraseFactory.createNounPhrase("a bag");

            SPhraseSpec _s1 = phraseFactory.createClause(subject, "carry", @object);


            // add a PP complement
            PPPhraseSpec pp1 =
                phraseFactory.createPrepositionPhrase("on", phraseFactory.createNounPhrase("most", "Tuesdays"));

            _s1.addFrontModifier(pp1);

            PPPhraseSpec pp2 = phraseFactory.createPrepositionPhrase("since", phraseFactory.createNounPhrase("1991"));

            _s1.addFrontModifier(pp2);
            pp1.setFeature(Feature.APPOSITIVE, true);
            pp2.setFeature(Feature.APPOSITIVE, true);

            //without setCommaSepCuephrase
            Assert.AreEqual("on most Tuesdays since 1991 I carry a bag", realiser.realise(_s1).Realisation);


            //with setCommaSepCuephrase
            realiser.CommaSepCuephrase = true;
            Assert.AreEqual("on most Tuesdays, since 1991, I carry a bag", realiser.realise(_s1).Realisation);
        }
        public virtual void testNoDoubledCommas()
        {
            NPPhraseSpec subject = phraseFactory.createNounPhrase("I");
            NPPhraseSpec @object = phraseFactory.createNounPhrase("a bag");

            SPhraseSpec _s1 = phraseFactory.createClause(subject, "carry", @object);

            PPPhraseSpec pp1 =
                phraseFactory.createPrepositionPhrase("on", phraseFactory.createNounPhrase("most", "Tuesdays"));

            _s1.addFrontModifier(pp1);

            PPPhraseSpec pp2 = phraseFactory.createPrepositionPhrase("since", phraseFactory.createNounPhrase("1991"));
            PPPhraseSpec pp3 =
                phraseFactory.createPrepositionPhrase("except", phraseFactory.createNounPhrase("yesterday"));

            pp2.setFeature(Feature.APPOSITIVE, true);
            pp3.setFeature(Feature.APPOSITIVE, true);

            pp1.addPostModifier(pp2);
            pp1.addPostModifier(pp3);

            realiser.CommaSepCuephrase = true;

            Assert.AreEqual("on most Tuesdays, since 1991, except yesterday, I carry a bag",
                            realiser.realise(_s1).Realisation);

            // without my fix (that we're testing here), you'd end up with
            // "on most Tuesdays, since 1991,, except yesterday, I carry a bag"
        }
예제 #7
0
        public virtual void testPassiveWithPPMod()
        {
            // passive with just complement
            NPPhraseSpec subject = phraseFactory.createNounPhrase("wave");

            subject.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
            NPPhraseSpec @object = phraseFactory.createNounPhrase("surfer");

            @object.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);

            SPhraseSpec
                _s1 = phraseFactory.createClause(subject, "carry", @object); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$


            // add a PP complement
            PPPhraseSpec pp =
                phraseFactory.createPrepositionPhrase("to", phraseFactory.createNounPhrase("the", "shore"));

            _s1.addPostModifier(pp);

            _s1.setFeature(Feature.PASSIVE, true);

            Assert.AreEqual("surfers are carried to the shore by waves",
                            realiser.realise(_s1).Realisation); //$NON-NLS-1$
        }
예제 #8
0
        public virtual void testCuePhrase()
        {
            NPPhraseSpec subject = phraseFactory.createNounPhrase("wave");

            subject.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
            NPPhraseSpec @object = phraseFactory.createNounPhrase("surfer");

            @object.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);

            SPhraseSpec
                _s1 = phraseFactory.createClause(subject, "carry", @object); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$


            // add a PP complement
            PPPhraseSpec pp =
                phraseFactory.createPrepositionPhrase("to", phraseFactory.createNounPhrase("the", "shore"));

            _s1.addPostModifier(pp);

            _s1.setFeature(Feature.PASSIVE, true);

            _s1.addFrontModifier("however");


            //without comma separation of cue phrase
            Assert.AreEqual("however surfers are carried to the shore by waves",
                            realiser.realise(_s1).Realisation); //$NON-NLS-1$


            realiser.CommaSepCuephrase = true;
            Assert.AreEqual("however, surfers are carried to the shore by waves",
                            realiser.realise(_s1).Realisation); //$NON-NLS-1$
        }
예제 #9
0
        public virtual void testComplexSentence3()
        {
            setUp();

            s1 = phraseFactory.createClause();
            s1.setSubject(woman);
            s1.setVerb("kiss");
            s1.setObject(man);

            PhraseElement _man = phraseFactory.createNounPhrase("the", "man"); //$NON-NLS-1$ //$NON-NLS-2$

            s3 = phraseFactory.createClause();
            s3.setSubject(_man);
            s3.setVerb("give");

            NPPhraseSpec flower = phraseFactory.createNounPhrase("flower"); //$NON-NLS-1$
            NPPhraseSpec john   = phraseFactory.createNounPhrase("John");   //$NON-NLS-1$

            john.setFeature(Feature.POSSESSIVE, true);
            flower.setSpecifier(john);
            s3.setObject(flower);

            PhraseElement _woman = phraseFactory.createNounPhrase("the", "woman"); //$NON-NLS-1$ //$NON-NLS-2$

            s3.setIndirectObject(_woman);

            // the coordinate sentence allows us to raise and lower complementiser
            CoordinatedPhraseElement coord2 = new CoordinatedPhraseElement(s1, s3);

            coord2.setFeature(Feature.TENSE, Tense.PAST);

            realiser.DebugMode = true;
            Assert.AreEqual("the woman kissed the man and the man gave the woman John's flower",
                            realiser.realise(coord2).Realisation); //$NON-NLS-1$
        }
예제 #10
0
        public virtual void testPassiveWithPPCompl()
        {
            // passive with just complement
            NPPhraseSpec subject = phraseFactory.createNounPhrase("wave");

            subject.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
            NPPhraseSpec @object = phraseFactory.createNounPhrase("surfer");

            @object.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);

            SPhraseSpec
                _s1 = phraseFactory.createClause(subject, "carry", @object); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$


            // add a PP complement
            PPPhraseSpec pp =
                phraseFactory.createPrepositionPhrase("to", phraseFactory.createNounPhrase("the", "shore"));

            pp.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.INDIRECT_OBJECT);
            _s1.addComplement(pp);

            _s1.setFeature(Feature.PASSIVE, true);

            Assert.AreEqual("surfers are carried to the shore by waves",
                            realiser.realise(_s1).Realisation); //$NON-NLS-1$
        }
예제 #11
0
        public virtual void section14_Test()
        {
            Lexicon    lexicon    = Lexicon.DefaultLexicon;  // default simplenlg lexicon
            NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon

            Realiser realiser = new Realiser(lexicon);

            SPhraseSpec p1 = nlgFactory.createClause("Mary", "chase", "the monkey");
            SPhraseSpec p2 = nlgFactory.createClause("The monkey", "fight back");
            SPhraseSpec p3 = nlgFactory.createClause("Mary", "be", "nervous");

            DocumentElement s1 = nlgFactory.createSentence(p1);
            DocumentElement s2 = nlgFactory.createSentence(p2);
            DocumentElement s3 = nlgFactory.createSentence(p3);

            DocumentElement par1 = nlgFactory.createParagraph(new List <DocumentElement> {
                s1, s2, s3
            });

            string output14a = realiser.realise(par1).Realisation;

            Assert.AreEqual("Mary chases the monkey. The monkey fights back. Mary is nervous.\n\n", output14a);

            DocumentElement section = nlgFactory.createSection("The Trials and Tribulation of Mary and the Monkey");

            section.addComponent(par1);
            string output14b = realiser.realise(section).Realisation;

            Assert.AreEqual(
                "The Trials and Tribulation of Mary and the Monkey\nMary chases the monkey. The monkey fights back. Mary is nervous.\n\n",
                output14b);
        }
예제 #12
0
        public virtual void section13_Test()
        {
            Lexicon    lexicon    = Lexicon.DefaultLexicon;  // default simplenlg lexicon
            NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon

            Realiser realiser = new Realiser(lexicon);

            SPhraseSpec s1 = nlgFactory.createClause("my cat", "like", "fish");
            SPhraseSpec s2 = nlgFactory.createClause("my dog", "like", "big bones");
            SPhraseSpec s3 = nlgFactory.createClause("my horse", "like", "grass");

            CoordinatedPhraseElement c = nlgFactory.createCoordinatedPhrase();

            c.addCoordinate(s1);
            c.addCoordinate(s2);
            c.addCoordinate(s3);

            string outputA = realiser.realiseSentence(c);

            Assert.AreEqual("My cat likes fish, my dog likes big bones and my horse likes grass.", outputA);

            SPhraseSpec p = nlgFactory.createClause("I", "be", "happy");
            SPhraseSpec q = nlgFactory.createClause("I", "eat", "fish");

            q.setFeature(Feature.COMPLEMENTISER, "because");
            q.setFeature(Feature.TENSE, Tense.PAST);
            p.addComplement(q);

            string outputB = realiser.realiseSentence(p);

            Assert.AreEqual("I am happy because I ate fish.", outputB);
        }
예제 #13
0
        public virtual void section8_Test()
        {
            Lexicon    lexicon    = Lexicon.DefaultLexicon;  // default simplenlg lexicon
            NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
            Realiser   realiser   = new Realiser(lexicon);

            NPPhraseSpec subject = nlgFactory.createNounPhrase("Mary");
            NPPhraseSpec @object = nlgFactory.createNounPhrase("the monkey");
            VPPhraseSpec verb    = nlgFactory.createVerbPhrase("chase");

            subject.addModifier("fast");

            SPhraseSpec p = nlgFactory.createClause();

            p.setSubject(subject);
            p.setVerb(verb);
            p.setObject(@object);

            string outputA = realiser.realiseSentence(p);

            Assert.AreEqual("Fast Mary chases the monkey.", outputA);

            verb.addModifier("quickly");

            string outputB = realiser.realiseSentence(p);

            Assert.AreEqual("Fast Mary quickly chases the monkey.", outputB);
        }
예제 #14
0
 public override void tearDown()
 {
     base.tearDown();
     p1 = null;
     p2 = null;
     p3 = null;
 }
예제 #15
0
        public void testNegatedQuestions()
        {
            setUp();
            this.phraseFactory.setLexicon(this.lexicon);
            this.realiser.setLexicon(this.lexicon);

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

            // sentence: however, tomorrow, Jane and Andrew will not pick up the
            // balls in the shop
            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.NEGATED.ToString(), true);
            s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
            s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
            Assert.AreEqual(
                "however, will Jane and Andrew not pick up the balls in the shop tomorrow",
                this.realiser.realise(s4).getRealisation());
        }
예제 #16
0
 public override void setUp()
 {
     base.setUp();
     p1 = phraseFactory.createClause("you", "be", "happy");
     p2 = phraseFactory.createClause("I", "be", "sad");
     p3 = phraseFactory.createClause("they", "be", "nervous");
 }
예제 #17
0
        public virtual void novelliTest()
        {
            PhraseElement
                p = phraseFactory.createClause("Mary", "chase", "George");              //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

            PhraseElement pp = phraseFactory.createPrepositionPhrase("in", "the park"); //$NON-NLS-1$ //$NON-NLS-2$

            p.addPostModifier(pp);

            Assert.AreEqual("Mary chases George in the park", realiser.realise(p).Realisation); //$NON-NLS-1$


            SPhraseSpec
                run = phraseFactory.createClause("you", "go", "running"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

            run.setFeature(Feature.MODAL, "should");                      //$NON-NLS-1$
            run.addPreModifier("really");                                 //$NON-NLS-1$
            SPhraseSpec think = phraseFactory.createClause("I", "think"); //$NON-NLS-1$ //$NON-NLS-2$

            think.setObject(run);
            run.setFeature(Feature.SUPRESSED_COMPLEMENTISER, true);

            string text = realiser.realise(think).Realisation;

            Assert.AreEqual("I think you should really go running", text); //$NON-NLS-1$
        }
예제 #18
0
        /**
         * Creates a clause with the given subject, verb or verb phrase and direct
         * object but no indirect object.
         *
         * @param subject
         *            the subject for the clause as a <code>NLGElement</code> or
         *            <code>String</code>. This forms a noun phrase.
         * @param verb
         *            the verb for the clause as a <code>NLGElement</code> or
         *            <code>String</code>. This forms a verb phrase.
         * @param directObject
         *            the direct object for the clause as a <code>NLGElement</code>
         *            or <code>String</code>. This forms a complement for the
         *            clause.
         * @return a <code>SPhraseSpec</code> representing this phrase.
         */
        public virtual SPhraseSpec createClause(object subject, object verb, object directObject)
        {
            SPhraseSpec phraseElement = new SPhraseSpec(this);

            if (verb != null)
            {
                // AG: fix here: check if "verb" is a VPPhraseSpec or a Verb
                if (verb is PhraseElement)
                {
                    phraseElement.VerbPhrase = (PhraseElement)verb;
                }
                else
                {
                    phraseElement.setVerb(verb);
                }
            }

            if (subject != null)
            {
                phraseElement.setSubject(subject);
            }

            if (directObject != null)
            {
                phraseElement.setObject(directObject);
            }

            return(phraseElement);
        }
예제 #19
0
        public virtual void testComplementiserPassivePerfectFeatures_PastTense()
        {
            setUp();
            realiser.Lexicon = lexicon;

            PhraseElement inner = phraseFactory.createClause("I", "play", "poker");

            inner.setFeature(Feature.TENSE, Tense.PAST);
            inner.setFeature(Feature.COMPLEMENTISER, "where");

            PhraseElement house = phraseFactory.createNounPhrase("the", "house");

            house.addComplement(inner);

            SPhraseSpec outer = phraseFactory.createClause(null, "abandon", house);

            outer.addPostModifier("since 1986");

            outer.setFeature(Feature.PASSIVE, true);
            outer.setFeature(Feature.PERFECT, true);

            DocumentElement sentence = docFactory.createSentence(outer);
            NLGElement      realised = realiser.realise(sentence);

            // Retrieve the realisation and dump it to the console
            Assert.AreEqual("The house where I played poker has been abandoned since 1986.", realised.Realisation);
        }
예제 #20
0
        public virtual void testFutureTense()
        {
            SPhraseSpec test = phraseFactory.createClause();

            NPPhraseSpec subj = phraseFactory.createNounPhrase("I");

            VPPhraseSpec verb = phraseFactory.createVerbPhrase("go");

            AdvPhraseSpec adverb = phraseFactory.createAdverbPhrase("tomorrow");

            test.setSubject(subj);
            test.VerbPhrase = verb;
            test.setFeature(Feature.TENSE, Tense.FUTURE);
            test.addPostModifier(adverb);
            string sentence = realiser.realiseSentence(test);

            Assert.AreEqual("I will go tomorrow.", sentence);

            SPhraseSpec test2 = phraseFactory.createClause();
            NLGElement  vb    =
                phraseFactory.createWord("go", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB));

            test2.setSubject(subj);
            test2.setVerb(vb);
            test2.setFeature(Feature.TENSE, Tense.FUTURE);
            test2.addPostModifier(adverb);
            string sentence2 = realiser.realiseSentence(test);

            Assert.AreEqual("I will go tomorrow.", sentence2);
        }
예제 #21
0
        public virtual void testAuxWHObjectQuestion()
        {
            SPhraseSpec p = phraseFactory.createClause(dog, "upset", man);


            // first without any aux
            p.setFeature(Feature.TENSE, Tense.PAST);
            p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
            Assert.AreEqual("what did the dog upset", realiser.realise(p).Realisation);

            p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
            Assert.AreEqual("who did the dog upset", realiser.realise(p).Realisation);

            p.setFeature(Feature.TENSE, Tense.PRESENT);
            p.setFeature(Feature.PERFECT, true);

            p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
            Assert.AreEqual("who has the dog upset", realiser.realise(p).Realisation);

            p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
            Assert.AreEqual("what has the dog upset", realiser.realise(p).Realisation);

            p.setFeature(Feature.TENSE, Tense.FUTURE);
            p.setFeature(Feature.PERFECT, true);

            p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
            Assert.AreEqual("who will the dog have upset", realiser.realise(p).Realisation);

            p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
            Assert.AreEqual("what will the dog have upset", realiser.realise(p).Realisation);
        }
예제 #22
0
        public virtual void testBeQuestionsPast()
        {
            SPhraseSpec p = phraseFactory.createClause(phraseFactory.createNounPhrase("a", "ball"),
                                                       phraseFactory.createWord("be", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)),
                                                       phraseFactory.createNounPhrase("a", "toy"));

            p.setFeature(Feature.TENSE, Tense.PAST);

            p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
            Assert.AreEqual("what was a ball", realiser.realise(p).Realisation);

            p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
            Assert.AreEqual("was a ball a toy", realiser.realise(p).Realisation);

            p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
            Assert.AreEqual("what was a toy", realiser.realise(p).Realisation);

            SPhraseSpec p2 = phraseFactory.createClause("Mary", "be", "beautiful");

            p2.setFeature(Feature.TENSE, Tense.PAST);
            p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
            Assert.AreEqual("why was Mary beautiful", realiser.realise(p2).Realisation);

            p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHERE);
            Assert.AreEqual("where was Mary beautiful", realiser.realise(p2).Realisation);

            p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
            Assert.AreEqual("who was beautiful", realiser.realise(p2).Realisation);
        }
예제 #23
0
        public virtual void testModalWHSubjectQuestion()
        {
            SPhraseSpec p = phraseFactory.createClause(dog, "upset", man);

            p.setFeature(Feature.TENSE, Tense.PAST);
            Assert.AreEqual("the dog upset the man", realiser.realise(p).Realisation);


            // first without modal
            p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
            Assert.AreEqual("who upset the man", realiser.realise(p).Realisation);

            p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
            Assert.AreEqual("what upset the man", realiser.realise(p).Realisation);


            // now with modal auxiliary
            p.setFeature(Feature.MODAL, "may");

            p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
            Assert.AreEqual("who may have upset the man", realiser.realise(p).Realisation);

            p.setFeature(Feature.TENSE, Tense.FUTURE);
            Assert.AreEqual("who may upset the man", realiser.realise(p).Realisation);

            p.setFeature(Feature.TENSE, Tense.PAST);
            p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
            Assert.AreEqual("what may have upset the man", realiser.realise(p).Realisation);

            p.setFeature(Feature.TENSE, Tense.FUTURE);
            Assert.AreEqual("what may upset the man", realiser.realise(p).Realisation);
        }
예제 #24
0
        public virtual void testNegatedQuestions()
        {
            setUp();
            phraseFactory.Lexicon = lexicon;
            realiser.Lexicon      = lexicon;

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


            // sentence: however, tomorrow, Jane and Andrew will not pick up the
            // balls in the shop
            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.NEGATED, true);
            s4.setFeature(Feature.TENSE, Tense.FUTURE);
            s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
            Assert.AreEqual("however, will Jane and Andrew not pick up the balls in the shop tomorrow",
                            realiser.realise(s4).Realisation); //$NON-NLS-1$
        }
예제 #25
0
        public void forcherTest()
        {
            // Bjorn Forcher's tests
            SetupForExternalTest.phraseFactory.setLexicon(SetupForExternalTest.lexicon);
            SPhraseSpec s1 = SetupForExternalTest.phraseFactory.createClause(null, "associate", "Marie");

            s1.setFeature(Feature.PASSIVE.ToString(), true);
            PPPhraseSpec pp1 = SetupForExternalTest.phraseFactory.createPrepositionPhrase("with");

            pp1.addComplement("Peter");
            pp1.addComplement("Paul");
            s1.addPostModifier(pp1);


            SetupForExternalTest.realiser.setDebugMode(true);
            var r = SetupForExternalTest.realiser.realise(s1).getRealisation();

            Assert.AreEqual("Marie is associated with Peter and Paul", r);


            SPhraseSpec s2 = SetupForExternalTest.phraseFactory.createClause();

            s2.setSubject((NPPhraseSpec)SetupForExternalTest.phraseFactory.createNounPhrase("Peter"));
            s2.setVerb("have");
            s2.setObject("something to do");
            s2.addPostModifier((PPPhraseSpec)SetupForExternalTest.phraseFactory.createPrepositionPhrase(
                                   "with", "Paul"));


            Assert.AreEqual("Peter has something to do with Paul",
                            SetupForExternalTest.realiser.realise(s2).getRealisation());
        }
예제 #26
0
        public void data2TextTest()
        {
            // Data2Text tests
            // test OK to have number at end of sentence
            SPhraseSpec p = SetupForExternalTest.phraseFactory.createClause("the dog", "weigh", "12");

            Assert.AreEqual("The dog weighs 12.", SetupForExternalTest.realiser.realiseSentence(p));

            // test OK to have "there be" sentence with "there" as a StringElement
            var dataDropout2 = SetupForExternalTest.phraseFactory.createNLGElement("data dropouts");

            dataDropout2.setPlural(true);
            var sentence2 = SetupForExternalTest.phraseFactory.createClause();

            sentence2.setSubject(SetupForExternalTest.phraseFactory.createStringElement("there"));
            sentence2.setVerb("be");
            sentence2.setObject(dataDropout2);
            Assert.AreEqual("There are data dropouts.", SetupForExternalTest.realiser.realiseSentence(sentence2));

            // test OK to have gerund form verb
            SPhraseSpec weather1 = SetupForExternalTest.phraseFactory.createClause("SE 10-15", "veer", "S 15-20");

            weather1.setFeature(Feature.FORM.ToString(), Form.GERUND);
            Assert.AreEqual("SE 10-15 veering S 15-20.", SetupForExternalTest.realiser.realiseSentence(weather1));

            // test OK to have subject only
            SPhraseSpec weather2 = SetupForExternalTest.phraseFactory.createClause("cloudy and misty", "be", "XXX");

            weather2.getVerbPhrase().setFeature(Feature.ELIDED.ToString(), true);
            Assert.AreEqual("Cloudy and misty.", SetupForExternalTest.realiser.realiseSentence(weather2));

            // test OK to have VP only
            SPhraseSpec weather3 = SetupForExternalTest.phraseFactory.createClause("S 15-20", "increase", "20-25");

            weather3.setFeature(Feature.FORM.ToString(), Form.GERUND);
            weather3.getSubject().setFeature(Feature.ELIDED.ToString(), true);
            Assert.AreEqual("Increasing 20-25.", SetupForExternalTest.realiser.realiseSentence(weather3));

            // conjoined test
            SPhraseSpec weather4 = SetupForExternalTest.phraseFactory.createClause("S 20-25", "back", "SSE");

            weather4.setFeature(Feature.FORM.ToString(), Form.GERUND);
            weather4.getSubject().setFeature(Feature.ELIDED.ToString(), true);

            var coord = new CoordinatedPhraseElement();

            coord.addCoordinate(weather1);
            coord.addCoordinate(weather3);
            coord.addCoordinate(weather4);
            coord.setConjunction("then");
            Assert.AreEqual("SE 10-15 veering S 15-20, increasing 20-25 then backing SSE.",
                            SetupForExternalTest.realiser.realiseSentence(coord));


            // no verb
            SPhraseSpec weather5 = SetupForExternalTest.phraseFactory.createClause("rain", null, "likely");

            Assert.AreEqual("Rain likely.", SetupForExternalTest.realiser.realiseSentence(weather5));
        }
예제 #27
0
        public virtual void leanTest()
        {
            SPhraseSpec sentence = phraseFactory.createClause();

            sentence.setVerb("be");
            sentence.setObject("a ball");
            sentence.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
            Assert.AreEqual("What is a ball?", realiser.realiseSentence(sentence));

            sentence = phraseFactory.createClause();
            sentence.setVerb("be");
            NPPhraseSpec @object = phraseFactory.createNounPhrase("example");

            @object.Plural = true;
            @object.addModifier("of jobs");
            sentence.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
            sentence.setObject(@object);
            Assert.AreEqual("What are examples of jobs?", realiser.realiseSentence(sentence));

            SPhraseSpec  p    = phraseFactory.createClause();
            NPPhraseSpec sub1 = phraseFactory.createNounPhrase("Mary");

            sub1.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
            sub1.setFeature(Feature.PRONOMINAL, true);
            sub1.setFeature(Feature.PERSON, Person.FIRST);
            p.setSubject(sub1);
            p.setVerb("chase");
            p.setObject("the monkey");


            string output2 = realiser.realiseSentence(p); // Realiser created earlier.

            Assert.AreEqual("I chase the monkey.", output2);

            SPhraseSpec  test    = phraseFactory.createClause();
            NPPhraseSpec subject = phraseFactory.createNounPhrase("Mary");

            subject.setFeature(Feature.PRONOMINAL, true);
            subject.setFeature(Feature.PERSON, Person.SECOND);
            test.setSubject(subject);
            test.setVerb("cry");

            test.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
            test.setFeature(Feature.TENSE, Tense.PRESENT);
            Assert.AreEqual("Why do you cry?", realiser.realiseSentence(test));

            test    = phraseFactory.createClause();
            subject = phraseFactory.createNounPhrase("Mary");

            subject.setFeature(Feature.PRONOMINAL, true);
            subject.setFeature(Feature.PERSON, Person.SECOND);
            test.setSubject(subject);
            test.setVerb("be");
            test.setObject("crying");

            test.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
            test.setFeature(Feature.TENSE, Tense.PRESENT);
            Assert.AreEqual("Why are you crying?", realiser.realiseSentence(test));
        }
예제 #28
0
        public virtual void stringElementAsVPTest()
        {
            SPhraseSpec s = phraseFactory.createClause();

            s.VerbPhrase = phraseFactory.createStringElement("eats and drinks");
            s.setSubject(phraseFactory.createStringElement("the big fat man"));
            Assert.AreEqual("the big fat man eats and drinks", realiser.realise(s).Realisation);
        }
예제 #29
0
        public void testDidNot()
        {
            SPhraseSpec o = this.phraseFactory.createClause("John", "eat");

            o.setFeature(Feature.TENSE.ToString(), Tense.PAST);
            o.setFeature(Feature.NEGATED.ToString(), true);
            this.realiser.setLexicon(this.lexicon);
            Assert.AreEqual("John did not eat", this.realiser.realise(o).getRealisation());
        }
예제 #30
0
 public void tearDown()
 {
     s1 = null;
     s2 = null;
     s3 = null;
     s4 = null;
     s5 = null;
     s6 = null;
 }