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);
        }
Beispiel #2
0
        /**
         * Sets the vp features.
         *
         * @param wp
         *            The xml Verb Phrase object.
         * @param p
         *            the internal VP object to get features from xml object.
         */
        private void setVPFeatures(wrapper.XmlVPPhraseSpec wp, VPPhraseSpec p)
        {
            if (wp.FORM != null)
            {
                Enum.TryParse(wp.FORM.ToString(), out Form form);
                p.setFeature(Feature.FORM, form);
            }

            if (wp.PERSON != null)
            {
                p.setFeature(Feature.PERSON, wp.PERSON);
            }

            if (wp.TENSE != null)
            {
                Enum.TryParse(wp.TENSE.ToString(), out Form tense);
                p.setFeature(Feature.TENSE, tense);
            }

            if (wp.MODAL != null)
            {
                p.setFeature(Feature.MODAL, wp.MODAL);
            }

            p.setFeature(Feature.AGGREGATE_AUXILIARY, wp.AGGREGATEAUXILIARY);
            p.setFeature(Feature.NEGATED, wp.NEGATED);
            p.setFeature(Feature.PASSIVE, wp.PASSIVE);
            p.setFeature(Feature.PERFECT, wp.PERFECT);
            p.setFeature(Feature.PROGRESSIVE, wp.PROGRESSIVE);
            p.setFeature(Feature.SUPPRESS_GENITIVE_IN_GERUND, wp.SUPPRESSGENITIVEINGERUND);
            p.setFeature(Feature.SUPRESSED_COMPLEMENTISER, wp.SUPRESSEDCOMPLEMENTISER);
        }
Beispiel #3
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);
        }
Beispiel #4
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());
        }
Beispiel #5
0
        /**
         * Creates a verb phrase wrapping the main verb given. If a
         * <code>String</code> is passed in then some parsing is done to see if the
         * verb contains a particle, for example <em>fall down</em>. The first word
         * is taken to be the verb while all other words are assumed to form the
         * particle.
         *
         * @param verb
         *            the verb to be wrapped.
         * @return a <code>VPPhraseSpec</code> representing this phrase.
         */
        public virtual VPPhraseSpec createVerbPhrase(object verb)
        {
            VPPhraseSpec phraseElement = new VPPhraseSpec(this);

            phraseElement.setVerb(verb);
            setPhraseHead(phraseElement, phraseElement.getVerb());
            return(phraseElement);
        }
Beispiel #6
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);
        }
Beispiel #7
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());
        }
Beispiel #8
0
        public virtual void testVerbParticle()
        {
            VPPhraseSpec v = phraseFactory.createVerbPhrase("fall down");    //$NON-NLS-1$

            Assert.AreEqual("down", v.getFeatureAsString(Feature.PARTICLE)); //$NON-NLS-1$

            Assert.AreEqual("fall", ((WordElement)v.getVerb()).BaseForm);    //$NON-NLS-1$

            v.setFeature(Feature.TENSE, Tense.PAST);
            v.setFeature(Feature.PERSON, Person.THIRD);
            v.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);

            Assert.AreEqual("fell down", realiser.realise(v).Realisation); //$NON-NLS-1$

            v.setFeature(Feature.FORM, Form.PAST_PARTICIPLE);
            Assert.AreEqual("fallen down", realiser.realise(v).Realisation); //$NON-NLS-1$
        }
Beispiel #9
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());
        }
