def testData2TextTest(self): # Data2Text tests # test OK to have number at end of sentence p = self.phraseFactory.createClause("the dog", "weigh", "12") self.assertEqual("The dog weighes 12.", self.realiser.realiseSentence(p)) # test OK to have "there be" sentence with "there" as a StringElement dataDropout2 = self.phraseFactory.createNLGElement("data dropouts") dataDropout2.setPlural(True) sentence2 = self.phraseFactory.createClause() sentence2.setSubject(self.phraseFactory.createStringElement("there")) sentence2.setVerb("be") sentence2.setObject(dataDropout2) self.assertEqual("There are data dropouts.", self.realiser.realiseSentence(sentence2)) # test OK to have gerund form verb weather1 = self.phraseFactory.createClause("SE 10-15", "veer", "S 15-20") weather1.setFeature(Feature.FORM, Form.GERUND) self.assertEqual("SE 10-15 veering S 15-20.", self.realiser.realiseSentence(weather1)) # test OK to have subject only weather2 = self.phraseFactory.createClause("cloudy and misty", "be", "XXX") weather2.getVerbPhrase().setFeature(Feature.ELIDED, True) self.assertEqual("Cloudy and misty.", self.realiser.realiseSentence(weather2)) # test OK to have VP only weather3 = self.phraseFactory.createClause("S 15-20", "increase", "20-25") weather3.setFeature(Feature.FORM, Form.GERUND) weather3.getSubject().setFeature(Feature.ELIDED, True) self.assertEqual("Increasing 20-25.", self.realiser.realiseSentence(weather3)) # conjoined test weather4 = self.phraseFactory.createClause("S 20-25", "back", "SSE") weather4.setFeature(Feature.FORM, Form.GERUND) weather4.getSubject().setFeature(Feature.ELIDED, True) coord = CoordinatedPhraseElement() coord.addCoordinate(weather1) coord.addCoordinate(weather3) coord.addCoordinate(weather4) coord.setConjunction("then") self.assertEqual( "SE 10-15 veering S 15-20, increasing 20-25 then backing SSE.", self.realiser.realiseSentence(coord)) # no verb weather5 = self.phraseFactory.createClause("rain", None, "likely") self.assertEqual("Rain likely.", self.realiser.realiseSentence(weather5))
def testAdj(self): # form the adjphrase "incredibly salacious" self.salacious.addPreModifier( self.phraseFactory.createAdverbPhrase("incredibly")) self.assertEqual( "incredibly salacious", self.realiser.realise(self.salacious).getRealisation()) # form the adjphrase "incredibly beautiful" self.beautiful.addPreModifier("amazingly") self.assertEqual( "amazingly beautiful", self.realiser.realise(self.beautiful).getRealisation()) # coordinate the two aps coordap = CoordinatedPhraseElement(self.salacious, self.beautiful) self.assertEqual("incredibly salacious and amazingly beautiful", \ self.realiser.realise(coordap).getRealisation()) # changing the inner conjunction coordap.setFeature(Feature.CONJUNCTION, "or") self.assertEqual("incredibly salacious or amazingly beautiful", \ self.realiser.realise(coordap).getRealisation()) # coordinate self with a new AdjPhraseSpec coord2 = CoordinatedPhraseElement(coordap, self.stunning) self.assertEqual("incredibly salacious or amazingly beautiful and stunning", \ self.realiser.realise(coord2).getRealisation()) # add a premodifier the coordinate phrase, yielding # "seriously and undeniably incredibly salacious or amazingly beautiful # and stunning" preMod = CoordinatedPhraseElement(StringElement("seriously"), StringElement("undeniably")) coord2.addPreModifier(preMod) self.assertEqual("seriously and undeniably incredibly salacious or amazingly beautiful and stunning", \ self.realiser.realise(coord2).getRealisation()) # adding a coordinate rather than coordinating should give a different # result coordap.addCoordinate(self.stunning) self.assertEqual("incredibly salacious, amazingly beautiful or stunning", \ self.realiser.realise(coordap).getRealisation())