Пример #1
0
def parse_sentence_tests():
    word_list = [('stop', 'the'), ('adj', 'damned'), ('noun', 'bee'), ('verb', 'stung'), ('stop', 'the'), ('noun', 'human')]
    assert_raises(parser.ParserError, parser.parse_sentence, word_list)

    word_list = [('number', 10), ('noun', 'lions'), ('verb', 'ate'), ('stop', 'the'), ('noun', 'zebra')]
    sentence = parser.parse_sentence(word_list)
    assert_equals(sentence.num_subjects, 10)
    assert_equals(sentence.subject, 'lions')
    assert_equals(sentence.verb, 'ate')
    assert_equals(sentence.object, 'zebra')

    word_list = [('stop', 'the'), ('noun', 'bee'), ('verb', 'stung'), ('stop', 'the'), ('noun', 'human')]
    sentence = parser.parse_sentence(word_list)
    assert_equals(sentence.subject, 'bee')
    assert_equals(sentence.verb, 'stung')
    assert_equals(sentence.object, 'human')

    word_list = [('verb', 'stung'), ('stop', 'the'), ('noun', 'human')]
    sentence = parser.parse_sentence(word_list)
    assert_equals(sentence.subject, 'player')
    assert_equals(sentence.verb, 'stung')
    assert_equals(sentence.object, 'human')

    word_list = [('start', 'hello'), ('noun', 'bee'), ('verb', 'stung'), ('stop', 'the'), ('noun', 'human')]
    assert_raises(parser.ParserError, parser.parse_sentence, word_list)
Пример #2
0
def test():
    assert_equal(parser.peek(lexicon.scan('go kill the princess')), 'verb')
    assert_equal(parser.match(lexicon.scan('go kill the princess'), 'verb'),
                 ('verb', 'go'))
    assert_equal(parser.skip(lexicon.scan('go kill the princess'), 'verb'),
                 None)
    assert_equal(parser.parse_verb(lexicon.scan('go kill the princess')),
                 ('verb', 'go'))
    assert_raises(parser.ParserError, parser.parse_verb, ('noun', 'princess'))
    assert_equal(parser.parse_object(lexicon.scan('the princess')),
                 ('noun', 'princess'))
    assert_equal(parser.parse_object(lexicon.scan('the north')),
                 ('direction', 'north'))
    assert_raises(parser.ParserError, parser.parse_object,
                  lexicon.scan('go kill the princess'))
    subj = 'bear'
    assert_equal(
        parser.parse_sentence(
            lexicon.scan('the bear eat the princess')).subject, subj)
    ver = 'eat'
    assert_equal(
        parser.parse_sentence(lexicon.scan('the bear eat the princess')).verb,
        ver)
    obj = 'princess'
    assert_equal(
        parser.parse_sentence(
            lexicon.scan('the bear eat the princess')).object, obj)
Пример #3
0
def test_parse_sentence():
    word_list = [('noun', 'princess'), ('verb', 'eat'), ('stop', 'the'),
                 ('noun', 'pea')]
    word_list2 = [('verb', 'go'), ('direction', 'south')]
    word_list3 = [('error', 'see'), ('stop', 'the'), ('noun', 'gun')]
    word_list4 = [('noun', 'princess'), ('error', 'eee'), ('stop', 'the'),
                  ('noun', 'pea')]
    word_list5 = [('verb', 'go'), ('error', 'bye')]

    sentence = parser.parse_sentence(word_list)
    assert_equal(sentence.subject, 'princess')
    assert_equal(sentence.verb, 'eat')
    assert_equal(sentence.object, 'pea')

    sentence = parser.parse_sentence(word_list2)
    assert_equal(sentence.subject, 'player')
    assert_equal(sentence.verb, 'go')
    assert_equal(sentence.object, 'south')

    sentence = parser.parse_sentence(word_list3)
    assert_equal(sentence, None)

    sentence = parser.parse_sentence(word_list4)
    assert_equal(sentence, None)

    sentence = parser.parse_sentence(word_list5)
    assert_equal(sentence, None)
Пример #4
0
def test_sentence():
    assert_equal(
        parser.parse_sentence([
            ('verb', 'go'),
            ('direction', 'north')
        ]).subject,
        'player'
    )
    assert_equal(
        parser.parse_sentence([
            ('verb', 'go'),
            ('direction', 'north')
        ]).verb,
        'go'
    )
    assert_equal(
        parser.parse_sentence([
            ('verb', 'go'),
            ('direction', 'north')
        ]).object,
        'north'
    )
    assert_raises(
        parser.ParserError,
        parser.parse_sentence,
        [('verb', 'eat'), ('verb', 'kill')]
    )