Beispiel #10
0
        public void coordinationTest()
        {
            // simple case
            VPPhraseSpec kiss2 = this.phraseFactory.createVerbPhrase("kiss");

            kiss2.addComplement(this.dog);
            VPPhraseSpec kick2 = this.phraseFactory.createVerbPhrase("kick");

            kick2.addComplement(this.boy);

            var coord1 = new CoordinatedPhraseElement(
                kiss2, kick2);

            coord1.setFeature(Feature.PERSON.ToString(), Person.THIRD);
            coord1.setFeature(Feature.TENSE.ToString(), Tense.PAST);
            Assert.AreEqual("kissed the dog and kicked the boy", this.realiser
                            .realise(coord1).getRealisation());

            // with negation: should be inherited by all components
            coord1.setFeature(Feature.NEGATED.ToString(), true);
            this.realiser.setLexicon(this.lexicon);
            Assert.AreEqual("did not kiss the dog and did not kick the boy",
                            this.realiser.realise(coord1).getRealisation());

            // set a modal
            coord1.setFeature(Feature.MODAL.ToString(), "could");
            Assert.AreEqual(
                "could not have kissed the dog and could not have kicked the boy",
                this.realiser.realise(coord1).getRealisation());

            // set perfect and progressive
            coord1.setFeature(Feature.PERFECT.ToString(), true);
            coord1.setFeature(Feature.PROGRESSIVE.ToString(), true);
            Assert.AreEqual("could not have been kissing the dog and "
                            + "could not have been kicking the boy", this.realiser.realise(
                                coord1).getRealisation());

            // now aggregate
            coord1.setFeature(Feature.AGGREGATE_AUXILIARY.ToString(), true);
            Assert.AreEqual(
                "could not have been kissing the dog and kicking the boy",
                this.realiser.realise(coord1).getRealisation());
        }
Beispiel #11
0
        public virtual void testModalWithPassive()
        {
            NPPhraseSpec  @object = phraseFactory.createNounPhrase("the", "pizza");
            AdjPhraseSpec post    = phraseFactory.createAdjectivePhrase("good");
            AdvPhraseSpec @as     = phraseFactory.createAdverbPhrase("as");

            @as.addComplement(post);
            VPPhraseSpec verb = phraseFactory.createVerbPhrase("classify");

            verb.addPostModifier(@as);
            verb.addComplement(@object);
            SPhraseSpec s = phraseFactory.createClause();

            s.VerbPhrase = verb;
            s.setFeature(Feature.MODAL, "can");
            // s.setFeature(Feature.FORM, Form.INFINITIVE);
            s.setFeature(Feature.PASSIVE, true);
            Assert.AreEqual("the pizza can be classified as good", realiser.realise(s).Realisation);
        }
        public virtual void setUp()
        {
            lexicon = new XMLLexicon(); // built in lexicon

            phraseFactory = new NLGFactory(lexicon);
            realiser      = new Realiser(lexicon);

            man   = phraseFactory.createNounPhrase("the", "man");         //$NON-NLS-1$ //$NON-NLS-2$
            woman = phraseFactory.createNounPhrase("the", "woman");       //$NON-NLS-1$//$NON-NLS-2$
            dog   = phraseFactory.createNounPhrase("the", "dog");         //$NON-NLS-1$ //$NON-NLS-2$
            boy   = phraseFactory.createNounPhrase("the", "boy");         //$NON-NLS-1$ //$NON-NLS-2$

            beautiful = phraseFactory.createAdjectivePhrase("beautiful"); //$NON-NLS-1$
            stunning  = phraseFactory.createAdjectivePhrase("stunning");  //$NON-NLS-1$
            salacious = phraseFactory.createAdjectivePhrase("salacious"); //$NON-NLS-1$

            onTheRock = phraseFactory.createPrepositionPhrase("on");      //$NON-NLS-1$
            np4       = phraseFactory.createNounPhrase("the", "rock");    //$NON-NLS-1$ //$NON-NLS-2$
            onTheRock.addComplement(np4);

            behindTheCurtain = phraseFactory.createPrepositionPhrase("behind"); //$NON-NLS-1$
            np5 = phraseFactory.createNounPhrase("the", "curtain");             //$NON-NLS-1$ //$NON-NLS-2$
            behindTheCurtain.addComplement(np5);

            inTheRoom = phraseFactory.createPrepositionPhrase("in");   //$NON-NLS-1$
            np6       = phraseFactory.createNounPhrase("the", "room"); //$NON-NLS-1$ //$NON-NLS-2$
            inTheRoom.addComplement(np6);

            underTheTable = phraseFactory.createPrepositionPhrase("under");              //$NON-NLS-1$
            underTheTable.addComplement(phraseFactory.createNounPhrase("the", "table")); //$NON-NLS-1$ //$NON-NLS-2$

            proTest1 = phraseFactory.createNounPhrase("the", "singer");                  //$NON-NLS-1$ //$NON-NLS-2$
            proTest2 = phraseFactory.createNounPhrase("some", "person");                 //$NON-NLS-1$ //$NON-NLS-2$

            kick     = phraseFactory.createVerbPhrase("kick");                           //$NON-NLS-1$
            kiss     = phraseFactory.createVerbPhrase("kiss");                           //$NON-NLS-1$
            walk     = phraseFactory.createVerbPhrase("walk");                           //$NON-NLS-1$
            talk     = phraseFactory.createVerbPhrase("talk");                           //$NON-NLS-1$
            getUp    = phraseFactory.createVerbPhrase("get up");                         //$NON-NLS-1$
            fallDown = phraseFactory.createVerbPhrase("fall down");                      //$NON-NLS-1$
            give     = phraseFactory.createVerbPhrase("give");                           //$NON-NLS-1$
            say      = phraseFactory.createVerbPhrase("say");                            //$NON-NLS-1$
        }
