Exemplo n.º 1
0
	def test_equal_true1(self):
		sentence = "not nice"
		tree1 = text_to_trees(sentence)[0]
		tree2 = text_to_trees(sentence)[0]
		adj1 = Adjective(tree1)
		adj2 = Adjective(tree2)
		self.assertEqual(adj1, adj2)
Exemplo n.º 2
0
	def test_not_equal(self):
		sentence1 = "awesome"
		sentence2 = "nice"
		tree1 = text_to_trees(sentence1)[0]
		tree2 = text_to_trees(sentence2)[0]
		adj1 = Adjective(tree1)
		adj2 = Adjective(tree2)
		self.assertNotEqual(adj1, adj2)
Exemplo n.º 3
0
	def test_get_adjective_match1(self):
		adj_str = "sweet"
		noun_str = "pig"
		adj_tree = text_to_trees(adj_str)[0]
		noun_tree = text_to_trees(noun_str)[0]
		adj = Adjective(adj_tree)
		noun = Noun(noun_tree)
		noun.add_adjective(adj)
		adj_match = noun.get_adjective_match(adj)
		self.assertEqual(adj, adj_match)
Exemplo n.º 4
0
	def test_combine1(self):
		sentence1 = "nice"
		sentence2 = "not nice"
		tree1 = text_to_trees(sentence1)[0]
		tree2 = text_to_trees(sentence2)[0]
		adj1 = Adjective(tree1)
		adj2 = Adjective(tree2)
		self.assertFalse(adj1.is_negated)
		self.assertTrue(adj2.is_negated)
		adj1.combine(adj2)
		self.assertTrue(adj1.is_negated)
Exemplo n.º 5
0
	def test_get_adjective_match2(self):
		adj_str1 = "sweet"
		adj_str2 = "not " + adj_str1
		noun_str = "pig"
		adj_tree1 = text_to_trees(adj_str1)[0]
		adj_tree2 = text_to_trees(adj_str2)[0]
		noun_tree = text_to_trees(noun_str)[0]
		adj1 = Adjective(adj_tree1)
		adj2 = Adjective(adj_tree2)
		noun = Noun(noun_tree)
		noun.add_adjective(adj2)
		adj_match = noun.get_adjective_match(adj1)
		self.assertTrue(adj_match.is_negated)
Exemplo n.º 6
0
	def test_add_adjective(self):
		noun_str = "pig"
		adj_str1 = "cute"
		adj_str2 = "not " + adj_str1
		noun_tree = text_to_trees(noun_str)[0]
		adj_tree1 = text_to_trees(adj_str1)[0]
		adj_tree2 = text_to_trees(adj_str2)[0]
		noun = Noun(noun_tree)
		adj1 = Adjective(adj_tree1)
		adj2 = Adjective(adj_tree2)
		noun.add_adjective(adj1)
		noun.add_adjective(adj2)
		description = noun.describe()
		self.assertIn(adj_str2, description)
Exemplo n.º 7
0
	def test_constructor_pass(self):
		verb_tree = text_to_trees(verb_str1)[0]
		noun = text_to_obj(noun_str1, Noun)
		try:
			verb = Verb(verb_tree, noun)
		except TypeError:
			self.fail("verb constructor threw an exception when given a verb tree")
Exemplo n.º 8
0
def text_to_verb(text, subj_str, obj_str):
	noun_subj = text_to_obj(subj_str, Noun)
	noun_obj = None
	if obj_str:
		noun_obj = text_to_obj(obj_str, Noun)
	verb_tree = text_to_trees(text)[0]
	return Verb(verb_tree, noun_sbj, noun_obj)
Exemplo n.º 9
0
	def tell(self, statement):
		trees = text_to_trees(statement)
		questions = [stmt for stmt in trees if stmt.is_question()]
		statements = [stmt for stmt in trees if stmt not in questions]
		if questions:
			return get_answers(questions, self.knowledge, format_question_answers)
		else:
			return get_answers(statements, self.knowledge, format_stmt_answers)
Exemplo n.º 10
0
	def test_description(self):
		noun_word = "pig"
		adj_word1 = "nice"
		adj_word2 = "not cool"
		sentence1 = "the only " + noun_word
		sentence2 = adj_word1
		sentence3 = "very " + adj_word2
		noun_tree = text_to_trees(sentence1)[0]
		adj_tree1 = text_to_trees(sentence2)[0]
		adj_tree2 = text_to_trees(sentence3)[0]
		noun = Noun(noun_tree)
		noun.add_adjective(adj_tree1)
		noun.add_adjective(adj_tree2)
		description = noun.describe()
		self.assertIn(noun_word, description)
		self.assertIn(adj_word1, description)
		self.assertIn(adj_word2, description)
Exemplo n.º 11
0
	def test_empty_description(self):
		noun_word = "pig"
		sentence = "a nice " + noun_word
		tree = text_to_trees(sentence)[0]
		noun = Noun(tree)
		expected_description = "I don't know anything about " + noun_word
		description = noun.describe()
		self.assertEqual(expected_description, description)
Exemplo n.º 12
0
	def test_invalid_constructor(self):
		sentence = "very nice"
		tree = text_to_trees(sentence)[0]
		self.assertRaises(TypeError, Noun, tree)
Exemplo n.º 13
0
	def test_combine2(self):
		sentence = "nice"
		tree = text_to_trees(sentence)[0]
		adj1 = Adjective(tree)
		adj2 = Adjective(tree)
		self.assertTrue(adj1.combine(adj2))
Exemplo n.º 14
0
	def test_constructor(self):
		sentence = "nice"
		tree = text_to_trees(sentence)[0]
		expected_result = sentence
		adj = Adjective(tree)
		self.assertEqual(adj.__str__(), expected_result)
Exemplo n.º 15
0
	def test_is_negated_false(self):
		text = "bad"
		tree = text_to_trees(text)[0]
		self.assertFalse(tree.is_negated())
Exemplo n.º 16
0
	def test_is_negated_true(self):
		text = "not bad"
		tree = text_to_trees(text)[0]
		self.assertTrue(tree.is_negated())
Exemplo n.º 17
0
	def test_constructor_fail(self):
		noun_tree = text_to_trees(noun_str1)[0]
		self.assertRaises(TypeError, Verb, noun_tree)
Exemplo n.º 18
0
def text_to_obj(text, constructor):
	tree = text_to_trees(text)[0]
	return constructor(tree)