Пример #5
0
def test_parse_sentence():
    word_list = [('noun', 'princess'), ('verb', 'eat'), ('stop', 'the'), 
                ('noun', 'pea')]
    word_list2 = [('verb', 'go'), ('direction', 'south')]
    word_list3 = [('error', 'see'), ('stop', 'the'), ('noun', 'gun')]
    word_list4 = [('noun', 'princess'), ('error', 'eee'), ('stop', 'the'),
                  ('noun', 'pea')]
    word_list5 = [('verb', 'go'), ('error', 'bye')]
    
    sentence = parser.parse_sentence(word_list)
    assert_equal(sentence.subject, 'princess')
    assert_equal(sentence.verb, 'eat')
    assert_equal(sentence.object, 'pea')
    
    sentence = parser.parse_sentence(word_list2)
    assert_equal(sentence.subject, 'player')
    assert_equal(sentence.verb, 'go')
    assert_equal(sentence.object, 'south')
    
    sentence = parser.parse_sentence(word_list3)
    assert_equal(sentence, None)
    
    sentence = parser.parse_sentence(word_list4)
    assert_equal(sentence, None)
    
    sentence = parser.parse_sentence(word_list5)
    assert_equal(sentence, None)
Пример #6
0
def test_unknown_words():
	word_list = [('noun', 'man'), ('verb', 'go'), ('direction', 'north'), ('stop', 'at'), ('xxx', 'xxx'), ('noun', 'door')]
	s = parser.parse_sentence(word_list)
	assert_raises(parser.ParserError, parser.parse_sentence, word_list)
	word_list = [('stop', 'the'), ('verb', 'go'), ('direction', 'north')]
	s = parser.parse_sentence(word_list)
	assert_raises(parser.ParserError, parser.parse_sentence, word_list)
def test_numbers():
    word_list = lexicon.scan("kill 7 bear")
    sen = parser.parse_sentence(word_list)
    assert_equal(sen.subject, "player")
    assert_equal(sen.verb, "kill")
    assert_equal(sen.object, "bear")
    word_list = lexicon.scan("cabinet kill the 42 bear")
    sen = parser.parse_sentence(word_list)
    assert_equal(sen.subject, "cabinet")
def test_numbers():
    word_list = lexicon.scan("kill 7 bear")
    sen = parser.parse_sentence(word_list)
    assert_equal(sen.subject, 'player')
    assert_equal(sen.verb, 'kill')
    assert_equal(sen.object, 'bear')
    word_list = lexicon.scan("cabinet kill the 42 bear")
    sen = parser.parse_sentence(word_list)
    assert_equal(sen.subject, 'cabinet')
Пример #9
0
def test_parse_sentence():
    word_list = lexicon.scan('the bear eat door')
    s = parser.parse_sentence(word_list)
    assert_equal(s.to_tuple(), ('bear', 'eat', 1, 'door'))
    word_list = lexicon.scan('in eat door')
    s = parser.parse_sentence(word_list)
    assert_equal(s.to_tuple(), ('player', 'eat', 1, 'door'))
    word_list = lexicon.scan('north eat door')
    assert_raises(parser.ParserError, parser.parse_sentence, word_list)
Пример #10
0
def test_parse_sentence():
	word_list = lexicon.scan('the princess go east')
	s = parser.parse_sentence(word_list)
	assert_equal(s.to_tuple(), ('princess', 'go', 'east'))
	word_list = lexicon.scan('in go door')
	s = parser.parse_sentence(word_list)
	assert_equal(s.to_tuple(), ('player', 'go', 'door'))
	word_list = lexicon.scan('north eat door')
	assert_raises(parser.ParserError, parser.parse_sentence, word_list)
def test_parse_sentence():
    word_list = lexicon.scan('the bear eat door')
    s = parser.parse_sentence(word_list)
    assert_equal(s.to_tuple(), ('bear', 'eat', 1, 'door'))
    word_list = lexicon.scan('in eat door')
    s = parser.parse_sentence(word_list)
    assert_equal(s.to_tuple(), ('player', 'eat', 1, 'door'))
    word_list = lexicon.scan('north eat door')
    assert_raises(parser.ParserError, parser.parse_sentence, word_list)
