Exemplo n.º 1
0
        public void multipleNLGElementListRealiserTest()
        {
            List <INLGElement> elements = new List <INLGElement>();
            // Create test NLGElements to realize:

            // "The cat jumping on the counter."
            DocumentElement sentence1 = SetupForRealiserTest.phraseFactory.createSentence();
            NPPhraseSpec    subject_1 = SetupForRealiserTest.phraseFactory.createNounPhrase("the", "cat");
            VPPhraseSpec    verb_1    = SetupForRealiserTest.phraseFactory.createVerbPhrase("jump");

            verb_1.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE);
            PPPhraseSpec prep_1   = SetupForRealiserTest.phraseFactory.createPrepositionPhrase();
            NPPhraseSpec object_1 = SetupForRealiserTest.phraseFactory.createNounPhrase();

            object_1.setDeterminer("the");
            object_1.setNoun("counter");
            prep_1.addComplement(object_1);
            prep_1.setPreposition("on");
            SPhraseSpec clause_1 = SetupForRealiserTest.phraseFactory.createClause();

            clause_1.setSubject(subject_1);
            clause_1.setVerbPhrase(verb_1);
            clause_1.setObject(prep_1);
            sentence1.addComponent(clause_1);

            // "The dog running on the counter."
            DocumentElement sentence2 = SetupForRealiserTest.phraseFactory.createSentence();
            NPPhraseSpec    subject_2 = SetupForRealiserTest.phraseFactory.createNounPhrase("the", "dog");
            VPPhraseSpec    verb_2    = SetupForRealiserTest.phraseFactory.createVerbPhrase("run");

            verb_2.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE);
            PPPhraseSpec prep_2   = SetupForRealiserTest.phraseFactory.createPrepositionPhrase();
            NPPhraseSpec object_2 = SetupForRealiserTest.phraseFactory.createNounPhrase();

            object_2.setDeterminer("the");
            object_2.setNoun("counter");
            prep_2.addComplement(object_2);
            prep_2.setPreposition("on");
            SPhraseSpec clause_2 = SetupForRealiserTest.phraseFactory.createClause();

            clause_2.setSubject(subject_2);
            clause_2.setVerbPhrase(verb_2);
            clause_2.setObject(prep_2);
            sentence2.addComponent(clause_2);


            elements.add(sentence1);
            elements.add(sentence2);

            List <INLGElement> realisedElements = SetupForRealiserTest.realiser.realise(elements);

            Assert.IsNotNull(realisedElements);
            Assert.AreEqual(2, realisedElements.size());
            Assert.AreEqual("The cat jumping on the counter.", realisedElements.get(0).getRealisation());
            Assert.AreEqual("The dog running on the counter.", realisedElements.get(1).getRealisation());
        }
Exemplo n.º 2
0
        public virtual void multipleNLGElementListRealiserTest()
        {
            List <NLGElement> elements = new List <NLGElement>();
            // Create test NLGElements to realize:

            // "The cat jumping on the counter."
            DocumentElement sentence1 = nlgFactory.createSentence();
            NPPhraseSpec    subject_1 = nlgFactory.createNounPhrase("the", "cat");
            VPPhraseSpec    verb_1    = nlgFactory.createVerbPhrase("jump");

            verb_1.setFeature(Feature.FORM, Form.PRESENT_PARTICIPLE);
            PPPhraseSpec prep_1   = nlgFactory.createPrepositionPhrase();
            NPPhraseSpec object_1 = nlgFactory.createNounPhrase();

            object_1.setDeterminer("the");
            object_1.setNoun("counter");
            prep_1.addComplement(object_1);
            prep_1.setPreposition("on");
            SPhraseSpec clause_1 = nlgFactory.createClause();

            clause_1.setSubject(subject_1);
            clause_1.VerbPhrase = verb_1;
            clause_1.setObject(prep_1);
            sentence1.addComponent(clause_1);

            // "The dog running on the counter."
            DocumentElement sentence2 = nlgFactory.createSentence();
            NPPhraseSpec    subject_2 = nlgFactory.createNounPhrase("the", "dog");
            VPPhraseSpec    verb_2    = nlgFactory.createVerbPhrase("run");

            verb_2.setFeature(Feature.FORM, Form.PRESENT_PARTICIPLE);
            PPPhraseSpec prep_2   = nlgFactory.createPrepositionPhrase();
            NPPhraseSpec object_2 = nlgFactory.createNounPhrase();

            object_2.setDeterminer("the");
            object_2.setNoun("counter");
            prep_2.addComplement(object_2);
            prep_2.setPreposition("on");
            SPhraseSpec clause_2 = nlgFactory.createClause();

            clause_2.setSubject(subject_2);
            clause_2.VerbPhrase = verb_2;
            clause_2.setObject(prep_2);
            sentence2.addComponent(clause_2);


            elements.Add(sentence1);
            elements.Add(sentence2);

            IList <NLGElement> realisedElements = realiser.realise(elements);

            Assert.IsNotNull(realisedElements);
            Assert.AreEqual(2, realisedElements.Count);
            Assert.AreEqual("The cat jumping on the counter.", realisedElements[0].Realisation);
            Assert.AreEqual("The dog running on the counter.", realisedElements[1].Realisation);
        }
