Пример #1
0
def test_parse_object():
	# parsing with empty word list
	word_list = []
	assert_raises(ParserError, parser.parse_object, word_list)

	# parsing correct word lists
	word_list = lexicon.scan("Of in the princess")
	assert_equal(parser.parse_object(word_list), ("noun", "princess"))

	word_list = lexicon.scan("bear")
	assert_equal(parser.parse_object(word_list), ("noun", "bear"))


	word_list = lexicon.scan("from at in the south")
	assert_equal(parser.parse_object(word_list), ("direction", "south"))

	word_list = lexicon.scan("down")
	assert_equal(parser.parse_object(word_list), ("direction", "down"))

	# parsing incorrect word lists
	word_list = lexicon.scan("go")
	assert_raises(ParserError, parser.parse_object, word_list)

	word_list = lexicon.scan("from at in the 98")
	assert_raises(ParserError, parser.parse_object, word_list)
Пример #2
0
def test_parse_object():
    word_list = lexicon.scan('the cabinet')
    assert_equal(parser.parse_object(word_list), ('noun', 'cabinet'))
    word_list = lexicon.scan('the north')
    assert_equal(parser.parse_object(word_list), ('direction', 'north'))
    word_list = lexicon.scan('in of the eat bla')
    assert_raises(parser.ParserError, parser.parse_object, word_list)
Пример #3
0
def test_parse_object():
  test = [('stop', 'the'), ('noun', 'bear')]
  assert_equal(parser.parse_object(test), ('noun', 'bear'))
  test2 = [('stop', 'go'), ('direction', 'up')]
  assert_equal(parser.parse_object(test2), ('direction', 'up'))
  test3 = [('verb', 'punch'), ('stop', 'the'), ('noun', 'bear')]
  assert_raises(parser.ParseError, parser.parse_object, test3)
Пример #4
0
def test_parse_object():
    word_list = lexicon.scan("the door")
    assert_equal(parser.parse_object(word_list), ("noun", "door"))
    word_list = lexicon.scan("the east")
    assert_equal(parser.parse_object(word_list), ("direction", "east"))
    word_list = lexicon.scan("the it")
    assert_raises(parser.ParserError, parser.parse_object, word_list)
Пример #5
0
def test_parse_object():
    word_list = lexicon.scan('the door')
    assert_equal(parser.parse_object(word_list), ('noun', 'door'))
    word_list = lexicon.scan('the east')
    assert_equal(parser.parse_object(word_list), ('direction', 'east'))
    word_list = lexicon.scan('the it')
    assert_raises(parser.ParserError, parser.parse_object, word_list)
Пример #6
0
def test_parse_object():
    word_list = lexicon.scan('the door')
    assert_equal(parser.parse_object(word_list), ('noun', 'door'))
    word_list = lexicon.scan('the east')
    assert_equal(parser.parse_object(word_list), ('direction', 'east'))
    word_list = lexicon.scan('the it')
    assert_raises(parser.ParserError, parser.parse_object, word_list)
Пример #7
0
def testing_parse_object():
    '''testing the parse_object function.'''
    word_list = lexicon.scan('the princess')
    assert_equal(parser.parse_object(word_list), ('noun', 'princess'))
    word_list = lexicon.scan('the south')
    assert_equal(parser.parse_object(word_list), ('direction', 'south'))
    word_list = lexicon.scan('the kill')
    assert_raises(parser.ParseError, parser.parse_object, word_list)
Пример #8
0
def test_parse_object():
	word_list = lexicon2.scan('princess')
	word_list2 = lexicon2.scan('north')
	word_list3 = lexicon2.scan('the it')
	parser.parse_object([('noun', 'princess'), ('direction', 'north')])
	assert_equal(parser.parse_object(word_list), ('noun', 'princess'))
	assert_equal(parser.parse_object(word_list2), ('direction', 'north'))
	assert_raises(parser.ParserError, parser.parse_object, word_list3)