Пример #12
0
def test_parse_sentence():
    word_list = lexicon.scan("the princess go north")
    assert_equal("princess", parser.parse_sentence(word_list).subject)
    word_list = lexicon.scan("kill bear")
    sen = parser.parse_sentence(word_list)
    assert_equal("player", sen.subject)
    assert_equal("kill", sen.verb)
    assert_equal("bear", sen.object)
    word_list = lexicon.scan("the the the the")
    assert_raises(parser.ParserError, parser.parse_sentence, word_list)
    assert_raises(parser.ParserError, parser.parse_sentence, [])
Пример #13
0
def test_parse_sentence():
    word_list = lexicon.scan("the princess go north")
    assert_equal('princess', parser.parse_sentence(word_list).subject)
    word_list = lexicon.scan("kill bear")
    sen = parser.parse_sentence(word_list)
    assert_equal('player', sen.subject)
    assert_equal('kill', sen.verb)
    assert_equal('bear', sen.object)
    word_list = lexicon.scan("the the the the")
    assert_raises(parser.ParserError, parser.parse_sentence, word_list)
    assert_raises(parser.ParserError, parser.parse_sentence, [])
Пример #14
0
def test_parse_sentence():
	word_list = [('noun', 'man'), ('verb', 'go'), ('direction', 'north'), ('stop', 'at'), ('noun', 'door')]
	s = parser.parse_sentence(word_list)
	assert_equal(s.to_tuple(), ('man', 'go', 1, 'north'))
	word_list = [('noun', 'man'), ('verb', 'go'), ('number', 5), ('stop', 'at'), ('noun', 'door')]
	s = parser.parse_sentence(word_list)
	assert_equal(s.to_tuple(), ('man', 'go', 5, 'door'))
	word_list = [('stop', 'in'), ('verb', 'eat'), ('noun', 'door')]
	s = parser.parse_sentence(word_list)
	assert_equal(s.to_tuple(), ('player', 'eat', 1, 'door'))
	word_list = [('direction', 'north'), ('verb', 'eat'), ('noun', 'door')]
	assert_raises(parser.ParserError, parser.parse_sentence, word_list)
Пример #15
0
def test_parse_sentence():
    x = parser.parse_sentence([('verb', 'run'), ('direction', 'north')])
    assert_equal(x.subject, 'player')
    assert_equal(x.verb, 'run')
    assert_equal(x.object, 'north')


    x = parser.parse_sentence([('noun', 'bear'), ('verb', 'eat'), ('stop', 'the'), (
        'noun', 'bear'), ('verb', 'eat'), ('stop', 'the'), ('noun', 'honey')])
    assert_equal(x.subject, 'bear')
    assert_equal(x.verb, 'eat')
    assert_equal(x.object, 'bear')
Пример #16
0
def test_parse_sentence():
    input_x = [('verb', 'run'), ('direction', 'up')]
    sentence_x = parser.parse_sentence(input_x)
    assert_equal(sentence_x.subject, 'player')
    assert_equal(sentence_x.verb, 'run')
    assert_equal(sentence_x.object, 'up')

    input_xx = [('noun', 'bear'), ('verb', 'eat'), ('stop', 'the'), ('noun', 'honey')]
    sentence_xx = parser.parse_sentence(input_xx)
    assert_equal(sentence_xx.subject, 'bear')
    assert_equal(sentence_xx.verb, 'eat')
    assert_equal(sentence_xx.object, 'honey')
Пример #17
0
def test_sentence():
    sentence = parser.parse_sentence([('verb', 'run'),
                                     ('direction', 'north')])
    assert_equal(sentence.subject, 'player')
    assert_equal(sentence.verb, 'run')
    assert_equal(sentence.object, 'north')

    sentence = parser.parse_sentence([('noun', 'bear'), ('verb', 'eat'),
                                     ('stop', 'the'), ('noun', 'honey')])
    assert_equal(sentence.subject, 'bear')
    assert_equal(sentence.verb, 'eat')
    assert_equal(sentence.object, 'honey')
    assert_raises(parser.ParserError, parser.parse_sentence, [('noun', 'bear'), ('noun', 'honey'), ('noun', 'princess')])
