class Test(unittest.TestCase):


    def setUp(self):
        #A young girl with red hair and green eyes is sitting in one of three chairs by the fireplace in the northern part of this room.
        lex = XMLLexicon("C:/projects/Python-nlg/res/default-lexicon.xml")
        self.np_a_young_girl = NounPhrase(lex.getWord("girl"), determiner = lex.getWord("a"), adjectives=[lex.getWord("young")])
        self.np_red_hair = NounPhrase(lex.getWord("hair"), adjectives=[lex.getWord("red", "ADJECTIVE")])
        self.np_glasses = NounPhrase(lex.getWord("glasses"))
        
        
        self.pp_with_red_hair_and_glasses = PrepositionalPhrase(lex.getWord("with"), [self.np_red_hair, self.np_glasses])
        
        self.np_the_fire = NounPhrase(lex.getWord("fire", "NOUN"), determiner=lex.getWord("the"))
        self.pp_by_the_fire = PrepositionalPhrase(lex.getWord("by", "PREPOSITION"), [self.np_the_fire])
        
        self.np_a_young_girl_with_red_hair_and_glasses = NounPhrase.from_nounphrase(self.np_a_young_girl, prepositional_phrases = [self.pp_with_red_hair_and_glasses])
        
        self.vp_is_sitting = VerbPhrase(lex.getWord("sit"), tense="present_progressive")
        
        self.vp_is_sitting_by_the_fire = VerbPhrase(lex.getWord("sit"), tense="present_progressive", prepositional_phrases = [self.pp_by_the_fire])
        
        self.np_a_young_girl_with_red_hair_and_glasses_is_sitting  = Clause(self.np_a_young_girl_with_red_hair_and_glasses, self.vp_is_sitting)
        
        
        self.np_a_young_girl_with_red_hair_and_glasses_is_sitting_by_the_fire  = Clause(self.np_a_young_girl_with_red_hair_and_glasses, self.vp_is_sitting_by_the_fire) 
        
        
        
    
    def testYoungGirl(self):
        self.assertEqual("a young girl", self.np_a_young_girl.realize())
    
    
    def testWithRedHairAndGlasses(self):
        self.assertEqual("with red hair and glasses", self.pp_with_red_hair_and_glasses.realize())
    
    
    def testYoungGirlWithRedHairAndGlasses(self):
        self.assertEqual("a young girl with red hair and glasses", self.np_a_young_girl_with_red_hair_and_glasses.realize())

    def testYoungGirlWithRedHairAndGlassesIsSitting(self):
        self.assertEqual("a young girl with red hair and glasses is sitting", self.np_a_young_girl_with_red_hair_and_glasses_is_sitting.realize())
    
    def testByTheFire(self):
        self.assertEqual("by the fire", self.pp_by_the_fire.realize())
        
    def testYoungGirlWithRedHairAndGlassesIsSittingByTheFire(self):
        self.assertEqual("a young girl with red hair and glasses is sitting by the fire", self.np_a_young_girl_with_red_hair_and_glasses_is_sitting_by_the_fire.realize())
        
        
    def tearDown(self):
        pass


    def testName(self):
        pass
