예제 #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())
예제 #2
0
 def testCoordination(self):
     cnp1 = CoordinatedPhraseElement(self.dog,  self.woman)
     # simple coordination
     self.assertEqual("the dog and the woman", self.realiser.realise(cnp1).getRealisation())
     # simple coordination with complementation of entire coordinate NP
     cnp1.addComplement(self.behindTheCurtain)
     self.assertEqual("the dog and the woman behind the curtain", \
               self.realiser.realise(cnp1).getRealisation())
예제 #3
0
 def testComplexSentence1(self):
     self.setUp()
     # the man's giving the woman John's flower upset Peter
     complexS = self.phraseFactory.createClause()
     complexS.setVerbPhrase(self.phraseFactory.createVerbPhrase("upset"))
     complexS.setFeature(Feature.TENSE, Tense.PAST)
     complexS.setObject(self.phraseFactory.createNounPhrase("Peter"))
     self.s3.setFeature(Feature.PERFECT, True)
     complexS.setSubject(self.s3)
     # check the realisation: subject should be genitive
     self.assertEqual("the man's having given the woman John's flower upset Peter", \
             self.realiser.realise(complexS).getRealisation())
     self.setUp()
     # coordinate sentences in subject position
     s5 = self.phraseFactory.createClause()
     s5.setSubject(self.phraseFactory.createNounPhrase("some", "person"))
     s5.setVerbPhrase(self.phraseFactory.createVerbPhrase("stroke"))
     s5.setObject(self.phraseFactory.createNounPhrase("the", "cat"))
     coord = CoordinatedPhraseElement(self.s3, s5)
     complexS = self.phraseFactory.createClause()
     complexS.setVerbPhrase(self.phraseFactory.createVerbPhrase("upset"))
     complexS.setFeature(Feature.TENSE, Tense.PAST)
     complexS.setObject(self.phraseFactory.createNounPhrase("Peter"))
     complexS.setSubject(coord)
     self.s3.setFeature(Feature.PERFECT, True)
     self.assertEqual("the man's having given the woman John's flower " \
             + "and some person's stroking the cat upset Peter", \
             self.realiser.realise(complexS).getRealisation())
     self.setUp()
     # now subordinate the complex sentence
     # coord.setClauseStatus(SPhraseSpec.ClauseType.MAIN)
     s6 = self.phraseFactory.createClause()
     s6.setVerbPhrase(self.phraseFactory.createVerbPhrase("tell"))
     s6.setFeature(Feature.TENSE, Tense.PAST)
     s6.setSubject(self.phraseFactory.createNounPhrase("the", "boy"))
     # ER - switched indirect and direct object
     indirect = self.phraseFactory.createNounPhrase("every", "girl")
     s6.setIndirectObject(indirect)
     complexS = self.phraseFactory.createClause()
     complexS.setVerbPhrase(self.phraseFactory.createVerbPhrase("upset"))
     complexS.setFeature(Feature.TENSE, Tense.PAST)
     complexS.setObject(self.phraseFactory.createNounPhrase("Peter"))
     s6.setObject(complexS)
     coord = CoordinatedPhraseElement(self.s3, s5)
     complexS.setSubject(coord)
     self.s3.setFeature(Feature.PERFECT, True)
     self.assertEqual("the boy told every girl that the man's having given the woman " \
                     + "John's flower and some person's stroking the cat " \
                     + "upset Peter", self.realiser.realise(s6).getRealisation())