Beispiel #13
0
        public virtual void section10_Test()
        {
            Lexicon    lexicon    = Lexicon.DefaultLexicon;  // default simplenlg lexicon
            NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
            Realiser   realiser   = new Realiser(lexicon);

            NPPhraseSpec subject1 = nlgFactory.createNounPhrase("Mary");
            NPPhraseSpec subject2 = nlgFactory.createNounPhrase("your", "giraffe");

            // next line is not correct ~ should be nlgFactory.createCoordinatedPhrase ~ may be corrected in the API
            CoordinatedPhraseElement subj = nlgFactory.createCoordinatedPhrase(subject1, subject2);

            VPPhraseSpec verb = nlgFactory.createVerbPhrase("chase");

            SPhraseSpec p = nlgFactory.createClause();

            p.setSubject(subj);
            p.setVerb(verb);
            p.setObject("the monkey");

            string outputA = realiser.realiseSentence(p);

            Assert.AreEqual("Mary and your giraffe chase the monkey.", outputA);

            NPPhraseSpec object1 = nlgFactory.createNounPhrase("the monkey");
            NPPhraseSpec object2 = nlgFactory.createNounPhrase("George");

            // next line is not correct ~ should be nlgFactory.createCoordinatedPhrase ~ may be corrected in the API
            CoordinatedPhraseElement obj = nlgFactory.createCoordinatedPhrase(object1, object2);

            obj.addCoordinate("Martha");
            p.setObject(obj);

            string outputB = realiser.realiseSentence(p);

            Assert.AreEqual("Mary and your giraffe chase the monkey, George and Martha.", outputB);

            obj.setFeature(Feature.CONJUNCTION, "or");

            string outputC = realiser.realiseSentence(p);

            Assert.AreEqual("Mary and your giraffe chase the monkey, George or Martha.", outputC);
        }
        public virtual void layTest()
        {
            string lemma = "slap";

            WordElement          word          = lexicon.lookupWord(lemma, new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB));
            InflectedWordElement inflectedWord = new InflectedWordElement(word);

            inflectedWord.setFeature(Feature.FORM, Form.PRESENT_PARTICIPLE);
            string form = realiser.realise(inflectedWord).Realisation;

            Assert.AreEqual("slapping", form);

            VPPhraseSpec v = phraseFactory.createVerbPhrase("slap");

            v.setFeature(Feature.PROGRESSIVE, true);
            string progressive = realiser.realise(v).Realisation;

            Assert.AreEqual("is slapping", progressive);
        }
