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 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 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()); }
public virtual void stringElementAsHeadTest() { NPPhraseSpec np = phraseFactory.createNounPhrase(); np.setHead(phraseFactory.createStringElement("dogs and cats")); np.setSpecifier(phraseFactory.createWord("the", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.DETERMINER))); Assert.AreEqual("the dogs and cats", realiser.realise(np).Realisation); }
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 virtual void dwightTest() { phraseFactory.Lexicon = lexicon; NPPhraseSpec noun4 = phraseFactory.createNounPhrase("FGFR3 gene in every cell"); //$NON-NLS-1$ noun4.setSpecifier("the"); PhraseElement prep1 = phraseFactory.createPrepositionPhrase("of", noun4); //$NON-NLS-1$ PhraseElement noun1 = phraseFactory.createNounPhrase("the", "patient's mother"); //$NON-NLS-1$ //$NON-NLS-2$ PhraseElement noun2 = phraseFactory.createNounPhrase("the", "patient's father"); //$NON-NLS-1$ //$NON-NLS-2$ PhraseElement noun3 = phraseFactory.createNounPhrase("changed copy"); //$NON-NLS-1$ noun3.addPreModifier("one"); //$NON-NLS-1$ noun3.addComplement(prep1); CoordinatedPhraseElement coordNoun1 = new CoordinatedPhraseElement(noun1, noun2); coordNoun1.Conjunction = "or"; //$NON-NLS-1$ PhraseElement verbPhrase1 = phraseFactory.createVerbPhrase("have"); //$NON-NLS-1$ verbPhrase1.setFeature(Feature.TENSE, Tense.PRESENT); PhraseElement sentence1 = phraseFactory.createClause(coordNoun1, verbPhrase1, noun3); realiser.DebugMode = true; Assert.AreEqual( "the patient's mother or the patient's father has one changed copy of the FGFR3 gene in every cell", realiser.realise(sentence1).Realisation); //$NON-NLS-1$ noun3 = phraseFactory.createNounPhrase("a", "gene test"); //$NON-NLS-1$ //$NON-NLS-2$ noun2 = phraseFactory.createNounPhrase("an", "LDL test"); //$NON-NLS-1$ //$NON-NLS-2$ noun1 = phraseFactory.createNounPhrase("the", "clinic"); //$NON-NLS-1$ //$NON-NLS-2$ verbPhrase1 = phraseFactory.createVerbPhrase("perform"); //$NON-NLS-1$ CoordinatedPhraseElement coord1 = new CoordinatedPhraseElement(noun2, noun3); sentence1 = phraseFactory.createClause(noun1, verbPhrase1, coord1); sentence1.setFeature(Feature.TENSE, Tense.PAST); Assert.AreEqual("the clinic performed an LDL test and a gene test", realiser.realise(sentence1).Realisation); //$NON-NLS-1$ }
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$ }
/** * Creates a noun phrase with the given specifier and subject. * * @param specifier * the specifier or determiner for the noun phrase. * @param noun * the subject of the phrase. * @return a <code>NPPhraseSpec</code> representing this phrase. */ public virtual NPPhraseSpec createNounPhrase(object specifier, object noun) { if (noun is NPPhraseSpec) { return((NPPhraseSpec)noun); } NPPhraseSpec phraseElement = new NPPhraseSpec(this); NLGElement nounElement = createNLGElement(noun, new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)); setPhraseHead(phraseElement, nounElement); if (specifier != null) { phraseElement.setSpecifier(specifier); } return(phraseElement); }
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); }
public virtual void whiteSpaceNPTest() { SPhraseSpec senSpec = phraseFactory.createClause(); NPPhraseSpec firstNoun = phraseFactory.createNounPhrase(); firstNoun.setDeterminer("the"); firstNoun.setNoun("Nasdaq"); senSpec.addComplement(firstNoun); senSpec.addComplement(phraseFactory.createStringElement(" rose steadily during ")); NPPhraseSpec secondNoun = phraseFactory.createNounPhrase(); secondNoun.setSpecifier("early"); secondNoun.setNoun("trading"); senSpec.addComplement(secondNoun); senSpec.addComplement(phraseFactory.createStringElement(" , however it plummeted due to")); NPPhraseSpec thirdNoun = phraseFactory.createNounPhrase(); thirdNoun.setSpecifier("a"); thirdNoun.setNoun("shock"); senSpec.addComplement(thirdNoun); senSpec.addComplement(phraseFactory.createStringElement(" after ")); NPPhraseSpec fourthNoun = phraseFactory.createNounPhrase(); fourthNoun.setNoun("IBM"); senSpec.addComplement(fourthNoun); senSpec.addComplement(phraseFactory.createStringElement("announced poor ")); NPPhraseSpec fifthNoun = phraseFactory.createNounPhrase(); fifthNoun.setSpecifier("first quarter"); fifthNoun.setNoun("results"); fifthNoun.Plural = true; senSpec.addComplement(fifthNoun); DocumentElement completeSen = phraseFactory.createSentence(); completeSen.addComponent(senSpec); Assert.AreEqual( "The Nasdaq rose steadily during early trading, however it plummeted due to a shock after IBM announced poor first quarter results.", realiser.realise(completeSen).Realisation); }
/** * 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); }