Exemplo n.º 1
0
 def test_parse_subject(self):
     self.assertRaises(parser.ParserError, parser.parse_subject,
                       [('stop', 'it')])
     self.assertEqual(parser.parse_subject([('noun', 'tree')]),
                      ('noun', 'tree'))
     self.assertEqual(parser.parse_subject([('verb', 'think')]),
                      ('noun', 'player'))
Exemplo n.º 2
0
def test_parse_subject():
	word_list = lexicon.scan('the princess')
	assert_equal(parser.parse_subject(word_list), ('noun', 'princess'))
	word_list = lexicon.scan('the stop')
	assert_equal(parser.parse_subject(word_list), ('noun', 'player'))
	word_list = lexicon.scan('the')
	assert_raises(parser.ParserError, parser.parse_subject, word_list)
Exemplo n.º 3
0
def test_parse_subjects():
    assert_equal(parser.parse_subject([('stop', 'the'), ('noun', 'BMO')]),
                 ('noun', 'BMO'))
    assert_equal(parser.parse_subject([('stop', 'the'), ('verb', 'jump')]),
                 ('noun', 'player'))
    assert_equal(parser.parse_subject([('noun', 'BMO'), ('verb', 'jump')]),
                 ('noun', 'BMO'))
Exemplo n.º 4
0
def test_parse_subject():
    word_list = lexicon.scan("kill the bear")
    assert ('noun', "player") == parser.parse_subject(word_list)

    word_list = lexicon.scan("at the bear")
    assert ('noun', "bear") == parser.parse_subject(word_list)

    word_list = lexicon.scan("at the at")
Exemplo n.º 5
0
def test_parse_subject():
    word_list = [('stop', 'the'), ('noun', 'cow')]
    assert_equal(parser.parse_subject(word_list), ('noun', 'cow'))
    assert_equal(word_list, [])
    verb_list = [('stop', 'way'), ('verb', 'run')]
    assert_equal(parser.parse_subject(verb_list), ('noun', 'player'))
    error_list = [('stop', 'way'), ('direction', 'down')]
    assert_raises(parser.ParserError, parser.parse_subject, error_list)
Exemplo n.º 6
0
def test_parse_subject():
	word_list = [('noun', 'door'), ('verb', 'go'), ('direction', 'north'), ('stop', 'at')]
	assert_equal(parser.parse_subject(word_list), ('noun', 'door'))
	word_list = [('verb', 'go'), ('direction', 'north'), ('stop', 'at')]
	assert_equal(parser.parse_subject(word_list), ('noun', 'player'))
	word_list = [('direction', 'north'), ('stop', 'at')]
	assert_raises(parser.ParserError, parser.parse_subject, word_list)
	word_list = [('stop', 'at'), ('direction', 'north')]
	assert_raises(parser.ParserError, parser.parse_subject, word_list)
Exemplo n.º 7
0
def test_parse_subject():
    word_list1 = [("stop", "at"), ("stop", "the"), ("noun", "bear"),
                  ("direction", "north")]
    word_list2 = [("stop", "at"), ("verb", "go"), ("stop", "at")]
    word_list3 = [("stop", "at"), ("stop", "the"), ("direction", "north")]
    word_list4 = []
    assert_equal(parser.parse_subject(word_list1), ("noun", "bear"))
    assert_equal(parser.parse_subject(word_list2), ("noun", "player"))
    assert_raises(parser.ParserError, parser.parse_subject, word_list3)
    assert_raises(parser.ParserError, parser.parse_subject, word_list4)
Exemplo n.º 8
0
def test_parse_subject():
    wordlist = [('stop', 'the'), ('noun', 'bear')]
    result = parser.parse_subject(wordlist)
    assert_equal(result, ('noun', 'bear'))
    assert_equal(wordlist, [])

    wordlist = [('stop', 'the'), ('verb', 'run')]
    result = parser.parse_subject(wordlist)
    assert_equal(result, ('noun', 'player'))
    assert_equal(wordlist, [('verb', 'run')])
def test_parse_subject():
    sentence = lexicon.scan("bear")
    assert_equal(parser.parse_subject(sentence), ('noun', 'bear'))

    sentence = lexicon.scan("in in from the go")
    assert_equal(parser.parse_subject(sentence), ('noun', 'player'))

    with assert_raises(parser.ParserError):
        sentence = lexicon.scan("oh poop")
        parser.parse_subject(sentence)