Beispiel #15
0
        public virtual void multipleAdvPremodifiersTest()
        {
            AdvPhraseSpec adv1 = phraseFactory.createAdverbPhrase("slowly");
            AdvPhraseSpec adv2 = phraseFactory.createAdverbPhrase("discretely");


            // case 1: concatenated premods: should have comma
            VPPhraseSpec vp = phraseFactory.createVerbPhrase("run");

            vp.addPreModifier(adv1);
            vp.addPreModifier(adv2);
            Assert.AreEqual("slowly, discretely runs", realiser.realise(vp).Realisation);


            // case 2: coordinated premods: no comma
            VPPhraseSpec vp2 = phraseFactory.createVerbPhrase("eat");

            vp2.addPreModifier(phraseFactory.createCoordinatedPhrase(adv1, adv2));
            Assert.AreEqual("slowly and discretely eats", realiser.realise(vp2).Realisation);
        }
        public virtual void testCoordinateVPComplexSubject()
        {
            // "As a result of the procedure the patient had an adverse contrast media reaction and went into cardiogenic shock."
            SPhraseSpec s = phraseFactory.createClause();

            s.setSubject(phraseFactory.createNounPhrase("the", "patient"));

            // first VP
            VPPhraseSpec vp1 = phraseFactory.createVerbPhrase(lexicon.getWord("have",
                                                                              new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)));
            NPPhraseSpec np1 = phraseFactory.createNounPhrase("a",
                                                              lexicon.getWord("contrast media reaction",
                                                                              new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)));

            np1.addPreModifier(lexicon.getWord("adverse",
                                               new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADJECTIVE)));
            vp1.addComplement(np1);

            // second VP
            VPPhraseSpec vp2 = phraseFactory.createVerbPhrase(lexicon.getWord("go",
                                                                              new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)));
            PPPhraseSpec pp = phraseFactory.createPrepositionPhrase("into",
                                                                    lexicon.getWord("cardiogenic shock", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)));

            vp2.addComplement(pp);

            // coordinate
            CoordinatedPhraseElement coord = phraseFactory.createCoordinatedPhrase(vp1, vp2);

            coord.setFeature(Feature.TENSE, Tense.PAST);
            Assert.AreEqual("had an adverse contrast media reaction and went into cardiogenic shock",
                            realiser.realise(coord).Realisation);


            // now put this in the sentence
            s.VerbPhrase = coord;
            s.addFrontModifier("As a result of the procedure");
            Assert.AreEqual(
                "As a result of the procedure the patient had an adverse contrast media reaction and went into cardiogenic shock",
                realiser.realise(s).Realisation);
        }
Beispiel #17
0
        public virtual void subclausesTest()
        {
            // Once upon a time, there was an Accountant, called Jeff, who lived in a forest.
            // main sentence
            NPPhraseSpec acct = phraseFactory.createNounPhrase("a", "accountant");


            // first postmodifier of "an accountant"
            VPPhraseSpec sub1 = phraseFactory.createVerbPhrase("call");

            sub1.addComplement("Jeff");
            sub1.setFeature(Feature.FORM, Form.PAST_PARTICIPLE);
            // this is an appositive modifier, which makes simplenlg put it between commas
            sub1.setFeature(Feature.APPOSITIVE, true);
            acct.addPostModifier(sub1);

            // second postmodifier of "an accountant" is "who lived in a forest"
            SPhraseSpec  sub2  = phraseFactory.createClause();
            VPPhraseSpec subvp = phraseFactory.createVerbPhrase("live");

            subvp.setFeature(Feature.TENSE, Tense.PAST);
            subvp.Complement =
                phraseFactory.createPrepositionPhrase("in", phraseFactory.createNounPhrase("a", "forest"));
            sub2.VerbPhrase = subvp;
            // simplenlg can't yet handle wh-clauses in NPs, so we need to hack it
            // by setting the subject to "who"
            sub2.setSubject("who");
            acct.addPostModifier(sub2);

            // main sentence
            SPhraseSpec s = phraseFactory.createClause("there", "be", acct);

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

            // add front modifier "once upon a time"
            s.addFrontModifier("once upon a time");

            Assert.AreEqual("once upon a time there was an accountant, called Jeff, who lived in a forest",
                            realiser.realise(s).Realisation);
        }
        public virtual void tearDown()
        {
            realiser = null;

            phraseFactory = null;

            if (null != lexicon)
            {
                lexicon = null;
            }

            man      = null;
            woman    = null;
            dog      = null;
            boy      = null;
            np4      = null;
            np5      = null;
            np6      = null;
            proTest1 = null;
            proTest2 = null;

            beautiful = null;
            stunning  = null;
            salacious = null;

            onTheRock        = null;
            behindTheCurtain = null;
            inTheRoom        = null;
            underTheTable    = null;

            kick     = null;
            kiss     = null;
            walk     = null;
            talk     = null;
            getUp    = null;
            fallDown = null;
            give     = null;
            say      = null;
        }
