Ejemplo n.º 1
0
 def testDwight(self):
     # Rachel Dwight's test
     self.phraseFactory.setLexicon(self.lexicon)
     noun4 = self.phraseFactory.createNounPhrase("FGFR3 gene in every cell")
     noun4.setSpecifier("the")
     prep1 = self.phraseFactory.createPrepositionPhrase("of", noun4)
     noun1 = self.phraseFactory.createNounPhrase("the", "patient's mother")
     noun2 = self.phraseFactory.createNounPhrase("the", "patient's father")
     noun3 = self.phraseFactory.createNounPhrase("changed copy")
     noun3.addPreModifier("one")
     noun3.addComplement(prep1)
     coordNoun1 = CoordinatedPhraseElement(noun1, noun2)
     coordNoun1.setConjunction("or")
     verbPhrase1 = self.phraseFactory.createVerbPhrase("have")
     verbPhrase1.setFeature(Feature.TENSE, Tense.PRESENT)
     sentence1 = self.phraseFactory.createClause(coordNoun1, verbPhrase1,
                                                 noun3)
     #realiser.setDebugMode(True)
     string = "the patient's mother or the patient's father has one changed copy of the FGFR3 gene in every cell"
     self.assertEqual(string,
                      self.realiser.realise(sentence1).getRealisation())
     # Rachel's second test
     noun3 = self.phraseFactory.createNounPhrase("a", "gene test")
     noun2 = self.phraseFactory.createNounPhrase("an", "LDL test")
     noun1 = self.phraseFactory.createNounPhrase("the", "clinic")
     verbPhrase1 = self.phraseFactory.createVerbPhrase("perform")
     coord1 = CoordinatedPhraseElement(noun2, noun3)
     sentence1 = self.phraseFactory.createClause(noun1, verbPhrase1, coord1)
     sentence1.setFeature(Feature.TENSE, Tense.PAST)
     self.assertEqual("the clinic performed an LDL test and a gene test", \
             self.realiser.realise(sentence1).getRealisation())
Ejemplo n.º 2
0
 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))