Beispiel #1
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)
Beispiel #2
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)
def test_parse_sentence():
	a_sentence = parser.parse_sentence([('stop', 'on'), ('noun', 'bear'), ('verb', 'eat'), ('direction', 'north')])
	assert_equal(a_sentence.subject, 'bear')
	assert_equal(a_sentence.verb, 'eat')
	assert_equal(a_sentence.object, 'north')

	a_sentence = parser.parse_sentence([('stop', 'on'), ('verb', 'eat'), ('direction', 'north')])
	assert_equal(a_sentence.subject, 'player')
	assert_equal(a_sentence.verb, 'eat')
	assert_equal(a_sentence.object, 'north')

	assert_raises(parser.parse_sentence([('direction', 'north'), ('noun', 'bear'), ('verb', 'eat')]))
Beispiel #4
0
def test_parse_sentence():
    sen1 = parser.parse_sentence([('verb', 'go'), ('direction', 'east')])
    assert_equal(sen1.subject, 'player')
    assert_equal(sen1.verb, 'go')
    assert_equal(sen1.object, 'east')

    sen2 = parser.parse_sentence([('noun', 'bear'), ('verb', 'go'),
                                  ('stop', 'the'), ('direction', 'east')])
    assert_equal(sen2.subject, 'bear')
    assert_equal(sen2.verb, 'go')
    assert_equal(sen2.object, 'east')

    assert_raises(parser.ParseError, parser.parse_sentence, [('stop', 'the'),
                                                             ('number', 123)])
Beispiel #5
0
def test_numbers():
    word_list = lexicon.scan('xxx the xxx bear xxx eat xxx 5 xxx door xxx')
    s = parser.parse_sentence(word_list)
    assert_equal(s.to_tuple(), ('bear', 'eat', 5, 'door'))
Beispiel #6
0
def test_numbers():
    word_list = lexicon.scan('xxx the xxx bear xxx eat xxx 5 xxx door xxx')
    s = parser.parse_sentence(word_list)
    assert_equal(s.to_tuple(), ('bear', 'eat', 5, 'door'))