Exemplo n.º 10
0
def test_parse_subject():
    assert_equal(parser.parse_subject(lexicon.scan("go north"), 
                 ('noun', 'bear')).subject,
                 parser.Sentence(('noun', 'bear'), 
                          ('verb', 'go'), 
                          ('direction', 'north')).subject)
    result = parser.parse_subject(lexicon.scan("eat cabinet"), ('noun', 'princess'))
    assert_equal(result.subject, parser.Sentence(('noun', 'princess'), 
                                          ('verb', 'eat'), 
                                          ('noun', 'cabinet')).subject)
def test_parse_subject():
    word_list = [('stop', 'of'), ('stop', 'the'), ('noun', 'honey')]
    assert_equal(parser.parse_subject(word_list), ('noun', 'honey'))

    word_list2 = [('stop', 'of'), ('stop', 'the'), ('verb', 'run')]
    assert_equal(parser.parse_subject(word_list2), ('noun', 'player'))

    assert_raises(Exception, parser.parse_subject, [('stop', 'of'),
                                                    ('stop', 'the'),
                                                    ('direction', 'north')])
Exemplo n.º 12
0
def test_parse_subject():
    word_list = [('stop', 'the'),
                 ('noun', 'cow')]
    assert_equal(parser.parse_subject(word_list), ('noun', 'cow'))
    assert_equal(word_list, [])
    verb_list = [('stop', 'way'),
                 ('verb', 'run')]
    assert_equal(parser.parse_subject(verb_list), ('noun', 'player'))
    error_list = [('stop', 'way'),
                  ('direction', 'down')]
    assert_raises(parser.ParserError, parser.parse_subject, error_list)
Exemplo n.º 13
0
def test_parse_subject():
    raw_word_list = [('stop', 'run'), ('noun', 'gogo'), ('direction', 'up')]
    assert_equal(parser.parse_subject(raw_word_list), ('noun', 'gogo'))

    player_word_list = [('verb', 'run'), ('noun', 'gogo'), ('direction', 'up')]
    assert_equal(parser.parse_subject(player_word_list), ('noun', 'player'))

    expected_error_message = "Expected a verb next."
    error_word_list = [('stop', 'run'), ('oh', 'go'), ('direction', 'up')]
    with assert_raises(parser.ParserError) as error:
        assert_equal(parser.parse_subject(error_word_list), ('oh', 'go'))
    assert_equal(error.exception.message, expected_error_message)
Exemplo n.º 14
0
def test_parse_subject():
	vector = lexicon.scan('kill bear jump')
	subject = ('noun','player')
	result = parser.parse_subject(vector, subject)
	assert_equal(result.subject, 'player')
	assert_equal(result.verb, 'kill')
	assert_equal(result.object, 'bear')
Exemplo n.º 15
0
def test_parsessubject():
    testsentence="eat the bear"
    result=lexicon.scan(testsentence)
    sentence=parser.parse_subject(result,('noun','player'))
    assert_equal(sentence.subject, 'player')
    assert_equal(sentence.verb, 'eat')
    assert_equal(sentence.object, 'bear')
Exemplo n.º 16
0
def test_parsessubject():
    testsentence = "eat the bear"
    result = lexicon.scan(testsentence)
    sentence = parser.parse_subject(result, ('noun', 'player'))
    assert_equal(sentence.subject, 'player')
    assert_equal(sentence.verb, 'eat')
    assert_equal(sentence.object, 'bear')
Exemplo n.º 17
0
def test_psub():
	sent = parser.parse_subject(lexicon.scan("eat the bear"), ('noun','princess'))
	subject = sent.subject
	verb = sent.verb
	object = sent.object
	assert_equal(subject, "princess")
	assert_equal(verb,"eat")
	assert_equal(object,"bear")
Exemplo n.º 18
0
def parse_subject():
    word_list = [('verb', 'eat'),
                 ('noun', 'princess')]

    sentence = parser.parse_subject(word_list, ('noun', 'bear'))
    print sentence.subject
    print sentence.verb
    print sentence.object
Exemplo n.º 19
0
def test_sentence():
    subj = parser.parse_subject([('stop', 'the'), ('noun', 'bear')])
    verb = parser.parse_verb([('stop', 'the'), ('verb', 'run'), ('direction', 'north')])
    obj = parser.parse_object([('stop', 'the'), ('direction', 'north')])
    sentence = parser.Sentence(subj, verb, obj)
    assert_equal(sentence.subject, "bear")
    assert_equal(sentence.verb, "run")
    assert_equal(sentence.object, "north")
Exemplo n.º 20
0
def test_parse_subject():
    word_list = lexicon.scan("go north")
    sen = parser.parse_subject(word_list, ("noun", "princess"))
    assert_equal(sen.subject, "princess")
    word_list = lexicon.scan("bear north")
    assert_raises(parser.ParserError, parser.parse_subject, word_list, ("noun", "princess"))
    word_list = lexicon.scan("go go")
    assert_raises(parser.ParserError, parser.parse_subject, word_list, ("noun", "princess"))