예제 #4
0
 def testForm2(self):
     # set s4 as subject of a new sentence
     temp = self.phraseFactory.createClause(self.s4, "be", "recommended")
     self.assertEqual("however tomorrow Jane and Andrew's picking up the " + \
             "balls in the shop is recommended", \
             self.realiser.realise(temp).getRealisation())
     # compose self with a new sentence
     # ER - switched direct and indirect object in sentence
     temp2 = self.phraseFactory.createClause("I", "tell", temp)
     temp2.setFeature(Feature.TENSE, Tense.FUTURE)
     indirectObject = self.phraseFactory.createNounPhrase("John")
     temp2.setIndirectObject(indirectObject)
     self.assertEqual("I will tell John that however tomorrow Jane and " +  \
             "Andrew's picking up the balls in the shop is recommended", \
             self.realiser.realise(temp2).getRealisation())
     # turn s4 to imperative and put it in indirect object position
     self.s4 = self.phraseFactory.createClause()
     self.s4.setFeature(Feature.CUE_PHRASE, "however")
     self.s4.addFrontModifier("tomorrow")
     subject =  CoordinatedPhraseElement(self.phraseFactory.createNounPhrase("Jane"), \
             self.phraseFactory.createNounPhrase("Andrew"))
     self.s4.setSubject(subject)
     pick = self.phraseFactory.createVerbPhrase("pick up")
     self.s4.setVerbPhrase(pick)
     self.s4.setObject("the balls")
     self.s4.addPostModifier("in the shop")
     self.s4.setFeature(Feature.TENSE, Tense.FUTURE)
     self.s4.setFeature(Feature.FORM, Form.IMPERATIVE)
     temp2 = self.phraseFactory.createClause("I", "tell", self.s4)
     indirectObject = self.phraseFactory.createNounPhrase("John")
     temp2.setIndirectObject(indirectObject)
     temp2.setFeature(Feature.TENSE, Tense.FUTURE)
     self.assertEqual("I will tell John however to pick up the balls " \
             + "in the shop tomorrow", self.realiser.realise(temp2).getRealisation())
예제 #5
0
 def testComplementation(self):
     self.inTheRoom.clearComplements()
     self.inTheRoom.addComplement(CoordinatedPhraseElement( \
             self.phraseFactory.createNounPhrase("the", "room"),
             self.phraseFactory.createNounPhrase("a", "car")))
     self.assertEqual("in the room and a car", \
             self.realiser.realise(self.inTheRoom).getRealisation())
예제 #6
0
 def testComplementation2(self):
     # give the woman the dog
     self.woman.setFeature(InternalFeature.DISCOURSE_FUNCTION,
                           DiscourseFunction.INDIRECT_OBJECT)
     self.dog.setFeature(InternalFeature.DISCOURSE_FUNCTION,
                         DiscourseFunction.OBJECT)
     self.give.clearComplements()
     self.give.addComplement(self.dog)
     self.give.addComplement(self.woman)
     self.assertEqual("gives the woman the dog", \
         self.realiser.realise(self.give).getRealisation())
     # add a few premodifiers and postmodifiers
     self.give.addPreModifier("slowly")
     self.give.addPostModifier(self.behindTheCurtain)
     self.give.addPostModifier(self.inTheRoom)
     self.assertEqual("slowly gives the woman the dog behind the curtain in the room", \
             self.realiser.realise(self.give).getRealisation())
     # reset the arguments
     self.give.clearComplements()
     self.give.addComplement(self.dog)
     womanBoy = CoordinatedPhraseElement(self.woman, self.boy)
     womanBoy.setFeature(InternalFeature.DISCOURSE_FUNCTION,
                         DiscourseFunction.INDIRECT_OBJECT)
     self.give.addComplement(womanBoy)
     # if we unset the passive, we should get the indirect objects
     # they won't be coordinated
     self.give.setFeature(Feature.PASSIVE, False)
     self.assertEqual("slowly gives the woman and the boy the dog behind the curtain in the room", \
             self.realiser.realise(self.give).getRealisation())
     # set them to a coordinate instead
     # set ONLY the complement INDIRECT_OBJECT, leaves OBJECT intact
     self.give.clearComplements()
     self.give.addComplement(womanBoy)
     self.give.addComplement(self.dog)
     complements = self.give.getFeatureAsElementList(
         InternalFeature.COMPLEMENTS)
     indirectCount = 0
     for eachElement in complements:
         if DiscourseFunction.INDIRECT_OBJECT == eachElement.getFeature(
                 InternalFeature.DISCOURSE_FUNCTION):
             indirectCount += 1
     self.assertEqual(1, indirectCount)  # only one indirect object
     # where
     # there were two before
     self.assertEqual("slowly gives the woman and the boy the dog behind the curtain in the room", \
             self.realiser.realise(self.give).getRealisation())