Пример #9
0
def test_object():
    word_list = lexicon.scan("the door")
    result = parser.parse_object(word_list)
    assert_equal(result, ("noun", "door"))

    word_list = lexicon.scan("now east")
    result = parser.parse_object(word_list)
    assert_equal(result, ("direction", "east"))
def test_object():
    word_list = lexicon.scan("the door")
    result = parser.parse_object(word_list)
    assert_equal(result, ('noun', 'door'))

    word_list = lexicon.scan("now east")
    result = parser.parse_object(word_list)
    assert_equal(result, ('direction', 'east'))
Пример #11
0
def test_parse_object():
    assert_equal(
        parser.parse_object([('noun', 'bear'), ('verb', 'go'),
                             ('direction', 'north')]), ('noun', 'bear'))
    assert_equal(
        parser.parse_object([('direction', 'south'), ('verb', 'go'),
                             ('noun', 'bear')]), ('direction', 'south'))
    assert_raises(parser.ParserError, parser.parse_object, [('verb', 'kill'),
                                                            ('stop', 'of'),
                                                            ('verb', 'go')])
Пример #12
0
def test_parse_object():
    scanner = lexicon.scan("the north bear")
    assert_equal(scanner, [('stop', 'the'), ('direction', 'north'),
                           ('noun', 'bear')])
    assert_equal(parser.parse_object(scanner), ('direction', 'north'))
    assert_equal(scanner, [('noun', 'bear')])

    scanner = lexicon.scan("the bear north")
    assert_equal(scanner, [('stop', 'the'), ('noun', 'bear'),
                           ('direction', 'north')])
    assert_equal(parser.parse_object(scanner), ('noun', 'bear'))
    assert_equal(scanner, [('direction', 'north')])
def test_parse_object():
    # test that parse_object removes/skips stop words and returns the object tuple wen the object is a noun
    word_list = [('stop', 'at'), ('stop', 'the'), ('noun', 'bear'), ('stop', 'is')]
    assert_equal(parser.parse_object(word_list), ('noun', 'bear'))
    
    # test that parse_object removes/skips stop words and returns the object tuple wen the object is a direction
    word_list = [('stop', 'at'), ('stop', 'the'), ('direction', 'north'), ('stop', 'is')]
    assert_equal(parser.parse_object(word_list), ('direction', 'north'))
    
    # test that parse_object raises an error when an object is not next in word_list (after removing stop words)
    word_list = [('stop', 'at'), ('stop', 'the'), ('verb', 'run'), ('stop', 'is')]
    assert_raises(parser.ParserError, parser.parse_object, word_list)
Пример #14
0
def test_pobj():
    assert_equal(parser.parse_object(lexicon.scan("the bear kill")),
                 ('noun', 'bear'))
    assert_equal(parser.parse_object(lexicon.scan("princess in north")),
                 ('noun', 'princess'))
    assert_equal(parser.parse_object(lexicon.scan("PRINCESS in north")),
                 ('noun', 'PRINCESS'))
    assert_equal(parser.parse_object(lexicon.scan("North bear")),
                 ('direction', 'North'))
    assert_equal(parser.parse_object(lexicon.scan("north the princess")),
                 ('direction', 'north'))
    assert_raises(Exception, parser.parse_object,
                  lexicon.scan("go in the north"))
Пример #15
0
def test_object():
    test_list = [('noun', 'princess')]
    result = parser.parse_object(test_list)
    assert_equal(result, ('noun', 'princess'))

    test_list = [('direction', 'east')]
    result = parser.parse_object(test_list)
    assert_equal(result, ('direction', 'east'))

    test_list = [('stop', 'in'),('direction', 'east')]
    result = parser.parse_object(test_list)
    assert_equal(result, ('direction', 'east'))

    assert_raises(parser.ParserError, parser.parse_object, [])
