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"
        }
示例#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 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);
        }
示例#4
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$
        }
        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);
        }
示例#6
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$
        }
示例#7
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$
        }
示例#8
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());
        }
        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));
        }
示例#10
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());
        }
示例#11
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);
        }
示例#12
0
        /**
         * Creates a preposition phrase with the given preposition and complement.
         * An <code>NLGElement</code> representing the preposition is added as the
         * head feature of this phrase while the complement is added as a normal
         * phrase complement.
         *
         * @param preposition
         *            the preposition to be used.
         * @param complement
         *            the complement of the phrase.
         * @return a <code>PPPhraseSpec</code> representing this phrase.
         */
        public virtual PPPhraseSpec createPrepositionPhrase(object preposition, object complement)
        {
            PPPhraseSpec phraseElement = new PPPhraseSpec(this);

            NLGElement prepositionalElement = createNLGElement(preposition, new LexicalCategory(LexicalCategory.LexicalCategoryEnum.PREPOSITION));

            setPhraseHead(phraseElement, prepositionalElement);

            if (complement != null)
            {
                setComplement(phraseElement, complement);
            }
            return(phraseElement);
        }
示例#13
0
        public void piotrekTest()
        {
            // Piotrek Smulikowski's test
            SetupForExternalTest.phraseFactory.setLexicon(SetupForExternalTest.lexicon);
            SPhraseSpec sent = SetupForExternalTest.phraseFactory.createClause(
                "I", "shoot", "the duck");

            sent.setFeature(Feature.TENSE.ToString(), Tense.PAST);

            PPPhraseSpec loc = SetupForExternalTest.phraseFactory.createPrepositionPhrase(
                "at", "the Shooting Range");

            sent.addPostModifier(loc);
            sent.setFeature(Feature.CUE_PHRASE.ToString(), "then");

            Assert.AreEqual("then I shot the duck at the Shooting Range",
                            SetupForExternalTest.realiser.realise(sent).getRealisation());
        }
示例#14
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());
        }
        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);
        }
        public virtual void testAppositivePreModifiers()
        {
            NPPhraseSpec subject = phraseFactory.createNounPhrase("I");
            NPPhraseSpec @object = phraseFactory.createNounPhrase("a bag");

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


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

            _s1.addPreModifier(pp);

            //without appositive feature on pp
            Assert.AreEqual("I on most Tuesdays carry a bag", realiser.realise(_s1).Realisation);


            //with appositive feature
            pp.setFeature(Feature.APPOSITIVE, true);
            Assert.AreEqual("I, on most Tuesdays, carry a bag", realiser.realise(_s1).Realisation);
        }
示例#17
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
示例#18
0
        public virtual void testWhatObjectInterrogative()
        {
            Lexicon    lexicon  = Lexicon.DefaultLexicon;
            NLGFactory nlg      = new NLGFactory(lexicon);
            Realiser   realiser = new Realiser(lexicon);

            // Case 1, no object is explicitly given:
            SPhraseSpec  clause    = nlg.createClause("you", "think");
            PPPhraseSpec aboutJohn = nlg.createPrepositionPhrase("about", "John");

            clause.addPostModifier(aboutJohn);
            clause.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
            string realisation = realiser.realiseSentence(clause);

            Console.WriteLine(realisation);
            Assert.AreEqual("What do you think about John?", realisation);

            // Case 2:
            // Add "bad things" as the object so the object doesn't remain null:
            clause.setObject("bad things");
            realisation = realiser.realiseSentence(clause);
            Console.WriteLine(realiser.realiseSentence(clause));
            Assert.AreEqual("What do you think about John?", realisation);
        }
示例#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);
        }
示例#20
0
        /**
         * @param args
         */
        public static void Main(string[] args)
        {
            // below is a simple complete example of using simplenlg V4
            // afterwards is an example of using simplenlg just for morphology

            // set up
            Lexicon    lexicon    = new XMLLexicon();        // default simplenlg lexicon
            NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon

            // create sentences
            //  "John did not go to the bigger park. He played football there."
            NPPhraseSpec  thePark = nlgFactory.createNounPhrase("the", "park"); // create an NP
            AdjPhraseSpec bigp    = nlgFactory.createAdjectivePhrase("big");    // create AdjP

            bigp.setFeature(Feature.IS_COMPARATIVE, true);                      // use comparative form ("bigger")
            thePark.addModifier(bigp);                                          // add adj as modifier in NP
            // above relies on default placement rules.  You can force placement as a premodifier
            // (before head) by using addPreModifier
            PPPhraseSpec toThePark = nlgFactory.createPrepositionPhrase("to"); // create a PP

            toThePark.setObject(thePark);                                      // set PP object
            // could also just say nlgFactory.createPrepositionPhrase("to", the Park);

            SPhraseSpec johnGoToThePark = nlgFactory.createClause("John", "go", toThePark); // create sentence

            johnGoToThePark.setFeature(Feature.TENSE, Tense.PAST);                          // set tense
            johnGoToThePark.setFeature(Feature.NEGATED, true);                              // set negated

            // note that constituents (such as subject and object) are set with setXXX methods
            // while features are set with setFeature

            DocumentElement sentence = nlgFactory.createSentence(johnGoToThePark);


            // below creates a sentence DocumentElement by concatenating strings
            StringElement hePlayed = new StringElement("he played");
            StringElement there    = new StringElement("there");
            WordElement   football = new WordElement("football");

            DocumentElement sentence2 = nlgFactory.createSentence();

            sentence2.addComponent(hePlayed);
            sentence2.addComponent(football);
            sentence2.addComponent(there);

            // now create a paragraph which contains these sentences
            DocumentElement paragraph = nlgFactory.createParagraph();

            paragraph.addComponent(sentence);
            paragraph.addComponent(sentence2);

            // create a realiser.  Note that a lexicon is specified, this should be
            // the same one used by the NLGFactory
            Realiser realiser = new Realiser(lexicon);
            //realiser.setDebugMode(true);     // uncomment this to print out debug info during realisation
            NLGElement realised = realiser.realise(paragraph);

            Console.WriteLine(realised.Realisation);

            // end of main example

            // second example - using simplenlg just for morphology
            // below is clumsy as direct access to morphology isn't properly supported in V4.2
            // hopefully will be better supported in later versions

            // get word element for "child"
            WordElement word = (WordElement)nlgFactory.createWord("child",
                                                                  new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN));
            // create InflectedWordElement from word element
            InflectedWordElement inflectedWord = new InflectedWordElement(word);

            // set the inflected word to plural
            inflectedWord.Plural = true;
            // realise the inflected word
            string result = realiser.realise(inflectedWord).Realisation;

            Console.WriteLine(result);
        }
示例#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);
        }
示例#22
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);
        }