예제 #7
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))
예제 #8
0
 def testComplexSentence3(self):
     self.setUp()
     self.s1 = self.phraseFactory.createClause()
     self.s1.setSubject(self.woman)
     self.s1.setVerb("kiss")
     self.s1.setObject(self.man)
     _man = self.phraseFactory.createNounPhrase("the", "man")
     self.s3 = self.phraseFactory.createClause()
     self.s3.setSubject(_man)
     self.s3.setVerb("give")
     flower = self.phraseFactory.createNounPhrase("flower")
     john = self.phraseFactory.createNounPhrase("John")
     john.setFeature(Feature.POSSESSIVE, True)
     flower.setSpecifier(john)
     self.s3.setObject(flower)
     _woman = self.phraseFactory.createNounPhrase("the", "woman")
     self.s3.setIndirectObject(_woman)
     # the coordinate sentence allows us to raise and lower complementiser
     coord2 = CoordinatedPhraseElement(self.s1, self.s3)
     coord2.setFeature(Feature.TENSE, Tense.PAST)
     #self.realiser.setDebugMode(True)
     self.assertEqual("the woman kissed the man and the man gave the woman John's flower", \
             self.realiser.realise(coord2).getRealisation())
예제 #9
0
 def testCoordination(self):
     # simple coordination
     coord1 = CoordinatedPhraseElement(self.inTheRoom,
                                       self.behindTheCurtain)
     self.assertEqual("in the room and behind the curtain", \
             self.realiser.realise(coord1).getRealisation())
     # change the conjunction
     coord1.setFeature(Feature.CONJUNCTION, "or")
     self.assertEqual("in the room or behind the curtain", \
             self.realiser.realise(coord1).getRealisation())
     # new coordinate
     coord2 = CoordinatedPhraseElement(self.onTheRock, self.underTheTable)
     coord2.setFeature(Feature.CONJUNCTION, "or")
     self.assertEqual("on the rock or under the table", \
             self.realiser.realise(coord2).getRealisation())
     # coordinate two coordinates
     coord3 = CoordinatedPhraseElement(coord1, coord2)
     text = self.realiser.realise(coord3).getRealisation()
     self.assertEqual(
         "in the room or behind the curtain and on the rock or under the table",
         text)
예제 #10
0
 def testPossessiveCoordinate(self):
     # simple coordination
     cnp2 = CoordinatedPhraseElement(self.dog, self.woman)
     self.assertEqual("the dog and the woman", self.realiser.realise(cnp2).getRealisation())
     # set possessive -- wide-scope by default
     cnp2.setFeature(Feature.POSSESSIVE, True)
     self.assertEqual("the dog and the woman's", self.realiser.realise(cnp2).getRealisation())
     # set possessive with pronoun
     self.dog.setFeature(Feature.PRONOMINAL, True)
     self.dog.setFeature(Feature.POSSESSIVE, True)
     cnp2.setFeature(Feature.POSSESSIVE, True)
     self.assertEqual("its and the woman's", self.realiser.realise(cnp2).getRealisation())
예제 #11
0
 def testComplementiserFeatureInACoordinatePhrase_PastTense(self):
     self.phraseFactory.setLexicon(self.lexicon)
     dave = self.phraseFactory.createWord("Dave Bus", LexicalCategory.NOUN)
     albert = self.phraseFactory.createWord("Albert", LexicalCategory.NOUN)
     coord1 = CoordinatedPhraseElement(dave, albert)
     born = self.phraseFactory.createClause(coord1, "be", "born")
     born.setFeature(Feature.TENSE,Tense.PAST)
     born.addPostModifier("in")
     born.setFeature(Feature.COMPLEMENTISER, "which")
     theHouse = self.phraseFactory.createNounPhrase("the", "house")
     theHouse.addComplement(born)
     clause = self.phraseFactory.createClause(theHouse, "be", \
             self.phraseFactory.createPrepositionPhrase("in", "Edinburgh"))
     sentence = self.docFactory.createSentence(clause)
     realised = self.realiser.realise(sentence)
     # Retrieve the realisation and dump it to the console
     self.assertEqual("The house which Dave Bus and Albert were born in is in Edinburgh.", \
             realised.getRealisation())