Пример #16
0
def test_object():
    test_list = [('noun', 'princess')]
    result = parser.parse_object(test_list)
    assert_equal(result, ('noun', 'princess'))

    test_list = [('direction', 'east')]
    result = parser.parse_object(test_list)
    assert_equal(result, ('direction', 'east'))

    test_list = [('stop', 'in'), ('direction', 'east')]
    result = parser.parse_object(test_list)
    assert_equal(result, ('direction', 'east'))

    assert_raises(parser.ParserError, parser.parse_object, [])
Пример #17
0
def test_parse_object():
    word_list_1 = [('noun', 'dog'), ('verb', 'go'), ('direction', 'north'),
                   ('stop', 'with'), ('noun', 'bear')]
    result = parser.parse_object(word_list_1)
    assert_equal(result, ('noun', 'dog'))  # Next word is a noun

    word_list_2 = [('stop', 'the'), ('noun', 'cows'), ('verb', 'go'),
                   ('direction', 'north'), ('stop', 'with'), ('noun', 'bears')]
    result = parser.parse_object(word_list_2)
    assert_equal(result,
                 ('noun', 'cows'))  # Next word is a noun, skip the 'stop'

    word_list_3 = [('adverb', 'quickly'), ('verb', 'run'),
                   ('direction', 'north'), ('stop', 'with'), ('stop', 'the'),
                   ('noun', 'bears')]

    assert_raises(parser.ParserError, parser.parse_object, word_list_3)
Пример #18
0
def test_parse_sentence():
    word_list = [("noun", "bear"), ("stop", "the"), ("verb", "eat"),
                 ("noun", "honey")]
    subj = parser.parse_subject(word_list)
    verb = parser.parse_verb(word_list)
    obj = parser.parse_object(word_list)

    x = parser.Sentence(subj, verb, obj)
    y = parser.Sentence(("noun", "bear"), ("verb", "eat"), ("noun", "honey"))

    assert_equal(x.subject, y.subject)
    assert_equal(x.object, y.object)
    assert_equal(x.verb, y.verb)
Пример #19
0
def test_parse_object():
    x = parser.parse_object([("noun", "bear")])
    assert_equal(x, ("noun", "bear"))

    y = parser.parse_object([("direction", "north")])
    assert_equal(y, ("direction", "north"))
Пример #20
0
def TestObject():
    inputsent = lexicon.scan("the eat castle")
    assert_raises(parser.ParserError, parser.parse_object, inputsent)
    inputsent = lexicon.scan("the bear castle")
    assert_equal(('noun', 'bear'), parser.parse_object(inputsent))
Пример #21
0
def test_parse_object():
    assert_raises(parser.ParseError,parser.parse_object,([('stop', 'the'), ('stop', 'of')], None))
    assert_equal(parser.parse_object([('stop', 'the'), ('stop', 'of'), ('noun', 'princess')]),('noun', 'princess'))
    assert_equal(parser.parse_object([('stop', 'the'), ('direction', 'east')]), ('direction', 'east'))
Пример #22
0
def test_parse_object():
    wordlist = [("noun", "princess")]
    assert_equal(parser.parse_object(wordlist), ("noun", "princess"))

    wordlist2 = [("verb", "kill")]
    assert_raises(parser.ParserError, parser.parse_object, wordlist2)
Пример #23
0
def test_parse_object():
	word_list = lexicon.scan(sentence)
	assert_equal(parser.parse_object(word_list), ('noun', 'princess'))
	word_list = lexicon.scan(obj_sentence)
	assert_equal(parser.parse_object(word_list), ('direction', 'east'))
	assert_raises(parser.ParserError, parser.parse_object, word_list)
Пример #24
0
def test_parse_object():
    assert_equal(parser.parse_object([('noun', 'prince')]), ('noun', 'prince'))
    assert_equal(parser.parse_object([('direction', 'north')]),
                 ('direction', 'north'))
    assert_raises(parser.ParserError, parser.parse_object,
                  [('verb', 'chortle')])
Пример #25
0
def test_parse_object():
    
    assert_equal(parser.parse_object(word_list), ('noun', 'door'))