Exemplo n.º 1
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());
        }
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 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.º 4
0
        public void passiveComplementTest()
        {
            NPPhraseSpec woman2            = this.phraseFactory.createNounPhrase("the", "woman");
            NPPhraseSpec dog2              = this.phraseFactory.createNounPhrase("the", "dog");
            VPPhraseSpec give2             = this.phraseFactory.createVerbPhrase("give");
            PPPhraseSpec behindTheCurtain2 = this.phraseFactory.createPrepositionPhrase("behind");
            NPPhraseSpec np52              = this.phraseFactory.createNounPhrase("the", "curtain");

            behindTheCurtain2.addComplement(np52);

            PPPhraseSpec inTheRoom2 = this.phraseFactory.createPrepositionPhrase("in");
            NPPhraseSpec np62       = this.phraseFactory.createNounPhrase("the", "room");

            inTheRoom2.addComplement(np62);


            // add some arguments
            dog2.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                            DiscourseFunction.OBJECT);
            woman2.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                              DiscourseFunction.INDIRECT_OBJECT);
            give2.addComplement(dog2);
            give2.addComplement(woman2);
            Assert.AreEqual("gives the woman the dog", this.realiser.realise(
                                give2).getRealisation());

            // add a few premodifiers and postmodifiers
            give2.addPreModifier("slowly");
            give2.addPostModifier(behindTheCurtain2);
            give2.addPostModifier(inTheRoom2);
            Assert.AreEqual(
                "slowly gives the woman the dog behind the curtain in the room",
                this.realiser.realise(give2).getRealisation());

            // passivise: This should suppress "the dog"
            give2.clearComplements();
            give2.addComplement(dog2);
            give2.addComplement(woman2);
            give2.setFeature(Feature.PASSIVE.ToString(), true);

            Assert.AreEqual(
                "is slowly given the woman behind the curtain in the room",
                this.realiser.realise(give2).getRealisation());
        }
Exemplo n.º 5
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