예제 #12
0
 def testForm(self):
     # check the getter method
     self.assertEqual(Form.NORMAL, self.s1.getFeatureAsElement( \
             InternalFeature.VERB_PHRASE).getFeature(Feature.FORM))
     # infinitive
     self.s1.setFeature(Feature.FORM, Form.INFINITIVE)
     self.assertEqual("to kiss the man",
                      self.realiser.realise(self.s1).getRealisation())
     # gerund with "there"
     self.s2.setFeature(Feature.FORM, Form.GERUND)
     self.assertEqual("there being the dog on the rock",
                      self.realiser.realise(self.s2).getRealisation())
     # gerund with possessive
     self.s3.setFeature(Feature.FORM, Form.GERUND)
     self.assertEqual("the man's giving the woman John's flower", \
             self.realiser.realise(self.s3).getRealisation())
     # imperative
     self.s3.setFeature(Feature.FORM, Form.IMPERATIVE)
     self.assertEqual("give the woman John's flower",
                      self.realiser.realise(self.s3).getRealisation())
     # subordinating the imperative to a verb should turn it to infinitive
     self.say.addComplement(self.s3)
     self.assertEqual("says to give the woman John's flower", \
             self.realiser.realise(self.say).getRealisation())
     # imperative -- case II
     self.s4.setFeature(Feature.FORM, Form.IMPERATIVE)
     self.assertEqual("however tomorrow pick up the balls in the shop", \
             self.realiser.realise(self.s4).getRealisation())
     # infinitive -- case II
     self.s4 = self.phraseFactory.createClause()
     self.s4.setFeature(Feature.CUE_PHRASE, "however")
     self.s4.addFrontModifier("tomorrow")
     subject = CoordinatedPhraseElement(self.phraseFactory.createNounPhrase("Jane"), \
             self.phraseFactory.createNounPhrase("Andrew"))
     self.s4.setFeature(InternalFeature.SUBJECTS, subject)
     pick = self.phraseFactory.createVerbPhrase("pick up")
     self.s4.setFeature(InternalFeature.VERB_PHRASE, pick)
     self.s4.setObject("the balls")
     self.s4.addPostModifier("in the shop")
     self.s4.setFeature(Feature.TENSE, Tense.FUTURE)
     self.s4.setFeature(Feature.FORM, Form.INFINITIVE)
     self.assertEqual("however to pick up the balls in the shop tomorrow", \
             self.realiser.realise(self.s4).getRealisation())
예제 #13
0
 def testComplementation1(self):
     # was kissing Mary
     mary = self.phraseFactory.createNounPhrase("Mary")
     mary.setFeature(InternalFeature.DISCOURSE_FUNCTION,
                     DiscourseFunction.OBJECT)
     self.kiss.clearComplements()
     self.kiss.addComplement(mary)
     self.kiss.setFeature(Feature.PROGRESSIVE, True)
     self.kiss.setFeature(Feature.TENSE, Tense.PAST)
     self.assertEqual("was kissing Mary", \
             self.realiser.realise(self.kiss).getRealisation())
     mary2 = CoordinatedPhraseElement(
         mary, self.phraseFactory.createNounPhrase("Susan"))
     # add another complement -- should come out as "Mary and Susan"
     self.kiss.clearComplements()
     self.kiss.addComplement(mary2)
     self.assertEqual("was kissing Mary and Susan", \
             self.realiser.realise(self.kiss).getRealisation())
     # passivise -- should make the direct object complement disappear
     # Note: The verb doesn't come out as plural because agreement
     # is determined by the sentential subjects and self VP isn't inside a
     # sentence
     self.kiss.setFeature(Feature.PASSIVE, True)
     self.assertEqual("was being kissed", \
             self.realiser.realise(self.kiss).getRealisation())
     # make it plural (self is usually taken care of in SPhraseSpec)
     self.kiss.setFeature(Feature.NUMBER, NumberAgreement.PLURAL)
     self.assertEqual("were being kissed",
                      self.realiser.realise(self.kiss).getRealisation())
     # depassivise and add post-mod: yields "was kissing Mary in the room"
     self.kiss.addPostModifier(self.inTheRoom)
     self.kiss.setFeature(Feature.PASSIVE, False)
     self.kiss.setFeature(Feature.NUMBER, NumberAgreement.SINGULAR)
     self.assertEqual("was kissing Mary and Susan in the room", \
             self.realiser.realise(self.kiss).getRealisation())
     # passivise again: should make direct object disappear, but not postMod
     # ="was being kissed in the room"
     self.kiss.setFeature(Feature.PASSIVE, True)
     self.kiss.setFeature(Feature.NUMBER, NumberAgreement.PLURAL)
     self.assertEqual("were being kissed in the room", \
             self.realiser.realise(self.kiss).getRealisation())