Beispiel #19
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);
        }
Beispiel #20
0
        /**
         * Unwrap a <code>simplenlg.xmlrealiser.wrapper.NLGElement</code> and map it
         * to a <code>simplenlg.framework.NLGElement</code>
         *
         * @param wps
         *            The wrapper object
         * @return the NLGElement
         */
        public virtual NLGElement UnwrapNLGElement(wrapper.XmlNLGElement wps)
        {
            if (wps == null)
            {
                return(null);
            }

            if (wps is wrapper.XmlDocumentElement)
            {
                return((NLGElement)UnwrapDocumentElement((wrapper.XmlDocumentElement)wps));
            }

            // Handle coordinate phrase specs first, which will cause recursion.
            NLGElement cp = UnwrapCoordinatePhraseSpec(wps);

            if (cp != null)
            {
                return(cp);
            }

            // Literal text.
            if (wps is wrapper.XmlStringElement)
            {
                wrapper.XmlStringElement wp = (wrapper.XmlStringElement)wps;
                NLGElement p = factory.createStringElement(wp.Val);
                return(p);
            }

            // WordElements (delegate to UnwrapWordElement) -- useful to have
            // because it is called by unWrapPhraseComponents, and pre/post mods
            // might be WordElements
            if (wps is XmlWordElement)
            {
                return(UnwrapWordElement((XmlWordElement)wps));
            }

            // Sentence
            else if (wps is wrapper.XmlSPhraseSpec)
            {
                wrapper.XmlSPhraseSpec wp = (wrapper.XmlSPhraseSpec)wps;
                SPhraseSpec            sp = factory.createClause();
                NLGElement             vp = null;

                List <NLGElement> subjects = new List <NLGElement>();
                foreach (wrapper.XmlNLGElement p in wp.Subj)
                {
                    NLGElement p1 = UnwrapNLGElement(p);
                    checkFunction(DiscourseFunction.SUBJECT, p1);
                    subjects.Add(p1);
                }

                if (subjects.Any())
                {
                    sp.setFeature(InternalFeature.SUBJECTS, subjects);
                }

                if (wp.Vp != null)
                {
                    vp            = UnwrapNLGElement(wp.Vp);
                    sp.VerbPhrase = vp;
                }

                if (wp.CuePhrase != null)
                {
                    NLGElement cue = UnwrapNLGElement(wp.CuePhrase);
                    cue.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.CUE_PHRASE);
                    sp.setFeature(Feature.CUE_PHRASE, cue);
                }

                if (wp.COMPLEMENTISER != null)
                {
                    sp.setFeature(Feature.COMPLEMENTISER, wp.COMPLEMENTISER);
                }

                setSFeatures(wp, sp, vp);

                // Common phrase components.
                UnwrapPhraseComponents(sp, wps);

                return(sp);
            }

            // Phrases
            else if (wps is wrapper.XmlPhraseElement)
            {
                wrapper.XmlPhraseElement we = (wrapper.XmlPhraseElement)wps;
                PhraseElement            hp = null;
                XmlWordElement           w  = we.Head;
                NLGElement head             = UnwrapWordElement(w);

                // NLGElement head;
                // simplenlg.xmlrealiser.wrapper.XmlNLGElement w =
                // we.getHeadstring();

                // check whether we have a stringelement or wordelement as head
                // if(w == null) {
                // w = we.getHeadword();
                // head = UnwrapWordElement((XmlWordElement) w);
                //
                // } else {
                // head = factory.createStringElement(((XmlStringElement)
                // w).getVal());
                // }

                // Noun Phrase
                if (wps is wrapper.XmlNPPhraseSpec)
                {
                    wrapper.XmlNPPhraseSpec wp = (wrapper.XmlNPPhraseSpec)wps;

                    NPPhraseSpec p = factory.createNounPhrase(head);
                    hp = p;

                    if (wp.Spec != null)
                    {
                        // p.setSpecifier(UnwrapWordElement(wp.getSpec()));
                        wrapper.XmlNLGElement spec = wp.Spec;

                        if (spec is XmlWordElement)
                        {
                            WordElement specifier = (WordElement)UnwrapWordElement((XmlWordElement)spec);

                            if (specifier != null)
                            {
                                p.setSpecifier(specifier);
                            }
                        }
                        else
                        {
                            p.setSpecifier(UnwrapNLGElement(spec));
                        }
                    }

                    setNPFeatures(wp, p);
                }

                // Adjective Phrase
                else if (wps is wrapper.XmlAdjPhraseSpec)
                {
                    wrapper.XmlAdjPhraseSpec wp = (wrapper.XmlAdjPhraseSpec)wps;
                    AdjPhraseSpec            p  = factory.createAdjectivePhrase(head);
                    hp = p;

                    p.setFeature(Feature.IS_COMPARATIVE, wp.ISCOMPARATIVE);
                    p.setFeature(Feature.IS_SUPERLATIVE, wp.ISSUPERLATIVE);
                }

                // Prepositional Phrase
                else if (wps is wrapper.XmlPPPhraseSpec)
                {
                    PPPhraseSpec p = factory.createPrepositionPhrase(head);
                    hp = p;
                }

                // Adverb Phrase
                else if (wps is wrapper.XmlAdvPhraseSpec)
                {
                    wrapper.XmlAdvPhraseSpec wp = (wrapper.XmlAdvPhraseSpec)wps;
                    AdvPhraseSpec            p  = factory.createAdverbPhrase();
                    p.setHead(head);
                    hp = p;
                    p.setFeature(Feature.IS_COMPARATIVE, wp.ISCOMPARATIVE);
                    p.setFeature(Feature.IS_SUPERLATIVE, wp.ISSUPERLATIVE);
                }

                // Verb Phrase
                else if (wps is wrapper.XmlVPPhraseSpec)
                {
                    wrapper.XmlVPPhraseSpec wp = (wrapper.XmlVPPhraseSpec)wps;
                    VPPhraseSpec            p  = factory.createVerbPhrase(head);
                    hp = p;
                    setVPFeatures(wp, p);
                }

                // Common phrase components.
                UnwrapPhraseComponents(hp, wps);

                // set the discourse function, if defined
                if (we.DiscourseFunction != null)
                {
                    DiscourseFunction func;
                    Enum.TryParse(we.DiscourseFunction.ToString(), out func);
                    hp.setFeature(InternalFeature.DISCOURSE_FUNCTION, func);
                }

                // check the appositive feature
                bool?appositive = we.Appositive;
                if (appositive != null)
                {
                    hp.setFeature(Feature.APPOSITIVE, appositive);
                }

                return(hp);
            }

            return(null);
        }