Exemplo n.º 21
0
def test_subject():

	assert_equal(
		parser.parse_subject([("verb", "kill"), 
							  ("noun", "bear")]),
		('noun', 'player')
	)
	assert_equal(
		parser.parse_subject([("noun", "bear"), 
							  ("verb", "eat"), 
							  ("noun", "princess")]),
		('noun', 'bear')
	)
	assert_raises(
		parser.ParserError, # expected error
		parser.parse_subject, # function to run
		[("direction", "north"), ("verb", "go")] # arg for function
	)
Exemplo n.º 22
0
def test_parse_subject():

    word_list1 = lexicon.scan("open the door")
    result = parser.parse_subject(word_list1, ('noun', 'princess'))
    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)
Exemplo n.º 23
0
def test_parse_subject():
    word_list = lexicon.scan("go north")
    sen = parser.parse_subject(word_list, ('noun', 'princess'))
    assert_equal(sen.subject, "princess")
    word_list = lexicon.scan("bear north")
    assert_raises(parser.ParserError, parser.parse_subject, word_list,
                  ('noun', 'princess'))
    word_list = lexicon.scan("go go")
    assert_raises(parser.ParserError, parser.parse_subject, word_list,
                  ('noun', 'princess'))
def test_parse_subject():
    subject = 'something'
    verb = ('verb', 'kill')
    obj = ('noun', 'bear')
    word_list = [verb, ('stop', 'the'), obj]

    actual = parser.parse_subject(word_list, subject)
    expect = parser.Sentence(subject, verb, obj)

    assert_sentence_equal(expect, actual)
Exemplo n.º 25
0
def test_parse_subject():
   subject = ('noun', 'princess')
   verb = ('verb', 'go')
   obj = ('direction', 'left')
   word_list = [verb, obj]
   s1 = parser.parse_subject(word_list, subject)
   s2 = Sentence(subject, verb, obj)
   assert_equal(s1.subject, s2.subject)
   assert_equal(s1.verb, s2.verb)
   assert_equal(s1.object, s2.object)
Exemplo n.º 26
0
def parse_subject_tests():
    word_list = [('verb', 'eat'), ('stop', 'the'), ('noun', 'bear')]
    sentence = parser.parse_subject(word_list, ('number', 0), ('noun', 'The Subject'))
    assert_equals(sentence.num_subjects, 0)
    assert_equals(sentence.subject, 'The Subject')
    assert_equals(sentence.verb, 'eat')
    assert_equals(sentence.object, 'bear')

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

    word_list = [('noun', 'bee'), ('verb', 'stung'), ('stop', 'the'), ('noun', 'human')]
    # in real usage, first tuple should have matched/been popped already
    assert_raises(parser.ParserError, parser.parse_subject, word_list, ('number', 0), ('noun', 'bee'))
    word_list = [('verb', 'stung'), ('stop', 'the'), ('adj', 'freaking'), ('noun', 'human')]
    # extra in front of the object
    assert_raises(parser.ParserError, parser.parse_subject, word_list, ('number', 0), ('noun', 'bee'))
Exemplo n.º 27
0
def test_subject():
    # 'go north' starts with a verb: implied subject == 'player'
    assert_equal(
        parser.parse_subject([
            ('verb', 'go'),
            ('direction', 'north')
        ]),
        ('noun', 'player')
    )
    # 'bear eat honey': subject is 'bear'
    assert_equal(
        parser.parse_subject([
            ('noun', 'bear'),
            ('verb', 'eat'),
            ('noun', 'honey')
        ]),
        ('noun', 'bear')
    )
    # 'back north': ParserError
    assert_raises(
        parser.ParserError,        # errorType
        parser.parse_subject,      # function expected to raise error
        [('direction', 'back'), ('direction', 'north')] # args
    )
def test_parse_subject():
    assert_equal(parser.parse_subject([('verb', 'stop')]), ('noun', 'player'))
Exemplo n.º 29
0
def test_parse_subject():
	sentence = [('verb', 'eat'), ('stop', 'a'), ('noun', 'bagel')]
	passing_sentence = ['Player', 'eat', 'bagel']
	result = parser.parse_subject(sentence, ('noun', 'Player'))
	result_sentence = [result.subject, result.verb, result.object]
	assert_equal(result_sentence, passing_sentence)
Exemplo n.º 30
0
def test_parse_subject():
    word_list = lexicon.scan("the bear  eat princess")
    assert_equal(('noun', 'bear'), parser.parse_subject(word_list))
    assert_equal(('noun', 'player'), parser.parse_subject(word_list))