예제 #14
0
 def testCoordination(self):
     # simple case
     self.kiss.addComplement(self.dog)
     self.kick.addComplement(self.boy)
     coord1 = CoordinatedPhraseElement(self.kiss, self.kick)
     coord1.setFeature(Feature.PERSON, Person.THIRD)
     coord1.setFeature(Feature.TENSE, Tense.PAST)
     self.assertEqual("kissed the dog and kicked the boy", \
             self.realiser.realise(coord1).getRealisation())
     # with negation: should be inherited by all components
     coord1.setFeature(Feature.NEGATED, True)
     self.realiser.setLexicon(self.lexicon)
     self.assertEqual("did not kiss the dog and did not kick the boy", \
             self.realiser.realise(coord1).getRealisation())
     # set a modal
     coord1.setFeature(Feature.MODAL, "could")
     self.assertEqual("could not have kissed the dog and could not have kicked the boy", \
             self.realiser.realise(coord1).getRealisation())
     # set perfect and progressive
     coord1.setFeature(Feature.PERFECT, True)
     coord1.setFeature(Feature.PROGRESSIVE, True)
     self.assertEqual("could not have been kissing the dog and " \
             + "could not have been kicking the boy",
             self.realiser.realise(coord1).getRealisation())
     # now aggregate
     coord1.setFeature(Feature.AGGREGATE_AUXILIARY, True)
     self.assertEqual("could not have been kissing the dog and kicking the boy", \
             self.realiser.realise(coord1).getRealisation())