Example #2
0
    def setUp(self):
        lex = XMLLexicon()

        #the woman kissed the man behind the curtain
        self.s1 = Clause()
        np_woman = self.s1.add_subject(lex.getWord("woman"))
        np_woman.add_determiner(lex.getWord("the"))
        vp_kiss = self.s1.add_verb(lex.getWord("kiss", "VERB"))

        np_man = vp_kiss.add_object(lex.getWord("man"))
        np_man.add_determiner(lex.getWord("the"))

        self.s1.set_verb_tense("past")

        #there is the dog on the rock

        #the man gives the woman John's flower
        self.s2 = Clause()
        np_man = self.s2.add_subject(lex.getWord("man"))
        np_man.add_determiner(lex.getWord("the"))

        vp_give = self.s2.add_verb(lex.getWord("give"))
        vp_give.set_tense("present")

        np_flower = vp_give.add_object(lex.getWord("flower"))
        np_flower.add_owner(lex.getWord("john"))

        np_woman = vp_give.add_indirect_object(lex.getWord("woman"))
        np_woman.add_determiner(lex.getWord("the"))

        #Test imperative

        #Make the coffee

        self.s3 = ImperativeClause()
        vp_make = self.s3.add_verb(lex.getWord("make", "VERB"))
        np_the_coffee = self.s3.add_subject(lex.getWord("coffee"))
        np_the_coffee.add_determiner(lex.getWord("the"))

        #Put the beans in the machine
        self.s4 = ImperativeClause()
        vp_put = self.s4.add_verb(lex.getWord("put", "VERB"))
        np_the_machine = NounPhrase(lex.getWord("machine", "NOUN"),
                                    determiner=lex.getWord("the"))
        pp_in_the_machine = PrepositionalPhrase(
            lex.getWord("in", "PREPOSITION"), [np_the_machine])

        vp_put.add_prepositional_phrase(pp_in_the_machine)

        np_the_beans = self.s4.add_subject(lex.getWord("bean"))
        np_the_beans.add_determiner(lex.getWord("the"))
        np_the_beans.set_number("plural")
 def setUp(self):
     #A young girl with red hair and green eyes is sitting in one of three chairs by the fireplace in the northern part of this room.
     lex = XMLLexicon("C:/projects/Python-nlg/res/default-lexicon.xml")
     self.np_a_young_girl = NounPhrase(lex.getWord("girl"), determiner = lex.getWord("a"), adjectives=[lex.getWord("young")])
     self.np_red_hair = NounPhrase(lex.getWord("hair"), adjectives=[lex.getWord("red", "ADJECTIVE")])
     self.np_glasses = NounPhrase(lex.getWord("glasses"))
     
     
     self.pp_with_red_hair_and_glasses = PrepositionalPhrase(lex.getWord("with"), [self.np_red_hair, self.np_glasses])
     
     self.np_the_fire = NounPhrase(lex.getWord("fire", "NOUN"), determiner=lex.getWord("the"))
     self.pp_by_the_fire = PrepositionalPhrase(lex.getWord("by", "PREPOSITION"), [self.np_the_fire])
     
     self.np_a_young_girl_with_red_hair_and_glasses = NounPhrase.from_nounphrase(self.np_a_young_girl, prepositional_phrases = [self.pp_with_red_hair_and_glasses])
     
     self.vp_is_sitting = VerbPhrase(lex.getWord("sit"), tense="present_progressive")
     
     self.vp_is_sitting_by_the_fire = VerbPhrase(lex.getWord("sit"), tense="present_progressive", prepositional_phrases = [self.pp_by_the_fire])
     
     self.np_a_young_girl_with_red_hair_and_glasses_is_sitting  = Clause(self.np_a_young_girl_with_red_hair_and_glasses, self.vp_is_sitting)
     
     
     self.np_a_young_girl_with_red_hair_and_glasses_is_sitting_by_the_fire  = Clause(self.np_a_young_girl_with_red_hair_and_glasses, self.vp_is_sitting_by_the_fire) 