Пример #18
0
def test_parser():
    sentence_list = lexicon.scan("run north")
    sentence = parser.parse_sentence(sentence_list)
    result = [sentence.subject, sentence.verb, sentence.object]
    assert_equal(result, ['player', 'run', 'north'])

    sentence_list = lexicon.scan("bear eat the honey")
    sentence = parser.parse_sentence(sentence_list)
    result = [sentence.subject, sentence.verb, sentence.object]
    assert_equal(result, ['bear', 'eat', 'honey'])

    sentence_list = lexicon.scan("the bear kill")
    assert_raises(parser.ParserError, parser.parse_sentence, sentence_list)
def test_parse_sentence():
    sentence = lexicon.scan("go in the door")
    sentence = parser.parse_sentence(sentence)
    result = parser.Sentence(('noun', 'player'),
                             ('verb', 'go'),
                             ('noun', 'door'))
    assert_equal(sentence.subject, result.subject)
    assert_equal(sentence.verb, result.verb)
    assert_equal(sentence.obj, result.obj)

    with assert_raises(parser.ParserError):
        sentence = lexicon.scan("go eat the player")
        parser.parse_sentence(sentence)
Пример #20
0
def test_parse_sentence():
    word_list = lexicon.scan('princess go the door')
    s = parser.parse_sentence(word_list)
    assert_equal(s.subject, 'princess')
    assert_equal(s.verb, 'go')
    assert_equal(s.object, 'door')
    word_list = lexicon.scan('stop at bear')
    s = parser.parse_sentence(word_list)
    assert_equal(s.subject, 'player')
    assert_equal(s.verb, 'stop')
    assert_equal(s.object, 'bear')

    word_list = lexicon.scan('noth eat bear')
    s = parser.parse_sentence
    assert_raises(parser.ParserError, s, word_list)
Пример #21
0
def test_parse_sentence():
    testSentence = parser.parse_sentence([('noun', 'bear'), ('verb', 'eats'),
                                          ('noun', 'honey')])
    assert_equal(
        [testSentence.subject, testSentence.verb, testSentence.object],
        ['bear', 'eats', 'honey'])
    testSentence = parser.parse_sentence([('stop', 'to'), ('verb', 'kill'),
                                          ('stop', 'a'),
                                          ('noun', 'mockingbird')])
    assert_equal(
        [testSentence.subject, testSentence.verb, testSentence.object],
        ['player', 'kill', 'mockingbird'])
    assert_raises(parser.ParserError, parser.parse_sentence, [('noun', 'hip')])
    assert_raises(parser.ParserError, parser.parse_sentence,
                  [('verb', 'cheer')])
Пример #22
0
def test_psentence():
	def check(sent, subject, verb, object): 
		assert_equal(sent.subject, subject)
		assert_equal(sent.verb, verb)
		assert_equal(sent.object, object)
	sent = parser.parse_sentence(lexicon.scan("kill the bear"))
	
	check(sent, "player", "kill", "bear")
	
	sent = parser.parse_sentence(lexicon.scan("Princess kill the bear"))
	
	check(sent, "princess", "kill", "bear")
	
	
	assert_raises(Exception, parser.parse_sentence, (lexicon.scan('moo')))
Пример #23
0
def test_parse_sentence():
    assert_equal(parser.parse_sentence(lexicon.scan("eat the bear")).subject,
                 parser.Sentence(('noun', 'player'), 
                                 ('verb', 'eat'), 
                                 ('noun', 'bear')).subject)
    result = parser.parse_sentence(lexicon.scan("go north"))
    assert_equal(result.subject, parser.Sentence(('noun', 'player'), 
                                                 ('verb', 'go'), 
                                                 ('direction', 'north')).subject)
    assert_equal(result.verb, parser.Sentence(('noun', 'player'), 
                                              ('verb', 'go'), 
                                              ('direction', 'north')).verb)
    assert_equal(result.object, parser.Sentence(('noun', 'player'), 
                                          ('verb', 'go'), 
                                          ('direction', 'north')).object)
Пример #24
0
def test_sentence():
    raw_sentence=lexicon.scan("go THROUGH the door")
    sentence=parser.parse_sentence(raw_sentence)
    result=sentence.subject+" "+sentence.verb+" "+sentence.object
    assert_equal(result,"player go door")

   # assert_raises
Пример #25
0
def test_stop():
    x = parser.parse_sentence([('stop', 'the'), ('noun', 'bear'), 
                        ('stop', 'that'), ('stop', 'it'), ('verb', 'go'), 
                        ('stop', 'to'), ('noun', 'east')])
    assert_equal(x.subject, 'bear')
    assert_equal(x.verb, 'go')
    assert_equal(x.object, 'east')