예제 #15
0
 def testClausalComplement(self):
     self.phraseFactory.setLexicon(self.lexicon)
     s = self.phraseFactory.createClause()
     s.setSubject(self.phraseFactory.createNounPhrase("John"))
     # Create a sentence first
     maryAndSusan = CoordinatedPhraseElement(self.phraseFactory.createNounPhrase("Mary"), \
             self.phraseFactory.createNounPhrase("Susan"))
     self.kiss.clearComplements()
     s.setVerbPhrase(self.kiss)
     s.setObject(maryAndSusan)
     s.setFeature(Feature.PROGRESSIVE, True)
     s.setFeature(Feature.TENSE, Tense.PAST)
     s.addPostModifier(self.inTheRoom)
     self.assertEqual("John was kissing Mary and Susan in the room", \
             self.realiser.realise(s).getRealisation())
     # make the main VP past
     self.say.setFeature(Feature.TENSE, Tense.PAST)
     self.assertEqual("said",
                      self.realiser.realise(self.say).getRealisation())
     # now add the sentence as complement of "say". Should make the sentence
     # subordinate
     # note that sentential punctuation is suppressed
     self.say.addComplement(s)
     self.assertEqual("said that John was kissing Mary and Susan in the room", \
             self.realiser.realise(self.say).getRealisation())
     # add a postModifier to the main VP
     # yields [says [that John was kissing Mary and Susan in the room]
     # [behind the curtain]]
     self.say.addPostModifier(self.behindTheCurtain)
     self.assertEqual("said that John was kissing Mary and Susan in the room behind the curtain", \
         self.realiser.realise(self.say).getRealisation())
     # create a sentential complement
     s2 = self.phraseFactory.createClause(self.phraseFactory.createNounPhrase("all"), \
             "be", self.phraseFactory.createAdjectivePhrase("fine"))
     s2.setFeature(Feature.TENSE, Tense.FUTURE)
     self.assertEqual("all will be fine",
                      self.realiser.realise(s2).getRealisation())
     # add the complement to the VP
     # yields [said [that John was kissing Mary and Susan in the room and
     # all will be fine] [behind the curtain]]
     s3 = CoordinatedPhraseElement(s, s2)
     self.say.clearComplements()
     self.say.addComplement(s3)
     # first with outer complementiser suppressed
     s3.setFeature(Feature.SUPRESSED_COMPLEMENTISER, True)
     self.assertEqual("said that John was kissing Mary and Susan in the room " \
             + "and all will be fine behind the curtain",
             self.realiser.realise(self.say).getRealisation())
     self.setUp()
     s = self.phraseFactory.createClause()
     s.setSubject(self.phraseFactory.createNounPhrase("John"))
     # Create a sentence first
     maryAndSusan = CoordinatedPhraseElement(self.phraseFactory.createNounPhrase("Mary"), \
             self.phraseFactory.createNounPhrase("Susan"))
     s.setVerbPhrase(self.kiss)
     s.setObject(maryAndSusan)
     s.setFeature(Feature.PROGRESSIVE, True)
     s.setFeature(Feature.TENSE, Tense.PAST)
     s.addPostModifier(self.inTheRoom)
     s2 = self.phraseFactory.createClause(self.phraseFactory.createNounPhrase("all"), "be", \
             self.phraseFactory.createAdjectivePhrase("fine"))
     s2.setFeature(Feature.TENSE, Tense.FUTURE)
     # then with complementiser not suppressed and not aggregated
     s3 = CoordinatedPhraseElement(s, s2)
     self.say.addComplement(s3)
     self.say.setFeature(Feature.TENSE, Tense.PAST)
     self.say.addPostModifier(self.behindTheCurtain)
     self.assertEqual("said that John was kissing Mary and Susan in the room and " \
             + "that all will be fine behind the curtain", #$NON-NLS-1$
             self.realiser.realise(self.say).getRealisation())
예제 #16
0
    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())
예제 #17
0
 def testCoordination2(self):
     # simple coordination of complementised nps
     self.dog.clearComplements()
     self.woman.clearComplements()
     cnp1 = CoordinatedPhraseElement(self.dog, self.woman)
     cnp1.setFeature(Feature.RAISE_SPECIFIER, True)
     realised = self.realiser.realise(cnp1)
     self.assertEqual("the dog and woman", realised.getRealisation())
     #
     self.dog.addComplement(self.onTheRock)
     self.woman.addComplement(self.behindTheCurtain)
     #
     cnp2 = CoordinatedPhraseElement(self.dog, self.woman)
     self.woman.setFeature(InternalFeature.RAISED, False)
     self.assertEqual("the dog on the rock and the woman behind the curtain", \
             self.realiser.realise(cnp2).getRealisation())
     # complementised coordinates + outer pp modifier
     cnp2.addPostModifier(self.inTheRoom)
     self.assertEqual("the dog on the rock and the woman behind the curtain in the room", \
             self.realiser.realise(cnp2).getRealisation())
     # set the specifier for self cnp should unset specifiers for all inner coordinates
     every = self.phraseFactory.createWord("every", LexicalCategory.DETERMINER)
     cnp2.setFeature(InternalFeature.SPECIFIER, every)
     self.assertEqual("every dog on the rock and every woman behind the curtain in the room", \
             self.realiser.realise(cnp2).getRealisation())
     # pronominalise one of the constituents
     self.dog.setFeature(Feature.PRONOMINAL, True) # ="it"
     self.dog.setFeature(InternalFeature.SPECIFIER, \
             self.phraseFactory.createWord("the", LexicalCategory.DETERMINER))
     # raising spec still returns True as spec has been set
     cnp2.setFeature(Feature.RAISE_SPECIFIER, True)
     # CNP should be realised with pronominal internal const
     self.assertEqual("it and every woman behind the curtain in the room", \
             self.realiser.realise(cnp2).getRealisation())