Example #4
0
def setUp():

	lex = XMLLexicon()    
	#the woman kissed the man behind the curtain
	s1 = Clause()
	np_woman = s1.add_subject(lex.getWord("woman"))
	np_woman.add_determiner(lex.getWord("the"))
	vp_kiss = s1.add_verb(lex.getWord("abandon", "VERB"))
	np_the_curtain = NounPhrase(lex.getWord("curtain", "NOUN"), determiner=lex.getWord("the"))
	pp_the_curtain = PrepositionalPhrase(lex.getWord("behind", "PREPOSITION"), [np_the_curtain])    
	vp_kiss.add_prepositional_phrase(pp_the_curtain)
	
	np_man = vp_kiss.add_object(lex.getWord("man"))
	np_man.add_determiner(lex.getWord("the"))    
	s1.set_verb_tense("past")
	print(s1.realize())
    def setUp(self):
        #A young girl with red hair and green eyes is sitting in one of three chairs by the fireplace in the northern part of this room.

        lex_path = os.path.join(os.path.dirname(__file__),
                                '../../res/default-lexicon.xml')
        lex = XMLLexicon(lex_path)
        self.lex = lex

        self.np_a_young_girl = NounPhrase(lex.getWord("girl"),
                                          determiner=lex.getWord("a"),
                                          adjectives=[lex.getWord("young")])
        self.np_red_hair = NounPhrase(
            lex.getWord("hair"), adjectives=[lex.getWord("red", "ADJECTIVE")])
        self.np_glasses = NounPhrase(lex.getWord("glasses"))

        self.pp_with_red_hair_and_glasses = PrepositionalPhrase(
            lex.getWord("with"), [self.np_red_hair, self.np_glasses])

        self.np_the_fire = NounPhrase(lex.getWord("fire", "NOUN"),
                                      determiner=lex.getWord("the"))
        self.pp_by_the_fire = PrepositionalPhrase(
            lex.getWord("by", "PREPOSITION"), [self.np_the_fire])

        self.np_a_young_girl_with_red_hair_and_glasses = NounPhrase.from_nounphrase(
            self.np_a_young_girl,
            prepositional_phrases=[self.pp_with_red_hair_and_glasses])

        self.vp_is_sitting = VerbPhrase(lex.getWord("sit"),
                                        tense="present_progressive")

        self.vp_is_sitting_by_the_fire = VerbPhrase(
            lex.getWord("sit"),
            tense="present_progressive",
            prepositional_phrases=[self.pp_by_the_fire])

        self.np_a_young_girl_with_red_hair_and_glasses_is_sitting = Clause(
            self.np_a_young_girl_with_red_hair_and_glasses, self.vp_is_sitting)

        self.np_a_young_girl_with_red_hair_and_glasses_is_sitting_by_the_fire = Clause(
            self.np_a_young_girl_with_red_hair_and_glasses,
            self.vp_is_sitting_by_the_fire)
class Test(unittest.TestCase):
    def setUp(self):
        #A young girl with red hair and green eyes is sitting in one of three chairs by the fireplace in the northern part of this room.

        lex_path = os.path.join(os.path.dirname(__file__),
                                '../../res/default-lexicon.xml')
        lex = XMLLexicon(lex_path)
        self.lex = lex

        self.np_a_young_girl = NounPhrase(lex.getWord("girl"),
                                          determiner=lex.getWord("a"),
                                          adjectives=[lex.getWord("young")])
        self.np_red_hair = NounPhrase(
            lex.getWord("hair"), adjectives=[lex.getWord("red", "ADJECTIVE")])
        self.np_glasses = NounPhrase(lex.getWord("glasses"))

        self.pp_with_red_hair_and_glasses = PrepositionalPhrase(
            lex.getWord("with"), [self.np_red_hair, self.np_glasses])

        self.np_the_fire = NounPhrase(lex.getWord("fire", "NOUN"),
                                      determiner=lex.getWord("the"))
        self.pp_by_the_fire = PrepositionalPhrase(
            lex.getWord("by", "PREPOSITION"), [self.np_the_fire])

        self.np_a_young_girl_with_red_hair_and_glasses = NounPhrase.from_nounphrase(
            self.np_a_young_girl,
            prepositional_phrases=[self.pp_with_red_hair_and_glasses])

        self.vp_is_sitting = VerbPhrase(lex.getWord("sit"),
                                        tense="present_progressive")

        self.vp_is_sitting_by_the_fire = VerbPhrase(
            lex.getWord("sit"),
            tense="present_progressive",
            prepositional_phrases=[self.pp_by_the_fire])

        self.np_a_young_girl_with_red_hair_and_glasses_is_sitting = Clause(
            self.np_a_young_girl_with_red_hair_and_glasses, self.vp_is_sitting)

        self.np_a_young_girl_with_red_hair_and_glasses_is_sitting_by_the_fire = Clause(
            self.np_a_young_girl_with_red_hair_and_glasses,
            self.vp_is_sitting_by_the_fire)

    def testYoungGirl(self):
        self.assertEqual("a young girl", self.np_a_young_girl.realize())

    def testWithRedHairAndGlasses(self):
        self.assertEqual("with red hair and glasses",
                         self.pp_with_red_hair_and_glasses.realize())

    def testYoungGirlWithRedHairAndGlasses(self):
        self.assertEqual(
            "a young girl with red hair and glasses",
            self.np_a_young_girl_with_red_hair_and_glasses.realize())

    def testYoungGirlWithRedHairAndGlassesIsSitting(self):
        self.assertEqual(
            "a young girl with red hair and glasses is sitting",
            self.np_a_young_girl_with_red_hair_and_glasses_is_sitting.realize(
            ))

    def testByTheFire(self):
        self.assertEqual("by the fire", self.pp_by_the_fire.realize())

    def testYoungGirlWithRedHairAndGlassesIsSittingByTheFire(self):
        self.assertEqual(
            "a young girl with red hair and glasses is sitting by the fire",
            self.
            np_a_young_girl_with_red_hair_and_glasses_is_sitting_by_the_fire.
            realize())

    def testConjunction(self):
        nc = NounConjunction([self.np_a_young_girl, self.np_the_fire])
        self.assertEqual("a young girl and the fire", nc.realize())

        nc2 = NounConjunction([self.np_the_fire, self.np_a_young_girl])
        self.assertEqual("the fire and a young girl", nc2.realize())

        nc3 = NounConjunction(
            [self.np_the_fire, self.np_a_young_girl, self.np_red_hair])
        self.assertEqual("the fire, a young girl, and red hair", nc3.realize())

        nc1 = NounConjunction([self.np_the_fire])
        self.assertEqual("the fire", nc1.realize())

    def test_number(self):
        self.np_the_fire.set_number(5)
        self.assertEqual("the five fires", self.np_the_fire.realize())