Пример #26
0
 def test_parse_sentence(self):
     self.addTypeEqualityFunc(parser.Sentence, sentence_eq)
     self.assertEqual(
         parser.parse_sentence([('noun', 'ratman'), ('verb', 'eats'),
                                ('noun', 'cake')]),
         parser.Sentence(('noun', 'ratman'), ('verb', 'eats'),
                         ('noun', 'cake')))
Пример #27
0
def test_parse_sentence():
    wordlist = [('verb', 'run'), ('direction', 'north')]
    result = parser.parse_sentence(wordlist)
    assert_equal(result.__class__, parser.Sentence)
    assert_equal(result.subject, 'player')
    assert_equal(result.verb, 'run')
    assert_equal(result.object, 'north')
Пример #28
0
def test_parse_sentence():
	vector = lexicon.scan('bear kill the princess')
	result = parser.parse_sentence(vector)
	assert_equal(result.subject, 'bear')
	assert_equal(result.verb, 'kill')
	assert_equal(result.object, 'princess')
	vector2 = lexicon.scan('VDFVDS eat bear')
	assert_raises(parser.ParseError, parser.parse_sentence, vector2)
Пример #29
0
def test_parse_sentence():
    a_sentence = parser.parse_sentence(
            [('noun', 'Wizard'),
             ('verb', 'kill'),
             ('noun', 'Troll')])
    assert_equal(a_sentence.subject, 'Wizard')
    assert_equal(a_sentence.verb, 'kill')
    assert_equal(a_sentence.obj, 'Troll')
Пример #30
0
def test_parse_sentence():
    result = lexicon.scan("the princess kill the bear")
    word_list = parser.parse_sentence(result)
    sample = Sentence(('noun', 'princess'), ('verb', 'kill'), ('noun', 'bear'))

    assert_equal(word_list.subject, sample.subject)
    assert_equal(word_list.verb, sample.verb)
    assert_equal(word_list.object, sample.object)
Пример #31
0
def test_sentence():
    words = lexicon.scan("the fighter will kill the bear")
    senten = parser.parse_sentence(words)
    assert_equal(senten.subject, 'fighter')
    assert_equal(senten.verb, 'kill')
    assert_equal(senten.object, 'bear')

    # no subject test
    words = lexicon.scan("kill the bear")
    senten = parser.parse_sentence(words)
    assert_equal(senten.subject, 'player')
    assert_equal(senten.verb, 'kill')
    assert_equal(senten.object, 'bear')

    # error test
    words = lexicon.scan("777 eat bear")
    assert_raises(parser.ParserError, parser.parse_sentence, words)  
Пример #32
0
def test_parse_sentence():
    word_list1 = [("stop", "at"), ("stop", "the"), ("noun", "bear"),
                  ("verb", "eat"), ("noun", "honey")]
    word_list2 = [("stop", "at"), ("verb", "go"), ("direction", "north")]
    word_list3 = [("stop", "at"), ("stop", "the"), ("verb", "go")]
    word_list4 = [("stop", "at"), ("stop", "the"), ("direction", "north")]
    word_list5 = []
    sentence1 = parser.parse_sentence(word_list1)
    sentence2 = parser.parse_sentence(word_list2)
    assert_equal(sentence1.subject, "bear")
    assert_equal(sentence1.verb, "eat")
    assert_equal(sentence1.object, "honey")
    assert_equal(sentence2.subject, "player")
    assert_equal(sentence2.verb, "go")
    assert_equal(sentence2.object, "north")
    assert_raises(parser.ParserError, parser.parse_sentence, word_list3)
    assert_raises(parser.ParserError, parser.parse_sentence, word_list4)
    assert_raises(parser.ParserError, parser.parse_sentence, word_list5)
def test_parse_sentence():
    word_list = [('stop', 'I'), ('verb', 'shrunk'), ('stop', 'the'),
                 ('noun', 'kids')]

    x = parser.parse_sentence(word_list)

    assert_equal(x.subject, 'player')
    assert_equal(x.verb, 'shrunk')
    assert_equal(x.object, 'kids')
