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())
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())
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())
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)
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())
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())
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())
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())