Пример #1
0
        public void xmlLexiconImmutabilityTest()
        {
            this.lexicon = new XMLLexicon();
            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.ToString()));

            // Realise a sentence with plural form of "wall"
            wall.setPlural(true);
            SPhraseSpec sentence = factory.createClause("motion", "observe");

            sentence.setFeature(Feature.TENSE.ToString(), Tense.PAST);
            PPPhraseSpec pp = factory.createPrepositionPhrase("in", wall);

            sentence.addPostModifier(pp);
            var r = realiser.realiseSentence(sentence);

            Assert.AreEqual(r, "Motion observed in the walls.");

            // 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.ToString()));
        }
Пример #2
0
        public void xmlLexiconLookupWord_plurals()
        {
            this.lexicon = new XMLLexicon();
            var w1 = lexicon.lookupWord("man", new LexicalCategory_NOUN());
            var w2 = w1.getFeature(LexicalFeature.PLURAL.ToString());

            w2.ShouldBeEquivalentTo("men");
        }
Пример #3
0
        public void setUp_from_Filepath()
        {
            var timer = new Stopwatch();

            timer.Start();
            this.lexicon = new XMLLexicon(@"C:\work\SharpSimpleNLG\SharpSimpleNLGDotNetCore\lexicon\default-lexicon.xml");
            timer.Stop();
            Console.WriteLine($"Loading Lexicon took: {timer.ElapsedMilliseconds}ms");
        }
Пример #4
0
        public void setUp_from_EmbeddedResource()
        {
            var timer = new Stopwatch();

            timer.Start();
            this.lexicon = new XMLLexicon();
            timer.Stop();
            Console.WriteLine($"Loading Lexicon took: {timer.ElapsedMilliseconds}ms");
        }
Пример #5
0
        public void xmlLexiconLookupWord()
        {
            this.lexicon = new XMLLexicon();
            var w  = lexicon.lookupWord("man", new LexicalCategory_NOUN());
            var id = w.getId();

            Assert.IsNotNull(id);
            Assert.IsNotEmpty(id);
            id.ShouldBeEquivalentTo("E0038767");
        }
Пример #6
0
        public void xmlLexiconLookupTests()
        {
            this.lexicon = new XMLLexicon();

            var w = lexicon.getWords("man");

            w.Count.ShouldBeEquivalentTo(1);
            w[0].getBaseForm().ShouldBeEquivalentTo("man");
            w[0].features.Count.ShouldBeEquivalentTo(2);
            w[0].getId().ShouldBeEquivalentTo("E0038767");
        }
Пример #7
0
        public virtual void setUp()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            //lexicon = new XMLLexicon(XML_FILENAME); // omit, use default lexicon instead
            lexicon = new XMLLexicon();

            stopwatch.Stop();

            Console.Write("Loading XML lexicon took " + stopwatch.ElapsedMilliseconds + " ms%n");
        }
Пример #8
0
        public static void Main(string[] args)
        {
            var ss       = new XMLLexicon();
            var Factory  = new NLGFactory(ss);
            var Realiser = new Realiser(ss);

            // Instructions will be given to you by the director.

            var verbp = Factory.createVerbPhrase("be given");

            verbp.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
            var subj  = Factory.createNounPhrase("The Director");
            var oobj  = Factory.createNounPhrase("Instruction");
            var ioobj = Factory.createNounPhrase("you");

            subj.setPlural(false);
            oobj.setPlural(true);

            var s = new List <INLGElement>()
            {
                verbp, subj, oobj, ioobj
            };

            var clause = Factory.createClause();

            clause.setVerb(verbp);
            clause.setSubject(subj);
            clause.setObject(oobj);
            clause.setIndirectObject(ioobj);


            var sentence = Factory.createSentence(clause);

            sentence.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);

            var active = Realiser.realise(sentence).ToString();

            Console.WriteLine($"{active}");

            Console.WriteLine("done");
            Console.ReadLine();
        }
Пример #9
0
        public void xmlLexiconGetWordVariants()
        {
            this.lexicon = new XMLLexicon();
            var w    = lexicon.getWordsFromVariant("did");
            var resw = w[0];

            Assert.IsNotNull(resw);
            resw.getAllFeatures().Count.ShouldBeEquivalentTo(8);
            var form1 = resw.getFeature(LexicalFeature.PAST);

            form1.ShouldBeEquivalentTo("did");
            var form2 = resw.getFeature(LexicalFeature.PRESENT3S);

            form2.ShouldBeEquivalentTo("does");
            var form3 = resw.getFeature(LexicalFeature.PAST_PARTICIPLE);

            form3.ShouldBeEquivalentTo("done");
            var form4 = resw.getFeature(LexicalFeature.PRESENT_PARTICIPLE);

            form4.ShouldBeEquivalentTo("doing");
        }
Пример #10
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);
        }