Exemplo n.º 31
0
def test_parse_subject():
    result = parser.parse_subject(
        lexicon.scan("in of kill at princess 234 what"), ('noun', 'Player'))
Exemplo n.º 32
0
def test_subject():
    words = lexicon.scan("kill the bear")
    senten = parser.parse_subject(words, ('noun', 'fighter'))
    assert_equal(senten.subject, 'fighter')
    assert_equal(senten.verb, 'kill')
    assert_equal(senten.object, 'bear')
Exemplo n.º 33
0
def test_parse_subject():
    assert_equal(parser.parse_subject([('stop', 'the'), ('noun', 'bear')]), ('noun', 'bear'))
    assert_equal(parser.parse_subject([('stop', 'the'), ('verb', 'run')]), ('noun', 'player'))
    assert_raises(parser.ParserError, parser.parse_subject, [('direction', 'north')])
Exemplo n.º 34
0
def test_parse_subject():
    a_word_list = lexicon.scan("eat it princess")
    test_subject = parser.parse_subject(a_word_list, ('noun', 'subj'))
    assert_equal(test_subject.verb, 'eat')
    assert_equal(test_subject.object, 'princess')
    assert_equal(test_subject.subject, 'subj')
def test_parse_subject():
    word_list = lexicon.scan('eat door')
    subj = ('noun', 'bear')
    s = parser.parse_subject(word_list, subj)
    assert_equal(s.to_tuple(), ('bear', 'eat', 1, 'door'))
def test_parse_subject():
    assert_is_instance(parser.parse_subject(word_list_7, ('noun', 'princess')), parser.Sentence)
Exemplo n.º 37
0
def test_parse_subject():
	a_word_list = lexicon.scan("eat it princess")
	test_subject = parser.parse_subject(a_word_list, ('noun','subj'))
	assert_equal(test_subject.verb, 'eat')
	assert_equal(test_subject.object, 'princess')
	assert_equal(test_subject.subject, 'subj')
Exemplo n.º 38
0
def test_parse_subject():
    result = parser.parse_subject(lexicon.scan("in of kill at princess 234 what"), ('noun', 'Player'))
Exemplo n.º 39
0
def test_parse_subject():
    word_list = [('verb', 'open'), ('stop', 'the'), ('noun', 'door')]
    assert_equal(parser.parse_subject(word_list), ('noun', 'player'))
    assert_equal(parser.parse_subject(word_list), ('noun', 'player'))
Exemplo n.º 40
0
def test_parse_subject():
    subject = parser.parse_subject([('noun', 'bear')])
    assert_equal(subject, ('noun', 'bear'))
    
    subject = parser.parse_subject([('verb', 'run')])
    assert_equal(subject, ('noun', 'player'))
Exemplo n.º 41
0
def test_parse_subject():
    assert_equal(parser.parse_subject([('noun', 'hip')]), ('noun', 'hip'))
    assert_equal(parser.parse_subject([('stop', 'to'), ('verb', 'kill')]),
                 ('noun', 'player'))
    assert_raises(parser.ParserError, parser.parse_subject,
                  [('stop', 'to'), ('direction', 'north')])
Exemplo n.º 42
0
def parse_subject():
    word_list = [('verb', 'eat'), ('noun', 'princess')]
    sentence = parser.parse_subject(word_list, ('noun', 'bear'))
    assert_equal(sentence.subject, 'bear')
    assert_equal(sentence.verb, 'eat')
    assert_equal(sentence.object, 'princess')
def test_subject():
    assert_equal(parser.parse_subject([('noun', 'me')]), ('noun', 'me'))
Exemplo n.º 44
0
def test_parse_subject():
    subject = parser.parse_subject([('noun', 'bear')])
    assert_equal(subject, ('noun', 'bear'))

    subject = parser.parse_subject([('verb', 'run')])
    assert_equal(subject, ('noun', 'player'))
Exemplo n.º 45
0
def test_parse_subject():
    word_list = lexicon.scan('eat door')
    subj = ('noun', 'bear')
    s = parser.parse_subject(word_list, subj)
    assert_equal(s.to_tuple(), ('bear', 'eat', 1, 'door'))
Exemplo n.º 46
0
def test_parse_sentence():
    word_list = lexicon.scan("princess kill the bear")
    subj = parser.parse_subject(word_list)
    verb = parser.parse_verb(word_list)
    obj = parser.parse_object(word_list)
    assert parser.Sentence(subj, verb, obj)
Exemplo n.º 47
0
def test_parse_subject():
    word_list = lexicon.scan('eat door')
    s = parser.parse_subject(word_list, ('noun', 'player'))
    assert_equal(s.subject, 'player')
    assert_equal(s.verb, 'eat')
    assert_equal(s.object, 'door')