Ejemplo 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());
        }
Ejemplo 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);
        }
Ejemplo n.º 3
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
Ejemplo n.º 4
0
        public Phrase(SightWords words, WordElement seed)
        {
            var factory = new NLGFactory(Lexicon);

            SentenceSpec = factory.createClause();

            var category = (LexicalCategoryEnum)seed.getCategory().enumType;

            NPPhraseSpec subject    = null;
            VPPhraseSpec verb       = null;
            PPPhraseSpec complement = null;

            switch (category)
            {
            case LexicalCategoryEnum.PRONOUN:
                var v = words.Verb;
                Console.Out.WriteLine("PRONOUN: {0}, {1} VERB: {2}, {3}", seed.getBaseForm(), seed.id, v.getBaseForm(), v.id);
                subject = factory.createNounPhrase(seed);

                verb = factory.createVerbPhrase(v);
                break;

            case LexicalCategoryEnum.NOUN:

                subject = factory.createNounPhrase(words.Determiner, seed);
                //verb = words.Verb;
                break;

            case LexicalCategoryEnum.VERB:

                verb    = factory.createVerbPhrase(seed);
                subject = factory.createNounPhrase(words.Pronoun);

                break;

            case LexicalCategoryEnum.ADJECTIVE:
                subject = factory.createNounPhrase(words.Determiner, words.Noun);
                //verb = words.Verb;
                ((NPPhraseSpec)subject).addModifier(seed);


                break;

            case LexicalCategoryEnum.DETERMINER:

                subject = factory.createNounPhrase(seed, words.Noun);
                //verb = words.Verb;
                break;

            case LexicalCategoryEnum.ADVERB:
                subject = factory.createNounPhrase(words.Pronoun);
                verb    = factory.createVerbPhrase(words.Verb);
                ((VPPhraseSpec)verb).addPreModifier(seed);
                break;

            case LexicalCategoryEnum.PREPOSITION:

                complement = factory.createPrepositionPhrase();
                complement.setComplement(factory.createNounPhrase(words.Determiner, words.Noun));
                complement.setPreposition(seed);

                break;

            case LexicalCategoryEnum.CONJUNCTION:

                var subject1 = factory.createNounPhrase(words.Determiner, words.Noun);
                var subject2 = factory.createNounPhrase(words.Determiner, words.Noun);
                var coord    = factory.createCoordinatedPhrase(subject1, subject2);
                coord.setFeature(Feature.CONJUNCTION.ToString(), seed);

                break;

            case LexicalCategoryEnum.MODAL:
                break;

            default:

                break;
            }

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

            if (verb != null)
            {
                SentenceSpec.setVerb(verb);
            }

            //if (complement != null)
            //    SentenceSpec.setComplement(complement);

            //SentenceSpec.setSubject("me");
            //SentenceSpec.setVerb("ride");
            // var tense = (Tense)Random.Next(0, 2);
            //SentenceSpec.setFeature(Feature.TENSE.ToString(), tense);
        }