Пример #34
0
def test_parse_sentence():
    word_list = lexicon.scan("scream at the bear")
    sen = parser.parse_sentence(word_list)
    assert "player" == sen.subject
    assert "scream" == sen.verb
    assert "bear" == sen.object

    word_list = lexicon.scan("princess kill the bear")
    sen = parser.parse_sentence(word_list)
    assert "princess" == sen.subject
    assert "kill" == sen.verb
    assert "bear" == sen.object

    word_list = lexicon.scan("the bear run south")
    sen = parser.parse_sentence(word_list)
    assert "bear", sen.subject
    assert "run", sen.verb
    assert "south", sen.object
Пример #35
0
def test_sentence():
	word_list = [('noun', 'princess'), ('verb', 'go'), ('direction', 'north')]
	word_list2 = word_list[:]

	parsed = parser.parse_sentence(word_list)
	parsed2 = parser.Sentence(word_list2[0], word_list2[1], word_list2[2])
	assert_equal(parsed.subject, parsed2.subject)
	assert_equal(parsed.verb, parsed2.verb)
	assert_equal(parsed.object, parsed2.object)
Пример #36
0
def test_parser_no_subject():
    theCall = parser.parse_sentence([('verb', 'go'), ('direction', 'north')])
    result1 = getattr(theCall, 'subject')
    result2 = getattr(theCall, 'verb')
    result3 = getattr(theCall, 'object')

    assert_equal(result1, 'player')
    assert_equal(result2, 'go')
    assert_equal(result3, 'north')
Пример #37
0
def test_parse_sentence():
   subject = ('noun', 'player')
   verb = ('verb', 'go')
   obj = ('direction', 'left')
   word_list = [('stop', 'the'), ('verb', 'go'), ('direction', 'left')]
   s1 = parser.parse_sentence(word_list)
   s2 = Sentence(subject, verb, obj)
   assert_equal(s1.subject, s2.subject)
   assert_equal(s1.verb, s2.verb)
   assert_equal(s1.object, s2.object)
def test_sentence():
    sentence1 = "bear go east"
    sentence2 = "princess kill bear"
    words1 = parser.scan(sentence1)
    words2 = parser.scan(sentence2)
    s_testing = parser.parse_sentence(words1)
    s = parser.Sentence(('noun','bear'),('verb','go'),('direction','east'))
    assert_equal(s_testing.subject,s.subject)
    assert_equal(s_testing.verb,s.verb)
    assert_equal(s_testing.object,s.object)
Пример #39
0
def test_parse_sentence():

    word_list3 = lexicon.scan("princess open the door")
    result = parser.parse_sentence(word_list3)
    wanted = parser.Sentence(('noun', 'princess'), ('verb', 'open'),
                             ('noun', 'door'))
    assert_equal(result.subject, wanted.subject)
    assert_equal(result.verb, wanted.verb)
    assert_equal(result.object, wanted.object)
    assert_raises(parser.ParserError, parser.parse_sentence, word_list3)
Пример #40
0
def test_parser_with_stops():
    theCall = parser.parse_sentence([('verb', 'kill'), 
                                     ('stop', 'the'),
                                     ('noun', 'princess')])
    result1 = getattr(theCall, 'subject')
    result2 = getattr(theCall, 'verb')
    result3 = getattr(theCall, 'object')

    assert_equal(result1, 'player')
    assert_equal(result2, 'kill')
    assert_equal(result3, 'princess')
Пример #41
0
def test_sentence_2():
	assert_equal(
		parser.parse_sentence([
			('verb', 'kill'),
			('noun', 'bear')
		]),
		parser.Sentence(
			('noun', 'player'),
			('verb', 'kill'),
			('noun', 'bear')
		)
	)
def test_parse_sentence():
    player = ('noun', 'player')
    bear = ('noun', 'bear')
    verb = ('verb', 'go')
    direction = ('direction', 'north')

    # When subject is not the player
    word_list = [bear, verb, direction]
    expect = parser.Sentence(bear, verb, direction)
    actual = parser.parse_sentence(word_list)
    assert_sentence_equal(expect, actual)
    
    # When subject is the player
    word_list = [verb, direction]
    expect = parser.Sentence(player, verb, direction)
    actual = parser.parse_sentence(word_list)    
    assert_sentence_equal(expect, actual)

    # When subject is invalid
    word_list = [('stop', 'the'), ('error', 'whatever')]
    assert_raises(parser.ParserError, parser.parse_sentence, word_list)