예제 #18
0
 def testPassive(self):
     # passive with just complement
     _s1 = self.phraseFactory.createClause(None, "intubate", \
             self.phraseFactory.createNounPhrase("the", "baby"))
     _s1.setFeature(Feature.PASSIVE, True)
     self.assertEqual("the baby is intubated",
                      self.realiser.realise(_s1).getRealisation())
     # passive with subject and complement
     _s1 = self.phraseFactory.createClause(None, "intubate", \
             self.phraseFactory.createNounPhrase("the", "baby"))
     _s1.setSubject(self.phraseFactory.createNounPhrase("the nurse"))
     _s1.setFeature(Feature.PASSIVE, True)
     self.assertEqual("the baby is intubated by the nurse", \
         self.realiser.realise(_s1).getRealisation())
     # passive with subject and indirect object
     _s2 = self.phraseFactory.createClause(None, "give",\
             self.phraseFactory.createNounPhrase("the", "baby"))
     morphine = self.phraseFactory.createNounPhrase("50ug of morphine")
     _s2.setIndirectObject(morphine)
     _s2.setFeature(Feature.PASSIVE, True)
     self.assertEqual("the baby is given 50ug of morphine", \
             self.realiser.realise(_s2).getRealisation())
     # passive with subject, complement and indirect object
     _s2 = self.phraseFactory.createClause(self.phraseFactory.createNounPhrase("the", "nurse"), \
             "give", self.phraseFactory.createNounPhrase("the", "baby"))
     morphine = self.phraseFactory.createNounPhrase("50ug of morphine")
     _s2.setIndirectObject(morphine)
     _s2.setFeature(Feature.PASSIVE, True)
     self.assertEqual("the baby is given 50ug of morphine by the nurse", \
             self.realiser.realise(_s2).getRealisation())
     # test agreement in passive
     _s3 = self.phraseFactory.createClause(\
             CoordinatedPhraseElement("my dog", "your cat"), "chase", "George")
     _s3.setFeature(Feature.TENSE, Tense.PAST)
     _s3.addFrontModifier("yesterday")
     self.assertEqual("yesterday my dog and your cat chased George", \
             self.realiser.realise(_s3).getRealisation())
     _s3 = self.phraseFactory.createClause(CoordinatedPhraseElement( \
             "my dog", "your cat"), "chase", self.phraseFactory.createNounPhrase("George"))
     _s3.setFeature(Feature.TENSE, Tense.PAST)
     _s3.addFrontModifier("yesterday")
     _s3.setFeature(Feature.PASSIVE, True)
     self.assertEqual("yesterday George was chased by my dog and your cat", \
             self.realiser.realise(_s3).getRealisation())
     # test correct pronoun forms
     _s4 = self.phraseFactory.createClause(self.phraseFactory.createNounPhrase("he"), "chase", \
             self.phraseFactory.createNounPhrase("I"))
     self.assertEqual("he chases me",
                      self.realiser.realise(_s4).getRealisation())
     _s4 = self.phraseFactory.createClause(\
             self.phraseFactory.createNounPhrase("he"), "chase", self.phraseFactory.createNounPhrase("me"))
     _s4.setFeature(Feature.PASSIVE, True)
     self.assertEqual("I am chased by him",
                      self.realiser.realise(_s4).getRealisation())
     # same thing, but giving the S constructor "me". Should recognise correct pro anyway
     _s5 = self.phraseFactory.createClause("him", "chase", "I")
     self.assertEqual("he chases me",
                      self.realiser.realise(_s5).getRealisation())
     _s5 = self.phraseFactory.createClause("him", "chase", "I")
     _s5.setFeature(Feature.PASSIVE, True)
     self.assertEqual("I am chased by him",
                      self.realiser.realise(_s5).getRealisation())