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); }
public virtual void leanTest() { SPhraseSpec sentence = phraseFactory.createClause(); sentence.setVerb("be"); sentence.setObject("a ball"); sentence.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT); Assert.AreEqual("What is a ball?", realiser.realiseSentence(sentence)); sentence = phraseFactory.createClause(); sentence.setVerb("be"); NPPhraseSpec @object = phraseFactory.createNounPhrase("example"); @object.Plural = true; @object.addModifier("of jobs"); sentence.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT); sentence.setObject(@object); Assert.AreEqual("What are examples of jobs?", realiser.realiseSentence(sentence)); SPhraseSpec p = phraseFactory.createClause(); NPPhraseSpec sub1 = phraseFactory.createNounPhrase("Mary"); sub1.setFeature(LexicalFeature.GENDER, Gender.FEMININE); sub1.setFeature(Feature.PRONOMINAL, true); sub1.setFeature(Feature.PERSON, Person.FIRST); p.setSubject(sub1); p.setVerb("chase"); p.setObject("the monkey"); string output2 = realiser.realiseSentence(p); // Realiser created earlier. Assert.AreEqual("I chase the monkey.", output2); SPhraseSpec test = phraseFactory.createClause(); NPPhraseSpec subject = phraseFactory.createNounPhrase("Mary"); subject.setFeature(Feature.PRONOMINAL, true); subject.setFeature(Feature.PERSON, Person.SECOND); test.setSubject(subject); test.setVerb("cry"); test.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY); test.setFeature(Feature.TENSE, Tense.PRESENT); Assert.AreEqual("Why do you cry?", realiser.realiseSentence(test)); test = phraseFactory.createClause(); subject = phraseFactory.createNounPhrase("Mary"); subject.setFeature(Feature.PRONOMINAL, true); subject.setFeature(Feature.PERSON, Person.SECOND); test.setSubject(subject); test.setVerb("be"); test.setObject("crying"); test.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY); test.setFeature(Feature.TENSE, Tense.PRESENT); Assert.AreEqual("Why are you crying?", realiser.realiseSentence(test)); }
/** * @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); }