class Test(unittest.TestCase):
    def setUp(self):
        #A young girl with red hair and green eyes is sitting in one of three chairs by the fireplace in the northern part of this room.
        lex = XMLLexicon("C:/projects/Python-nlg/res/default-lexicon.xml")
        self.np_a_young_girl = NounPhrase(lex.getWord("girl"),
                                          determiner=lex.getWord("a"),
                                          adjectives=[lex.getWord("young")])
        self.np_red_hair = NounPhrase(
            lex.getWord("hair"), adjectives=[lex.getWord("red", "ADJECTIVE")])
        self.np_glasses = NounPhrase(lex.getWord("glasses"))

        self.pp_with_red_hair_and_glasses = PrepositionalPhrase(
            lex.getWord("with"), [self.np_red_hair, self.np_glasses])

        self.np_the_fire = NounPhrase(lex.getWord("fire", "NOUN"),
                                      determiner=lex.getWord("the"))
        self.pp_by_the_fire = PrepositionalPhrase(
            lex.getWord("by", "PREPOSITION"), [self.np_the_fire])

        self.np_a_young_girl_with_red_hair_and_glasses = NounPhrase.from_nounphrase(
            self.np_a_young_girl,
            prepositional_phrases=[self.pp_with_red_hair_and_glasses])

        self.vp_is_sitting = VerbPhrase(lex.getWord("sit"),
                                        tense="present_progressive")

        self.vp_is_sitting_by_the_fire = VerbPhrase(
            lex.getWord("sit"),
            tense="present_progressive",
            prepositional_phrases=[self.pp_by_the_fire])

        self.np_a_young_girl_with_red_hair_and_glasses_is_sitting = Clause(
            self.np_a_young_girl_with_red_hair_and_glasses, self.vp_is_sitting)

        self.np_a_young_girl_with_red_hair_and_glasses_is_sitting_by_the_fire = Clause(
            self.np_a_young_girl_with_red_hair_and_glasses,
            self.vp_is_sitting_by_the_fire)

    def testYoungGirl(self):
        self.assertEqual("a young girl", self.np_a_young_girl.realize())

    def testWithRedHairAndGlasses(self):
        self.assertEqual("with red hair and glasses",
                         self.pp_with_red_hair_and_glasses.realize())

    def testYoungGirlWithRedHairAndGlasses(self):
        self.assertEqual(
            "a young girl with red hair and glasses",
            self.np_a_young_girl_with_red_hair_and_glasses.realize())

    def testYoungGirlWithRedHairAndGlassesIsSitting(self):
        self.assertEqual(
            "a young girl with red hair and glasses is sitting",
            self.np_a_young_girl_with_red_hair_and_glasses_is_sitting.realize(
            ))

    def testByTheFire(self):
        self.assertEqual("by the fire", self.pp_by_the_fire.realize())

    def testYoungGirlWithRedHairAndGlassesIsSittingByTheFire(self):
        self.assertEqual(
            "a young girl with red hair and glasses is sitting by the fire",
            self.
            np_a_young_girl_with_red_hair_and_glasses_is_sitting_by_the_fire.
            realize())

    def tearDown(self):
        pass

    def testName(self):
        pass