Ejemplo n.º 1
0
 def setUp(self):
     sample_lexicon = {
         'subject': {'player'},
         'verb': {'smack', 'punch', 'go', 'open'},
         'object': {'bear', 'door', 'face', 'nose'},
         'constituent': {'in', 'the', 'their', 'that', 'at', 'upon', 'where', 'on', 'through'}
     }
     self.sentence = lexicon.Sentence(word_order='SVO')
     self.game_lexicon = lexicon.Lexicon(sample_lexicon)
Ejemplo n.º 2
0
    def test_build_invalid_vso_sentences(self):
        self.sentence = lexicon.Sentence(word_order='vso')

        invalid_vso0 = self.game_lexicon.scan_text('punch bear Player')
        invalid_vso1 = self.game_lexicon.scan_text('punch the bear Player')
        invalid_vso2 = self.game_lexicon.scan_text('smack bear Player')
        invalid_vso3 = self.game_lexicon.scan_text('smack the bear Player')
        invalid_vso4 = self.game_lexicon.scan_text('open door Player')
        invalid_vso5 = self.game_lexicon.scan_text('open the door Player')
        invalid_vso6 = self.game_lexicon.scan_text('punch through the door Player')
        invalid_vso7 = self.game_lexicon.scan_text('go through the door Player')

        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_vso0)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_vso1)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_vso2)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_vso3)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_vso4)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_vso5)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_vso6)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_vso7)
Ejemplo n.º 3
0
    def test_build_valid_vso_sentences(self):
        self.sentence = lexicon.Sentence(word_order='vso')

        valid_vso0 = self.game_lexicon.scan_text('punch Player bear')
        valid_vso1 = self.game_lexicon.scan_text('punch Player the bear')
        valid_vso2 = self.game_lexicon.scan_text('smack Player bear')
        valid_vso3 = self.game_lexicon.scan_text('smack Player the bear')
        valid_vso4 = self.game_lexicon.scan_text('open Player door')
        valid_vso5 = self.game_lexicon.scan_text('open Player the door')
        valid_vso6 = self.game_lexicon.scan_text('punch Player through the door')
        valid_vso7 = self.game_lexicon.scan_text('go Player through the door')
        valid_vso8 = self.game_lexicon.scan_text('go in Player through the door')

        self.assertEqual(self.sentence.build(valid_vso0), 'punch player bear')
        self.assertEqual(self.sentence.build(valid_vso1), 'punch player bear')
        self.assertEqual(self.sentence.build(valid_vso2), 'smack player bear')
        self.assertEqual(self.sentence.build(valid_vso3), 'smack player bear')
        self.assertEqual(self.sentence.build(valid_vso4), 'open player door')
        self.assertEqual(self.sentence.build(valid_vso5), 'open player door')
        self.assertEqual(self.sentence.build(valid_vso6), 'punch player door')
        self.assertEqual(self.sentence.build(valid_vso7), 'go player door')
        self.assertEqual(self.sentence.build(valid_vso8), 'go player door')
Ejemplo n.º 4
0
    def test_build_valid_sov_sentences(self):
        self.sentence = lexicon.Sentence(word_order='sov')

        valid_sov0 = self.game_lexicon.scan_text('Player bear punch')
        valid_sov1 = self.game_lexicon.scan_text('Player the bear punch')
        valid_sov2 = self.game_lexicon.scan_text('Player bear smack')
        valid_sov3 = self.game_lexicon.scan_text('Player the bear smack')
        valid_sov4 = self.game_lexicon.scan_text('Player door open')
        valid_sov5 = self.game_lexicon.scan_text('Player the door open')
        valid_sov6 = self.game_lexicon.scan_text('Player through the door punch')
        valid_sov7 = self.game_lexicon.scan_text('Player through the door go')
        valid_sov8 = self.game_lexicon.scan_text('Player in through the door go')

        self.assertEqual(self.sentence.build(valid_sov0), 'player bear punch')
        self.assertEqual(self.sentence.build(valid_sov1), 'player bear punch')
        self.assertEqual(self.sentence.build(valid_sov2), 'player bear smack')
        self.assertEqual(self.sentence.build(valid_sov3), 'player bear smack')
        self.assertEqual(self.sentence.build(valid_sov4), 'player door open')
        self.assertEqual(self.sentence.build(valid_sov5), 'player door open')
        self.assertEqual(self.sentence.build(valid_sov6), 'player door punch')
        self.assertEqual(self.sentence.build(valid_sov7), 'player door go')
        self.assertEqual(self.sentence.build(valid_sov8), 'player door go')
Ejemplo n.º 5
0
    def test_build_invalid_sov_sentences(self):
        self.sentence = lexicon.Sentence(word_order='sov')

        invalid_sov0 = self.game_lexicon.scan_text('bear punch')
        invalid_sov1 = self.game_lexicon.scan_text('the bear punch')
        invalid_sov2 = self.game_lexicon.scan_text('bear smack')
        invalid_sov3 = self.game_lexicon.scan_text('the bear smack')
        invalid_sov4 = self.game_lexicon.scan_text('door open')
        invalid_sov5 = self.game_lexicon.scan_text('the door open')
        invalid_sov6 = self.game_lexicon.scan_text('through the door punch')
        invalid_sov7 = self.game_lexicon.scan_text('through the door go')
        invalid_sov8 = self.game_lexicon.scan_text('Player the bear in the face punch')
        invalid_sov9 = self.game_lexicon.scan_text('Player the bear in the nose smack')

        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_sov0)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_sov1)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_sov2)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_sov3)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_sov4)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_sov5)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_sov6)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_sov7)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_sov8)
        self.assertRaises(lexicon.ParserError, self.sentence.build, invalid_sov9)