Пример #43
0
def test_parse_sentence():
    a_word_list = lexicon.scan("it princess eat it")
    #a_test_sentence = parser.parse_sentence(a_word_list)
    assert_raises(parser.ParserError, parser.parse_sentence, a_word_list)
    b_word_list = lexicon.scan("eat princess")
    b_test_sentence = parser.parse_sentence(b_word_list)
    assert_equal(b_test_sentence.verb, 'eat')
    assert_equal(b_test_sentence.object, 'princess')
    assert_equal(b_test_sentence.subject, 'player')

    c_word_list = lexicon.scan("what is the matter?")
    assert_raises(parser.ParserError, parser.parse_sentence, c_word_list)
Пример #44
0
def test_sentence_again():
    assert_equal(
        parser.parse_sentence([
            ('verb', 'go'),
            ('direction', 'north')
        ]),
        parser.Sentence(
            ('noun', 'player'),
            ('verb', 'go'),
            ('direction', 'north')
        )
    )
Пример #45
0
def test_sentence():
    testsentence="the princess eat 100 bear 14 times"
    result=lexicon.scan(testsentence)
    sentence=parser.parse_sentence(result)
    assert_equal(sentence.subject, 'princess')
    assert_equal(sentence.verb, 'eat')
    assert_equal(sentence.amount, 100)
    assert_equal(sentence.object, 'bear')
    assert_equal(sentence.times, 14)
    
    testsentence="eat the bear"
    result=lexicon.scan(testsentence)
    sentence=parser.parse_sentence(result)
    assert_equal(sentence.subject, 'player')
    assert_equal(sentence.verb, 'eat')
    assert_equal(sentence.object, 'bear')
    
    testsentence="sdfsdfsf princess eat the bear"
    result=lexicon.scan(testsentence)
    sentence=parser.parse_sentence(result)
    assert_equal(sentence.subject, 'princess') 
Пример #46
0
def test_sentence():
    testsentence = "the princess eat 100 bear 14 times"
    result = lexicon.scan(testsentence)
    sentence = parser.parse_sentence(result)
    assert_equal(sentence.subject, 'princess')
    assert_equal(sentence.verb, 'eat')
    assert_equal(sentence.amount, 100)
    assert_equal(sentence.object, 'bear')
    assert_equal(sentence.times, 14)

    testsentence = "eat the bear"
    result = lexicon.scan(testsentence)
    sentence = parser.parse_sentence(result)
    assert_equal(sentence.subject, 'player')
    assert_equal(sentence.verb, 'eat')
    assert_equal(sentence.object, 'bear')

    testsentence = "sdfsdfsf princess eat the bear"
    result = lexicon.scan(testsentence)
    sentence = parser.parse_sentence(result)
    assert_equal(sentence.subject, 'princess')
Пример #47
0
def test_parse_sentence():
	a_word_list = lexicon.scan("it princess eat it")
	#a_test_sentence = parser.parse_sentence(a_word_list)
	assert_raises(parser.ParserError, parser.parse_sentence, a_word_list)
	b_word_list = lexicon.scan("eat princess")
	b_test_sentence = parser.parse_sentence(b_word_list)
	assert_equal(b_test_sentence.verb, 'eat')
	assert_equal(b_test_sentence.object, 'princess')
	assert_equal(b_test_sentence.subject, 'player')

	c_word_list = lexicon.scan("what is the matter?")
	assert_raises(parser.ParserError, parser.parse_sentence, c_word_list)
Пример #48
0
def test_parse_sentence():
    word_list = [('stop', 'the'), ('noun', 'princess'), ('verb', 'kill'),
                 ('noun', 'bear')]
    sentence = parser.parse_sentence(word_list)
    assert_equal(sentence.subject, 'princess')
    assert_equal(sentence.verb, 'kill')
    assert_equal(sentence.object, 'bear')

    word_list = [('noun', 'princess'), ('verb', 'kill'), ('noun', 'bear')]
    sentence = parser.parse_sentence(word_list)
    assert_equal(sentence.subject, 'princess')
    assert_equal(sentence.verb, 'kill')
    assert_equal(sentence.object, 'bear')

    word_list = [('verb', 'kill'), ('noun', 'bear')]
    sentence = parser.parse_sentence(word_list)
    assert_equal(sentence.subject, 'player')
    assert_equal(sentence.verb, 'kill')
    assert_equal(sentence.object, 'bear')

    word_list = [('direction', 'south'), ('noun', 'princess')]
    assert_raises(Exception, parser.parse_sentence, word_list)
