public void section8_Test() { var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon var realiser = new Realiser(lexicon); //realiser.setDebugMode(true); var subject = nlgFactory.createNounPhrase("Mary"); var obj = nlgFactory.createNounPhrase("the monkey"); var verb = nlgFactory.createVerbPhrase("chase"); subject.addModifier("fast"); var p = nlgFactory.createClause(); p.setSubject(subject); p.setVerb(verb); p.setObject(obj); var outputA = realiser.realiseSentence(p); Assert.AreEqual("Fast Mary chases the monkey.", outputA); verb.addModifier("quickly"); var outputB = realiser.realiseSentence(p); Assert.AreEqual("Fast Mary quickly chases the monkey.", outputB); }
public void section13_Test() { var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon var realiser = new Realiser(lexicon); var s1 = nlgFactory.createClause("my cat", "like", "fish"); var s2 = nlgFactory.createClause("my dog", "like", "big bones"); var s3 = nlgFactory.createClause("my horse", "like", "grass"); var c = nlgFactory.createCoordinatedPhrase(); c.addCoordinate(s1); c.addCoordinate(s2); c.addCoordinate(s3); var outputA = realiser.realiseSentence(c); Assert.AreEqual("My cat likes fish, my dog likes big bones and my horse likes grass.", outputA); var p = nlgFactory.createClause("I", "be", "happy"); var q = nlgFactory.createClause("I", "eat", "fish"); q.setFeature(Feature.COMPLEMENTISER.ToString(), "because"); q.setFeature(Feature.TENSE.ToString(), Tense.PAST); p.addComplement(q); var outputB = realiser.realiseSentence(p); Assert.AreEqual("I am happy because I ate fish.", outputB); }
public virtual void section13_Test() { Lexicon lexicon = Lexicon.DefaultLexicon; // default simplenlg lexicon NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon Realiser realiser = new Realiser(lexicon); SPhraseSpec s1 = nlgFactory.createClause("my cat", "like", "fish"); SPhraseSpec s2 = nlgFactory.createClause("my dog", "like", "big bones"); SPhraseSpec s3 = nlgFactory.createClause("my horse", "like", "grass"); CoordinatedPhraseElement c = nlgFactory.createCoordinatedPhrase(); c.addCoordinate(s1); c.addCoordinate(s2); c.addCoordinate(s3); string outputA = realiser.realiseSentence(c); Assert.AreEqual("My cat likes fish, my dog likes big bones and my horse likes grass.", outputA); SPhraseSpec p = nlgFactory.createClause("I", "be", "happy"); SPhraseSpec q = nlgFactory.createClause("I", "eat", "fish"); q.setFeature(Feature.COMPLEMENTISER, "because"); q.setFeature(Feature.TENSE, Tense.PAST); p.addComplement(q); string outputB = realiser.realiseSentence(p); Assert.AreEqual("I am happy because I ate fish.", outputB); }
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 aggregationStringElementTest() { CoordinatedPhraseElement coordinate = phraseFactory.createCoordinatedPhrase( new StringElement("John is going to Tesco"), new StringElement("Mary is going to Sainsburys")); SPhraseSpec sentence = phraseFactory.createClause(); sentence.addComplement(coordinate); Assert.AreEqual("John is going to Tesco and Mary is going to Sainsburys.", realiser.realiseSentence(sentence)); }
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)); }
public void variantsTest() { var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon var realiser = new Realiser(lexicon); var p = nlgFactory.createClause(); p.setSubject("my dog"); p.setVerb("is"); // variant of be p.setObject("George"); var output = realiser.realiseSentence(p); Assert.AreEqual("My dog is George.", output); p = nlgFactory.createClause(); p.setSubject("my dog"); p.setVerb("chases"); // variant of chase p.setObject("George"); output = realiser.realiseSentence(p); Assert.AreEqual("My dog chases George.", output); p = nlgFactory.createClause(); p.setSubject(nlgFactory.createNounPhrase("the", "dogs")); // variant of "dog" p.setVerb("is"); // variant of be p.setObject("happy"); // variant of happy output = realiser.realiseSentence(p); Assert.AreEqual("The dog is happy.", output); p = nlgFactory.createClause(); p.setSubject(nlgFactory.createNounPhrase("the", "children")); // variant of "child" p.setVerb("is"); // variant of be p.setObject("happy"); // variant of happy output = realiser.realiseSentence(p); Assert.AreEqual("The child is happy.", output); // following functionality is enabled p = nlgFactory.createClause(); p.setSubject(nlgFactory.createNounPhrase("the", "dogs")); // variant of "dog" p.setVerb("is"); // variant of be p.setObject("happy"); // variant of happy output = realiser.realiseSentence(p); Assert.AreEqual("The dog is happy.", output); //corrected automatically }
public void section10_Test() { var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon var realiser = new Realiser(lexicon); var subject1 = nlgFactory.createNounPhrase("Mary"); var subject2 = nlgFactory.createNounPhrase("your", "giraffe"); // next line is not correct ~ should be nlgFactory.createCoordinatedPhrase ~ may be corrected in the API var subj = nlgFactory.createCoordinatedPhrase(subject1, subject2); var verb = nlgFactory.createVerbPhrase("chase"); var p = nlgFactory.createClause(); p.setSubject(subj); p.setVerb(verb); p.setObject("the monkey"); var outputA = realiser.realiseSentence(p); Assert.AreEqual("Mary and your giraffe chase the monkey.", outputA); var object1 = nlgFactory.createNounPhrase("the monkey"); var object2 = nlgFactory.createNounPhrase("George"); // next line is not correct ~ should be nlgFactory.createCoordinatedPhrase ~ may be corrected in the API var obj = nlgFactory.createCoordinatedPhrase(object1, object2); obj.addCoordinate("Martha"); p.setObject(obj); var outputB = realiser.realiseSentence(p); Assert.AreEqual("Mary and your giraffe chase the monkey, George and Martha.", outputB); obj.setFeature(Feature.CONJUNCTION.ToString(), "or"); var outputC = realiser.realiseSentence(p); Assert.AreEqual("Mary and your giraffe chase the monkey, George or Martha.", outputC); }
public override void RunCommand(object sender) { var engine = (AutomationEngineInstance)sender; var p = (SPhraseSpec)v_InstanceName.GetAppInstance(engine); Lexicon lexicon = Lexicon.getDefaultLexicon(); Realiser realiser = new Realiser(lexicon); string phraseOutput = realiser.realiseSentence(p); phraseOutput.StoreInUserVariable(engine, v_OutputUserVariableName); }
public async override Task RunCommand(object sender) { var engine = (IAutomationEngineInstance)sender; var p = (SPhraseSpec)((OBAppInstance)await v_InstanceName.EvaluateCode(engine)).Value; Lexicon lexicon = Lexicon.getDefaultLexicon(); Realiser realiser = new Realiser(lexicon); string phraseOutput = realiser.realiseSentence(p); phraseOutput.SetVariableValue(engine, v_OutputUserVariableName); }
public void section6A_Test() { var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon var realiser = new Realiser(lexicon); var p = nlgFactory.createClause(); p.setSubject("Mary"); p.setVerb("chase"); p.setObject("the monkey"); p.setFeature(Feature.TENSE.ToString(), Tense.PAST); var output = realiser.realiseSentence(p); Assert.AreEqual("Mary chased the monkey.", output); p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE); output = realiser.realiseSentence(p); Assert.AreEqual("Mary will chase the monkey.", output); p.setFeature(Feature.NEGATED.ToString(), true); output = realiser.realiseSentence(p); Assert.AreEqual("Mary will not chase the monkey.", output); p = nlgFactory.createClause(); p.setSubject("Mary"); p.setVerb("chase"); p.setObject("the monkey"); p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO); output = realiser.realiseSentence(p); Assert.AreEqual("Does Mary chase the monkey?", output); p.setSubject("Mary"); p.setVerb("chase"); p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT); output = realiser.realiseSentence(p); Assert.AreEqual("Who does Mary chase?", output); }
public virtual void section3_Test() { Lexicon lexicon = Lexicon.DefaultLexicon; // default simplenlg lexicon NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon NLGElement s1 = nlgFactory.createSentence("my dog is happy"); Realiser r = new Realiser(lexicon); string output = r.realiseSentence(s1); Assert.AreEqual("My dog is happy.", output); }
public void section3_Test() { var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon NLGElement s1 = nlgFactory.createSentence("my dog is happy"); var r = new Realiser(lexicon); var output = r.realiseSentence(s1); Assert.AreEqual("My dog is happy.", output); }
public override void RunCommand(object sender) { var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; var vInstance = v_InstanceName.ConvertToUserVariable(engine); var p = (SPhraseSpec)engine.GetAppInstance(vInstance); Lexicon lexicon = Lexicon.getDefaultLexicon(); Realiser realiser = new Realiser(lexicon); String phraseOutput = realiser.realiseSentence(p); phraseOutput.StoreInUserVariable(sender, v_applyToVariableName); }
public void section11_Test() { var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon var realiser = new Realiser(lexicon); var pA = nlgFactory.createClause("Mary", "chase", "the monkey"); pA.addComplement("in the park"); var outputA = realiser.realiseSentence(pA); Assert.AreEqual("Mary chases the monkey in the park.", outputA); // alternative build paradigm var place = nlgFactory.createNounPhrase("park"); var pB = nlgFactory.createClause("Mary", "chase", "the monkey"); // next line is depreciated ~ may be corrected in the API place.setDeterminer("the"); var pp = nlgFactory.createPrepositionPhrase(); pp.addComplement(place); pp.setPreposition("in"); pB.addComplement(pp); var outputB = realiser.realiseSentence(pB); Assert.AreEqual("Mary chases the monkey in the park.", outputB); place.addPreModifier("leafy"); var outputC = realiser.realiseSentence(pB); Assert.AreEqual("Mary chases the monkey in the leafy park.", outputC); } // testSection11
public void testWhatObjectInterrogative() { var lexicon = Lexicon.getDefaultLexicon(); var nlg = new NLGFactory(lexicon); var realiser = new Realiser(lexicon); // Case 1, no object is explicitly given: var clause = nlg.createClause("you", "think"); var aboutJohn = nlg.createPrepositionPhrase("about", "John"); clause.addPostModifier(aboutJohn); clause.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT); var realisation = realiser.realiseSentence(clause); 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); Assert.AreEqual("What do you think about John?", realisation); }
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); }
public void section5_Test() { var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon var realiser = new Realiser(lexicon); var p = nlgFactory.createClause(); p.setSubject("my dog"); p.setVerb("chase"); p.setObject("George"); var output = realiser.realiseSentence(p); Assert.AreEqual("My dog chases George.", output); }
public virtual void section5_Test() { Lexicon lexicon = Lexicon.DefaultLexicon; // default simplenlg lexicon NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon Realiser realiser = new Realiser(lexicon); SPhraseSpec p = nlgFactory.createClause(); p.setSubject("my dog"); p.setVerb("chase"); p.setObject("George"); string output = realiser.realiseSentence(p); Assert.AreEqual("My dog chases George.", output); }
public void section5A_Test() { var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon var realiser = new Realiser(lexicon); var p = nlgFactory.createClause(); p.setSubject("Mary"); p.setVerb("chase"); p.setObject("the monkey"); var output = realiser.realiseSentence(p); Assert.AreEqual("Mary chases the monkey.", output); } // testSection5A
public virtual void testPluralThisDeterminerNPObject_NIHDBLexicon() { lexicon = new NIHDBLexicon(DB_FILENAME, LEXICON_TYPE); phraseFactory = new NLGFactory(lexicon); realiser = new Realiser(lexicon); SPhraseSpec sentence_1 = phraseFactory.createClause(); NPPhraseSpec nounPhrase_1 = phraseFactory.createNounPhrase("monkey"); nounPhrase_1.Plural = true; nounPhrase_1.setDeterminer("this"); sentence_1.setObject(nounPhrase_1); Assert.AreEqual("These monkeys.", realiser.realiseSentence(sentence_1)); }
public void section7_Test() { var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon var realiser = new Realiser(lexicon); var p = nlgFactory.createClause(); p.setSubject("Mary"); p.setVerb("chase"); p.setObject("the monkey"); p.addComplement("very quickly"); p.addComplement("despite her exhaustion"); var output = realiser.realiseSentence(p); Assert.AreEqual("Mary chases the monkey very quickly despite her exhaustion.", output); }
public virtual void section6_Test() { Lexicon lexicon = Lexicon.DefaultLexicon; // default simplenlg lexicon NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon Realiser realiser = new Realiser(lexicon); SPhraseSpec p = nlgFactory.createClause(); p.setSubject("Mary"); p.setVerb("chase"); p.setObject("George"); p.setFeature(Feature.TENSE, Tense.PAST); string output = realiser.realiseSentence(p); Assert.AreEqual("Mary chased George.", output); p.setFeature(Feature.TENSE, Tense.FUTURE); output = realiser.realiseSentence(p); Assert.AreEqual("Mary will chase George.", output); p.setFeature(Feature.NEGATED, true); output = realiser.realiseSentence(p); Assert.AreEqual("Mary will not chase George.", output); p = nlgFactory.createClause(); p.setSubject("Mary"); p.setVerb("chase"); p.setObject("George"); p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO); output = realiser.realiseSentence(p); Assert.AreEqual("Does Mary chase George?", output); p.setSubject("Mary"); p.setVerb("chase"); p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT); output = realiser.realiseSentence(p); Assert.AreEqual("Who does Mary chase?", output); p = nlgFactory.createClause(); p.setSubject("the dog"); p.setVerb("wake up"); output = realiser.realiseSentence(p); Assert.AreEqual("The dog wakes up.", output); }
public virtual void pierreTest() { SPhraseSpec p = phraseFactory.createClause("Mary", "chase", "George"); p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT); Assert.AreEqual("What does Mary chase?", realiser.realiseSentence(p)); p = phraseFactory.createClause("Mary", "chase", "George"); p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO); Assert.AreEqual("Does Mary chase George?", realiser.realiseSentence(p)); p = phraseFactory.createClause("Mary", "chase", "George"); p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHERE); Assert.AreEqual("Where does Mary chase George?", realiser.realiseSentence(p)); p = phraseFactory.createClause("Mary", "chase", "George"); p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY); Assert.AreEqual("Why does Mary chase George?", realiser.realiseSentence(p)); p = phraseFactory.createClause("Mary", "chase", "George"); p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.HOW); Assert.AreEqual("How does Mary chase George?", realiser.realiseSentence(p)); }
public override string ToString() { Realiser realizer = new Realiser(); return(realizer.realiseSentence(SentenceSpec)); }
public virtual void testLowercaseConstant() { SPhraseSpec sentence = phraseFactory.createClause(); NPPhraseSpec subject = phraseFactory.createNounPhrase("a", "dog"); sentence.setSubject(subject); string output = realiser.realiseSentence(sentence); Assert.AreEqual("A dog.", output); }