public void correctPluralizationWithPossessives() { NPPhraseSpec sisterNP = SetupForRealiserTest.phraseFactory.createNounPhrase("sister"); INLGElement word = SetupForRealiserTest.phraseFactory.createInflectedWord("Albert Einstein", new LexicalCategory_NOUN()); word.setFeature(LexicalFeature.PROPER, true); NPPhraseSpec possNP = SetupForRealiserTest.phraseFactory.createNounPhrase(word); possNP.setFeature(Feature.POSSESSIVE.ToString(), true); sisterNP.setSpecifier(possNP); Assert.AreEqual("Albert Einstein's sister", SetupForRealiserTest.realiser.realise(sisterNP).getRealisation()); sisterNP.setPlural(true); SetupForRealiserTest.realiser.setDebugMode(true); Assert.AreEqual("Albert Einstein's sisters", SetupForRealiserTest.realiser.realise(sisterNP).getRealisation()); sisterNP.setPlural(false); possNP.setFeature(LexicalFeature.GENDER, Gender.MASCULINE); possNP.setFeature(Feature.PRONOMINAL.ToString(), true); Assert.AreEqual("his sister", SetupForRealiserTest.realiser.realise(sisterNP).getRealisation()); sisterNP.setPlural(true); Assert.AreEqual("his sisters", SetupForRealiserTest.realiser.realise(sisterNP).getRealisation()); }
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)); }
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 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$ }
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$ }
public virtual void spellingVariantsInNPTest() { WordElement asd = lexicon.getWord("Adams-Stokes disease"); Assert.AreEqual("Adams-Stokes disease", asd.DefaultSpellingVariant); NPPhraseSpec np = factory.createNounPhrase(asd); np.setSpecifier(lexicon.getWord("the")); Assert.AreEqual("the Adams-Stokes disease", realiser.realise(np).Realisation); // change spelling var asd.DefaultSpellingVariant = "Adams Stokes disease"; Assert.AreEqual("Adams Stokes disease", asd.DefaultSpellingVariant); Assert.AreEqual("the Adams Stokes disease", realiser.realise(np).Realisation); //default infl for this word is uncount np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL); Assert.AreEqual("the Adams Stokes disease", realiser.realise(np).Realisation); //change default infl for this word asd.setDefaultInflectionalVariant(Inflection.REGULAR); Assert.AreEqual("the Adams Stokes diseases", realiser.realise(np).Realisation); }
public virtual void testComplexSentence3() { setUp(); s1 = phraseFactory.createClause(); s1.setSubject(woman); s1.setVerb("kiss"); s1.setObject(man); PhraseElement _man = phraseFactory.createNounPhrase("the", "man"); //$NON-NLS-1$ //$NON-NLS-2$ s3 = phraseFactory.createClause(); s3.setSubject(_man); s3.setVerb("give"); NPPhraseSpec flower = phraseFactory.createNounPhrase("flower"); //$NON-NLS-1$ NPPhraseSpec john = phraseFactory.createNounPhrase("John"); //$NON-NLS-1$ john.setFeature(Feature.POSSESSIVE, true); flower.setSpecifier(john); s3.setObject(flower); PhraseElement _woman = phraseFactory.createNounPhrase("the", "woman"); //$NON-NLS-1$ //$NON-NLS-2$ s3.setIndirectObject(_woman); // the coordinate sentence allows us to raise and lower complementiser CoordinatedPhraseElement coord2 = new CoordinatedPhraseElement(s1, s3); coord2.setFeature(Feature.TENSE, Tense.PAST); realiser.DebugMode = true; Assert.AreEqual("the woman kissed the man and the man gave the woman John's flower", realiser.realise(coord2).Realisation); //$NON-NLS-1$ }
public virtual void testHowPredicateQuestion() { SPhraseSpec test = phraseFactory.createClause(); NPPhraseSpec subject = phraseFactory.createNounPhrase("You"); subject.setFeature(Feature.PRONOMINAL, true); subject.setFeature(Feature.PERSON, Person.SECOND); test.setSubject(subject); test.setVerb("be"); test.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.HOW_PREDICATE); test.setFeature(Feature.TENSE, Tense.PRESENT); string result = realiser.realiseSentence(test); Assert.AreEqual("How are you?", result); }
public virtual void correctPluralizationWithPossessives() { NPPhraseSpec sisterNP = nlgFactory.createNounPhrase("sister"); NLGElement word = nlgFactory.createInflectedWord("Albert Einstein", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)); word.setFeature(LexicalFeature.PROPER, true); NPPhraseSpec possNP = nlgFactory.createNounPhrase(word); possNP.setFeature(Feature.POSSESSIVE, true); sisterNP.setSpecifier(possNP); Assert.AreEqual("Albert Einstein's sister", realiser.realise(sisterNP).Realisation); sisterNP.Plural = true; Assert.AreEqual("Albert Einstein's sisters", realiser.realise(sisterNP).Realisation); sisterNP.Plural = false; possNP.setFeature(LexicalFeature.GENDER, Gender.MASCULINE); possNP.setFeature(Feature.PRONOMINAL, true); Assert.AreEqual("his sister", realiser.realise(sisterNP).Realisation); sisterNP.Plural = true; Assert.AreEqual("his sisters", realiser.realise(sisterNP).Realisation); }
/** * Sets the np features. * * @param wp * The xml Noun Phrase object. * @param p * the NPPhraseSpec object to get the features. */ private void setNPFeatures(wrapper.XmlNPPhraseSpec wp, NPPhraseSpec p) { if (wp.NUMBER != null) { // map number feature from wrapper ~NumberAgr to actual NumberAgr string numString = wp.NUMBER.ToString(); Enum.TryParse(numString, out NumberAgreement simplenlgNum); // p.setFeature(Feature.NUMBER, wp.getNUMBER()); p.setFeature(Feature.NUMBER, simplenlgNum); } if (wp.PERSON != null) { // map person feature from wrapper Person to actual Person string perString = wp.PERSON.ToString(); Enum.TryParse(perString, out Person simplenlgPers); p.setFeature(Feature.PERSON, simplenlgPers); } if (wp.GENDER != null) { // map gender feature from wrapper Gender to actual Gender string genString = wp.GENDER.ToString(); Enum.TryParse(genString, out Gender simplenlgGen); p.setFeature(LexicalFeature.GENDER, simplenlgGen); } p.setFeature(Feature.ELIDED, wp.ELIDED); p.setFeature(Feature.POSSESSIVE, wp.POSSESSIVE); p.setFeature(Feature.PRONOMINAL, wp.PRONOMINAL); }
public virtual void testAgreement() { // basic agreement NPPhraseSpec np = phraseFactory.createNounPhrase("dog"); //$NON-NLS-1$ np.setSpecifier("the"); //$NON-NLS-1$ np.addPreModifier("angry"); //$NON-NLS-1$ PhraseElement _s1 = phraseFactory.createClause(np, "chase", "John"); //$NON-NLS-1$ //$NON-NLS-2$ Assert.AreEqual("the angry dog chases John", realiser.realise(_s1).Realisation); //$NON-NLS-1$ // plural np = phraseFactory.createNounPhrase("dog"); //$NON-NLS-1$ np.setSpecifier("the"); //$NON-NLS-1$ np.addPreModifier("angry"); //$NON-NLS-1$ np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL); _s1 = phraseFactory.createClause(np, "chase", "John"); //$NON-NLS-1$ //$NON-NLS-2$ Assert.AreEqual("the angry dogs chase John", realiser.realise(_s1).Realisation); //$NON-NLS-1$ // test agreement with "there is" np = phraseFactory.createNounPhrase("dog"); //$NON-NLS-1$ np.addPreModifier("angry"); //$NON-NLS-1$ np.setFeature(Feature.NUMBER, NumberAgreement.SINGULAR); np.setSpecifier("a"); //$NON-NLS-1$ PhraseElement _s2 = phraseFactory.createClause("there", "be", np); //$NON-NLS-1$ //$NON-NLS-2$ Assert.AreEqual("there is an angry dog", realiser.realise(_s2).Realisation); //$NON-NLS-1$ // plural with "there" np = phraseFactory.createNounPhrase("dog"); //$NON-NLS-1$ np.addPreModifier("angry"); //$NON-NLS-1$ np.setSpecifier("a"); //$NON-NLS-1$ np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL); _s2 = phraseFactory.createClause("there", "be", np); //$NON-NLS-1$ //$NON-NLS-2$ Assert.AreEqual("there are some angry dogs", realiser.realise(_s2).Realisation); //$NON-NLS-1$ }
public override void setUp() { base.setUp(); // the woman kisses the man s1 = phraseFactory.createClause(); s1.setSubject(woman); s1.VerbPhrase = kiss; s1.setObject(man); // there is the dog on the rock s2 = phraseFactory.createClause(); s2.setSubject("there"); //$NON-NLS-1$ s2.setVerb("be"); //$NON-NLS-1$ s2.setObject(dog); s2.addPostModifier(onTheRock); // the man gives the woman John's flower s3 = phraseFactory.createClause(); s3.setSubject(man); s3.VerbPhrase = give; NPPhraseSpec flower = phraseFactory.createNounPhrase("flower"); //$NON-NLS-1$ NPPhraseSpec john = phraseFactory.createNounPhrase("John"); //$NON-NLS-1$ john.setFeature(Feature.POSSESSIVE, true); flower.setFeature(InternalFeature.SPECIFIER, john); s3.setObject(flower); s3.setIndirectObject(woman); s4 = phraseFactory.createClause(); s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$ s4.addFrontModifier("tomorrow"); //$NON-NLS-1$ CoordinatedPhraseElement subject = phraseFactory.createCoordinatedPhrase(phraseFactory.createNounPhrase("Jane"), phraseFactory.createNounPhrase("Andrew")); //$NON-NLS-1$ - $NON-NLS-1$ s4.setSubject(subject); PhraseElement pick = phraseFactory.createVerbPhrase("pick up"); //$NON-NLS-1$ s4.VerbPhrase = pick; s4.setObject("the balls"); //$NON-NLS-1$ s4.addPostModifier("in the shop"); //$NON-NLS-1$ s4.setFeature(Feature.TENSE, Tense.FUTURE); }
public virtual void testSingularNounsBelongingToAPlural() { SPhraseSpec sent = phraseFactory.createClause("I", "clean"); sent.setFeature(Feature.TENSE, Tense.PAST); NPPhraseSpec obj = phraseFactory.createNounPhrase("car"); obj.Plural = false; NPPhraseSpec possessor = phraseFactory.createNounPhrase("the", "parent"); possessor.Plural = true; possessor.setFeature(Feature.POSSESSIVE, true); obj.setSpecifier(possessor); sent.setObject(obj); Assert.AreEqual("I cleaned the parents' car", realiser.realise(sent).Realisation); //$NON-NLS-1$ }
public virtual void testPluralNounsBelongingToASingular() { SPhraseSpec sent = phraseFactory.createClause("I", "count up"); sent.setFeature(Feature.TENSE, Tense.PAST); NPPhraseSpec obj = phraseFactory.createNounPhrase("digit"); obj.Plural = true; NPPhraseSpec possessor = phraseFactory.createNounPhrase("the", "box"); possessor.Plural = false; possessor.setFeature(Feature.POSSESSIVE, true); obj.setSpecifier(possessor); sent.setObject(obj); Assert.AreEqual("I counted up the box's digits", realiser.realise(sent).Realisation); //$NON-NLS-1$ }
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 uncountInflectionalVariantTest() { WordElement calc = (WordElement)factory.createWord("calcification", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)); NPPhraseSpec theCalc = factory.createNounPhrase("the", calc); theCalc.setFeature(Feature.NUMBER, NumberAgreement.PLURAL); string r1 = realiser.realise(theCalc).Realisation; Assert.AreEqual("the calcifications", r1); calc.setDefaultInflectionalVariant(Inflection.UNCOUNT); NPPhraseSpec theCalc2 = factory.createNounPhrase("the", calc); theCalc2.setFeature(Feature.NUMBER, NumberAgreement.PLURAL); string r2 = realiser.realise(theCalc2).Realisation; Assert.AreEqual("the calcification", r2); }
public virtual void spellingVariantWithInflectionTest() { WordElement word = lexicon.getWord("formalization"); IList <string> spellVars = word.getFeatureAsStringList(LexicalFeature.SPELL_VARS); Assert.IsTrue(spellVars.Contains("formalisation")); Assert.AreEqual(Inflection.REGULAR, word.getDefaultInflectionalVariant()); // create with default spelling NPPhraseSpec np = factory.createNounPhrase("the", word); np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL); Assert.AreEqual("the formalizations", realiser.realise(np).Realisation); // reset spell var word.DefaultSpellingVariant = "formalisation"; Assert.AreEqual("the formalisations", realiser.realise(np).Realisation); }
public virtual void testPronominalisation2() { // Ehud - added extra pronominalisation tests NPPhraseSpec pro = phraseFactory.createNounPhrase("Mary"); pro.setFeature(Feature.PRONOMINAL, true); pro.setFeature(Feature.PERSON, Person.FIRST); SPhraseSpec sent = phraseFactory.createClause(pro, "like", "John"); Assert.AreEqual("I like John.", realiser.realiseSentence(sent)); pro = phraseFactory.createNounPhrase("Mary"); pro.setFeature(Feature.PRONOMINAL, true); pro.setFeature(Feature.PERSON, Person.SECOND); sent = phraseFactory.createClause(pro, "like", "John"); Assert.AreEqual("You like John.", realiser.realiseSentence(sent)); pro = phraseFactory.createNounPhrase("Mary"); pro.setFeature(Feature.PRONOMINAL, true); pro.setFeature(Feature.PERSON, Person.THIRD); pro.setFeature(LexicalFeature.GENDER, Gender.FEMININE); sent = phraseFactory.createClause(pro, "like", "John"); Assert.AreEqual("She likes John.", realiser.realiseSentence(sent)); pro = phraseFactory.createNounPhrase("Mary"); pro.setFeature(Feature.PRONOMINAL, true); pro.setFeature(Feature.PERSON, Person.FIRST); pro.Plural = true; sent = phraseFactory.createClause(pro, "like", "John"); Assert.AreEqual("We like John.", realiser.realiseSentence(sent)); pro = phraseFactory.createNounPhrase("Mary"); pro.setFeature(Feature.PRONOMINAL, true); pro.setFeature(Feature.PERSON, Person.SECOND); pro.Plural = true; sent = phraseFactory.createClause(pro, "like", "John"); Assert.AreEqual("You like John.", realiser.realiseSentence(sent)); pro = phraseFactory.createNounPhrase("Mary"); pro.setFeature(Feature.PRONOMINAL, true); pro.setFeature(Feature.PERSON, Person.THIRD); pro.Plural = true; pro.setFeature(LexicalFeature.GENDER, Gender.FEMININE); sent = phraseFactory.createClause(pro, "like", "John"); Assert.AreEqual("They like John.", realiser.realiseSentence(sent)); pro = phraseFactory.createNounPhrase("John"); pro.setFeature(Feature.PRONOMINAL, true); pro.setFeature(Feature.PERSON, Person.FIRST); sent = phraseFactory.createClause("Mary", "like", pro); Assert.AreEqual("Mary likes me.", realiser.realiseSentence(sent)); pro = phraseFactory.createNounPhrase("John"); pro.setFeature(Feature.PRONOMINAL, true); pro.setFeature(Feature.PERSON, Person.SECOND); sent = phraseFactory.createClause("Mary", "like", pro); Assert.AreEqual("Mary likes you.", realiser.realiseSentence(sent)); pro = phraseFactory.createNounPhrase("John"); pro.setFeature(Feature.PRONOMINAL, true); pro.setFeature(Feature.PERSON, Person.THIRD); pro.setFeature(LexicalFeature.GENDER, Gender.MASCULINE); sent = phraseFactory.createClause("Mary", "like", pro); Assert.AreEqual("Mary likes him.", realiser.realiseSentence(sent)); pro = phraseFactory.createNounPhrase("John"); pro.setFeature(Feature.PRONOMINAL, true); pro.setFeature(Feature.PERSON, Person.FIRST); pro.Plural = true; sent = phraseFactory.createClause("Mary", "like", pro); Assert.AreEqual("Mary likes us.", realiser.realiseSentence(sent)); pro = phraseFactory.createNounPhrase("John"); pro.setFeature(Feature.PRONOMINAL, true); pro.setFeature(Feature.PERSON, Person.SECOND); pro.Plural = true; sent = phraseFactory.createClause("Mary", "like", pro); Assert.AreEqual("Mary likes you.", realiser.realiseSentence(sent)); pro = phraseFactory.createNounPhrase("John"); pro.setFeature(Feature.PRONOMINAL, true); pro.setFeature(Feature.PERSON, Person.THIRD); pro.setFeature(LexicalFeature.GENDER, Gender.MASCULINE); pro.Plural = true; sent = phraseFactory.createClause("Mary", "like", pro); Assert.AreEqual("Mary likes them.", realiser.realiseSentence(sent)); }