Exemplo n.º 3
0
        public virtual void testPluralTheseDeterminerNPObject()
        {
            SPhraseSpec sentence_1 = phraseFactory.createClause();

            NPPhraseSpec nounPhrase_1 = phraseFactory.createNounPhrase("monkey");

            nounPhrase_1.Plural = true;
            nounPhrase_1.setDeterminer("these");
            sentence_1.setObject(nounPhrase_1);

            Assert.AreEqual("These monkeys.", realiser.realiseSentence(sentence_1));
        }
Exemplo n.º 4
0
        public virtual void NPIndefiniteArticleInflectionVowelTest()
        {
            SPhraseSpec senSpec = phraseFactory.createClause();

            senSpec.addComplement(phraseFactory.createStringElement("I see"));
            NPPhraseSpec firstNoun = phraseFactory.createNounPhrase("elephant");

            firstNoun.setDeterminer("a");
            senSpec.addComplement(firstNoun);
            DocumentElement completeSen = phraseFactory.createSentence();

            completeSen.addComponent(senSpec);
            Assert.AreEqual("I see an elephant.", realiser.realise(completeSen).Realisation);
        }
Exemplo n.º 5
0
        public virtual void frontNPStringElementTest()
        {
            SPhraseSpec  senSpec = phraseFactory.createClause();
            NPPhraseSpec np      = phraseFactory.createNounPhrase();

            np.setHead("cat");
            np.setDeterminer("the");
            senSpec.addComplement(np);
            senSpec.addComplement(phraseFactory.createStringElement("loves a dog"));
            DocumentElement completeSen = phraseFactory.createSentence();

            completeSen.addComponent(senSpec);
            Assert.AreEqual("The cat loves a dog.", realiser.realise(completeSen).Realisation);
        }
Exemplo n.º 6
0
        public virtual void NPIndefiniteArticleInflectionConsonantTest()
        {
            SPhraseSpec senSpec = phraseFactory.createClause();

            senSpec.addComplement(phraseFactory.createStringElement("I see"));
            NPPhraseSpec firstNoun = phraseFactory.createNounPhrase("cow");

            firstNoun.setDeterminer("an");
            senSpec.addComplement(firstNoun);
            DocumentElement completeSen = phraseFactory.createSentence();

            completeSen.addComponent(senSpec);
            // Do not attempt "an" -> "a"
            Assert.AreEqual("I see an cow.", realiser.realise(completeSen).Realisation);
        }
Exemplo n.º 7
0
        public virtual void testPluralThisDeterminerNPObject_NIHDBLexicon()
        {
            lexicon       = new NIHDBLexicon(DB_FILENAME, LEXICON_TYPE);
            phraseFactory = new NLGFactory(lexicon);
            realiser      = new Realiser(lexicon);

            SPhraseSpec sentence_1 = phraseFactory.createClause();

            NPPhraseSpec nounPhrase_1 = phraseFactory.createNounPhrase("monkey");

            nounPhrase_1.Plural = true;
            nounPhrase_1.setDeterminer("this");
            sentence_1.setObject(nounPhrase_1);

            Assert.AreEqual("These monkeys.", realiser.realiseSentence(sentence_1));
        }