Beispiel #21
0
        protected virtual void setUp()
        {
            this.lexicon = Lexicon.getDefaultLexicon();

            this.phraseFactory = new NLGFactory(this.lexicon);
            this.realiser      = new Realiser(this.lexicon);

            this.man   = this.phraseFactory.createNounPhrase("the", "man");
            this.woman = this.phraseFactory.createNounPhrase("the", "woman");
            this.dog   = this.phraseFactory.createNounPhrase("the", "dog");
            this.boy   = this.phraseFactory.createNounPhrase("the", "boy");

            this.beautiful = this.phraseFactory.createAdjectivePhrase("beautiful");
            this.stunning  = this.phraseFactory.createAdjectivePhrase("stunning");
            this.salacious = this.phraseFactory.createAdjectivePhrase("salacious");

            this.onTheRock = this.phraseFactory.createPrepositionPhrase("on");
            this.np4       = this.phraseFactory.createNounPhrase("the", "rock");
            this.onTheRock.addComplement(this.np4);

            this.behindTheCurtain = this.phraseFactory.createPrepositionPhrase("behind");
            this.np5 = this.phraseFactory.createNounPhrase("the", "curtain");
            this.behindTheCurtain.addComplement(this.np5);

            this.inTheRoom = this.phraseFactory.createPrepositionPhrase("in");
            this.np6       = this.phraseFactory.createNounPhrase("the", "room");
            this.inTheRoom.addComplement(this.np6);

            this.underTheTable = this.phraseFactory.createPrepositionPhrase("under");
            this.underTheTable.addComplement(this.phraseFactory.createNounPhrase("the", "table"));


            this.proTest1 = this.phraseFactory.createNounPhrase("the", "singer");
            this.proTest2 = this.phraseFactory.createNounPhrase("some", "person");

            this.kick     = this.phraseFactory.createVerbPhrase("kick");
            this.kiss     = this.phraseFactory.createVerbPhrase("kiss");
            this.walk     = this.phraseFactory.createVerbPhrase("walk");
            this.talk     = this.phraseFactory.createVerbPhrase("talk");
            this.getUp    = this.phraseFactory.createVerbPhrase("get up");
            this.fallDown = this.phraseFactory.createVerbPhrase("fall down");
            this.give     = this.phraseFactory.createVerbPhrase("give");
            this.say      = this.phraseFactory.createVerbPhrase("say");

            // the woman kisses the man
            s1 = this.phraseFactory.createClause();
            s1.setSubject(this.woman);
            s1.setVerbPhrase(this.kiss);
            s1.setObject(this.man);

            // there is the dog on the rock
            s2 = this.phraseFactory.createClause();
            s2.setSubject("there");
            s2.setVerb("be");
            s2.setObject(this.dog);
            s2.addPostModifier(this.onTheRock);

            // the man gives the woman John's flower
            s3 = this.phraseFactory.createClause();
            s3.setSubject(this.man);
            s3.setVerbPhrase(this.give);

            var flower = this.phraseFactory.createNounPhrase("flower");
            var john   = this.phraseFactory.createNounPhrase("John");

            john.setFeature(Feature.POSSESSIVE.ToString(), true);
            flower.setFeature(InternalFeature.SPECIFIER.ToString(), john);
            s3.setObject(flower);
            s3.setIndirectObject(this.woman);

            s4 = this.phraseFactory.createClause();
            s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
            s4.addFrontModifier("tomorrow");

            var subject = this.phraseFactory
                          .createCoordinatedPhrase(this.phraseFactory
                                                   .createNounPhrase("Jane"), this.phraseFactory
                                                   .createNounPhrase("Andrew"));

            s4.setSubject(subject);

            var pick = this.phraseFactory.createVerbPhrase("pick up");

            s4.setVerbPhrase(pick);
            s4.setObject("the balls");
            s4.addPostModifier("in the shop");
            s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
        }