Пример #49
0
def test_parser_with_subject():
    theCall = parser.parse_sentence([('stop', 'the'), 
                                     ('noun', 'bear'),
                                     ('verb', 'go'),
                                     ('stop', 'in'),
                                     ('stop', 'the'),                                  
                                     ('noun', 'cabinet')])
    result1 = getattr(theCall, 'subject')
    result2 = getattr(theCall, 'verb')
    result3 = getattr(theCall, 'object')

    assert_equal(result1, 'bear')
    assert_equal(result2, 'go')
    assert_equal(result3, 'cabinet')
Пример #50
0
def test_parse_sentence():
    word_list = lexicon.scan('the bear is go to the east')

    def re_sentence(parser_sentence):
        subj = parser_sentence.subject
        verb = parser_sentence.verb
        obj = parser_sentence.object
        return subj, verb, obj

    result = re_sentence(parser.parse_sentence(word_list))
    print(result)

    assert_equal(result, ('bear', 'go', 'east'))
    assert_raises(parser.ParserError, parser.parse_verb, [('noun', 'dog')])
Пример #51
0
def test_parse_sentence():
    word_list = lexicon.scan('the bear is go to the east')

    def re_sentence(parser_sentence):
        subj = parser_sentence.subject
        verb = parser_sentence.verb
        obj = parser_sentence.object
        return subj, verb, obj

    result = re_sentence(parser.parse_sentence(word_list))
    print(result)

    assert_equal(result, ('bear', 'go', 'east'))
    assert_raises(parser.ParserError, parser.parse_verb, [('noun', 'dog')])
Пример #52
0
def test_parse_sentence():
    # standard subject-verb-object
    line1 = "bear eat the princess"
    word_list1 = lexicon.scan(line1)
    parsed_sentence1 = parser.parse_sentence(word_list1)
    assert_equal("bear", parsed_sentence1.subject)
    assert_equal("eat", parsed_sentence1.verb)
    assert_equal("princess", parsed_sentence1.object)
    
    # only verb-object
    line2 = "eat the bear"
    word_list2 = lexicon.scan(line2)
    parsed_sentence2 = parser.parse_sentence(word_list2)
    assert_equal("player", parsed_sentence2.subject)
    assert_equal("eat", parsed_sentence2.verb)
    assert_equal("bear", parsed_sentence2.object)
    
    # random stop word
    line3 = "the bear eat the the princess"
    word_list3 = lexicon.scan(line3)
    parsed_sentence3 = parser.parse_sentence(word_list3)
    assert_equal("bear", parsed_sentence3.subject)
    assert_equal("eat", parsed_sentence3.verb)
    assert_equal("princess", parsed_sentence3.object)
Пример #53
0
def test_parse_sentence():
    result = parser.parse_sentence([('verb', 'hit'), ('noun', 'bear')])
    assert_equal(result.subject, 'player')
    assert_equal(result.verb, 'hit')
    assert_equal(result.object, 'bear')
Пример #54
0
def test_parse_some_stops_sentence():
    temp_sentence = parser.parse_sentence(some_stops_word_list)
    assert_equal(temp_sentence.subject, default_subject)
    assert_equal(temp_sentence.verb, default_verb)
    assert_equal(temp_sentence.object, default_object)
Пример #55
0
def test_parse_no_subject_sentence():
    temp_sentence = parser.parse_sentence(no_subject_word_list)
    assert_equal(temp_sentence.subject, 'player')
    assert_equal(temp_sentence.verb, default_verb)
    assert_equal(temp_sentence.object, default_object)
Пример #56
0
def test_parse_sentence():
    result = parser.parse_sentence(lexicon.scan("in princess go at east"))
    # test the object Sentence(result)

    word_list = lexicon.scan("I kill the bear")
    assert_raises(parser.ParserError, parser.parse_sentence, word_list)
Пример #57
0
def test_parse_sentence():
    word_list = lexicon.scan("the bear a eat a a a princess")
    m = parser.parse_sentence(word_list)

    assert_equal(('bear', 'eat', 'princess'), (m.subject, m.verb, m.object))
Пример #58
0
def test_subject():
    result = parser.parse_sentence([('verb', 'run'), ('direction', 'north')])
    assert_equal(result.subject, 'player')
    result2 = parser.parse_sentence([('noun', 'bear'), ('verb', 'eat'), ('stop', 'the'), ('noun', 'honey')])
    assert_equal(result2.subject, 'bear')
    assert_raises(ParserError, parser.parse_sentence, [('stop', 'the'), ('stop', 'and'), ('stop', 'at')])