Exemplo n.º 8
0
        public virtual void mulitpleNPElementsTest()
        {
            SPhraseSpec  senSpec   = phraseFactory.createClause();
            NPPhraseSpec frontNoun = phraseFactory.createNounPhrase();

            frontNoun.setHead("john");
            senSpec.addComplement(frontNoun);
            senSpec.addComplement(phraseFactory.createStringElement("is a trier"));
            NPPhraseSpec backNoun = phraseFactory.createNounPhrase();

            backNoun.setDeterminer("for");
            backNoun.setNoun("cheese");
            senSpec.addComplement(backNoun);
            DocumentElement completeSen = phraseFactory.createSentence();

            completeSen.addComponent(senSpec);
            Assert.AreEqual("John is a trier for cheese.", realiser.realise(completeSen).Realisation);
        }
Exemplo n.º 9
0
        public virtual void middleAbbreviationTest()
        {
            SPhraseSpec  senSpec   = phraseFactory.createClause();
            NPPhraseSpec firstNoun = phraseFactory.createNounPhrase();

            firstNoun.setNoun("yahya");
            senSpec.addComplement(firstNoun);
            senSpec.addComplement(phraseFactory.createStringElement("and friends etc. went to"));
            NPPhraseSpec secondNoun = phraseFactory.createNounPhrase();

            secondNoun.setDeterminer("the");
            secondNoun.setNoun("park");
            senSpec.addComplement(secondNoun);
            senSpec.addComplement("to play");
            DocumentElement completeSen = phraseFactory.createSentence();

            completeSen.addComponent(senSpec);
            Assert.AreEqual("Yahya and friends etc. went to the park to play.",
                            realiser.realise(completeSen).Realisation);
        }
Exemplo n.º 10
0
        public virtual void whiteSpaceNPTest()
        {
            SPhraseSpec  senSpec   = phraseFactory.createClause();
            NPPhraseSpec firstNoun = phraseFactory.createNounPhrase();

            firstNoun.setDeterminer("the");
            firstNoun.setNoun("Nasdaq");
            senSpec.addComplement(firstNoun);
            senSpec.addComplement(phraseFactory.createStringElement(" rose steadily during "));
            NPPhraseSpec secondNoun = phraseFactory.createNounPhrase();

            secondNoun.setSpecifier("early");
            secondNoun.setNoun("trading");
            senSpec.addComplement(secondNoun);
            senSpec.addComplement(phraseFactory.createStringElement(" , however it plummeted due to"));
            NPPhraseSpec thirdNoun = phraseFactory.createNounPhrase();

            thirdNoun.setSpecifier("a");
            thirdNoun.setNoun("shock");
            senSpec.addComplement(thirdNoun);
            senSpec.addComplement(phraseFactory.createStringElement(" after "));
            NPPhraseSpec fourthNoun = phraseFactory.createNounPhrase();

            fourthNoun.setNoun("IBM");
            senSpec.addComplement(fourthNoun);
            senSpec.addComplement(phraseFactory.createStringElement("announced poor    "));
            NPPhraseSpec fifthNoun = phraseFactory.createNounPhrase();

            fifthNoun.setSpecifier("first quarter");
            fifthNoun.setNoun("results");
            fifthNoun.Plural = true;
            senSpec.addComplement(fifthNoun);
            DocumentElement completeSen = phraseFactory.createSentence();

            completeSen.addComponent(senSpec);
            Assert.AreEqual(
                "The Nasdaq rose steadily during early trading, however it plummeted due to a shock after IBM announced poor first quarter results.",
                realiser.realise(completeSen).Realisation);
        }
Exemplo n.º 11
0
        public virtual void section11_Test()
        {
            Lexicon    lexicon    = Lexicon.DefaultLexicon;  // default simplenlg lexicon
            NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon

            Realiser realiser = new Realiser(lexicon);

            SPhraseSpec pA = nlgFactory.createClause("Mary", "chase", "the monkey");

            pA.addComplement("in the park");

            string outputA = realiser.realiseSentence(pA);

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

            // alternative build paradigm
            NPPhraseSpec place = nlgFactory.createNounPhrase("park");
            SPhraseSpec  pB    = nlgFactory.createClause("Mary", "chase", "the monkey");

            // next line is depreciated ~ may be corrected in the API
            place.setDeterminer("the");
            PPPhraseSpec pp = nlgFactory.createPrepositionPhrase();

            pp.addComplement(place);
            pp.setPreposition("in");

            pB.addComplement(pp);

            string outputB = realiser.realiseSentence(pB);

            Assert.AreEqual("Mary chases the monkey in the park.", outputB);

            place.addPreModifier("leafy");

            string outputC = realiser.realiseSentence(pB);

            Assert.AreEqual("Mary chases the monkey in the leafy park.", outputC);
        } // testSection11