Example #1
0
	def test_find_returns_tuple_of_matching_words(self):
		lookupTable = LookUpTable()
		lookupTable._load_lookup(feature="organization", file_name="../sample/organizations.list")
		lookupTable._load_lookup(feature="name", file_name="../sample/names.list")
		result1 = lookupTable.find(feature="organization", text="Hello Jithin, where is aneesh?. Is facebook down?")
		result2 = lookupTable.find(feature="name", text="Hello Jithin/aneesh?. Is facebook down?")
		self.assertTrue(result1==("facebook",) and result2==("Jithin", "aneesh",))
Example #2
0
	def test_find_from_file_returns_tuple_of_matching_words(self):
		lookupTable = LookUpTable()
		lookupTable._load_lookup(feature="organization", file_name="../sample/organizations.list")
		lookupTable._load_lookup(feature="name", file_name="../sample/names.list")
		result1 = lookupTable.find_from_file(feature="organization", file_name="../sample/sample2.txt")
		result2 = lookupTable.find_from_file(feature="name", file_name="../sample/sample2.txt")
		self.assertTrue(result1==("facebook",) and result2==("Jithin", "aneesh",))
Example #3
0
	def test_matching_tokens_returns_list_of_tokens_matching_specified_lookup(self):
		lookupTable = LookUpTable()
		lookupTable._load_lookup(feature="name", file_name="../sample/names.list")
		tokens = ["Hello", "Jithin", "where", "is", "aneesh", "Is", "facebook", "down"]
		result = lookupTable._matching_tokens(feature="name", tokens=tokens)
		self.assertEqual(result, ("Jithin", "aneesh",))
Example #4
0
	def test_find_from_file_raises_value_error_if_file_given_is_invalid(self):
		lookupTable = LookUpTable()
		lookupTable._load_lookup(feature="name", file_name="../sample/names.list")
		self.assertRaises(IOError, lookupTable.find_from_file, feature="name", file_name="../sample/unavailable.txt")
Example #5
0
	def test_find_raises_value_error_if_feature_not_exists(self):
		lookupTable = LookUpTable()
		lookupTable._load_lookup(feature="name", file_name="../sample/names.list")
		self.assertRaises(KeyError, lookupTable.find, feature="fruit", text="Hello Jithin, where is aneesh?")
Example #6
0
	def test_find_returns_list_of_tuples(self):
		lookupTable = LookUpTable()
		lookupTable._load_lookup(feature="name", file_name="../sample/names.list")
		result = lookupTable.find(feature="name", text="Hello Jithin, where is aneesh?")
		self.assertEqual(result, ("Jithin", "aneesh"))
Example #7
0
	def test_absolute_file_path_returns_absolute_path_of_given_file(self):
		lookupTable = LookUpTable()
		result = lookupTable._absolute_file_path(file_name="../sample/sample2.txt")
		self.assertEqual(result, "/home/qbuser/Galileo/parrot/lib/../sample/sample2.txt")
Example #8
0
	def test_match_returns_true_if_word_is_a_feature(self):
		lookupTable = LookUpTable()
		lookupTable._load_lookup(feature="organization", file_name="../sample/organizations.list")
		lookupTable._load_lookup(feature="name", file_name="../sample/names.list")
		self.assertTrue(lookupTable._match(feature="name", word="Akhil"))
Example #9
0
	def test_load_custom_lookups_returns_list_lookups_added_for_file_param(self):
		lookupTable = LookUpTable()
		result = lookupTable.load_custom_lookups(path="../sample/my_custom_repo/organization.list")
		self.assertEqual(result, ["organization"])
Example #10
0
	def test_load_custom_lookups_returns_list_lookups_added_for_directory_param(self):
		lookupTable = LookUpTable()
		result = lookupTable.load_custom_lookups(path="../sample/my_custom_repo")
		self.assertEqual(result, ["organization", "name",])
Example #11
0
	def test__load_lookup_returns_true_if_loading_lookup_from_file_success(self):
		lookupTable = LookUpTable()
		result = lookupTable._load_lookup(feature="name", file_name="../sample/names.list")
		self.assertTrue(result)
Example #12
0
	def test__load_lookup_raises_value_error_if_feature_already_exists(self):
		lookupTable = LookUpTable()
		lookupTable._load_lookup(feature="name", file_name="../sample/names.list")
		self.assertRaises(KeyError, lookupTable._load_lookup, "name", "../sample/names.list")
Example #13
0
	def test_read_lines_returns_list_of_keywords(self):
		lookupTable = LookUpTable()
		result = lookupTable._read_lines("../sample/names.list", lookup_file=True)
		self.assertEqual(result, ["jithin", "sajith", "uvais", "akhil", "aneesh", "abhijith", "rohith"])
Example #14
0
	def test_available_features_returns_list_of_features_added(self):
		lookupTable = LookUpTable()
		lookupTable._load_lookup(feature="organization", file_name="../sample/organizations.list")
		lookupTable._load_lookup(feature="name", file_name="../sample/names.list")
		result = lookupTable.available_features()
		self.assertEqual(result, ["organization", "name"])
Example #15
0
	def test_tokenize_returns_list_of_words(self):
		lookupTable = LookUpTable()
		tokens = lookupTable._tokenize("Hello world from Jithin")
		self.assertEqual(tokens, ["Hello", "world", "from", "Jithin",])
Example #16
0
	def test_find_all_returns_list_of_tuples_maping_word_with_feature(self):
		lookupTable = LookUpTable()
		lookupTable._load_lookup(feature="organization", file_name="../sample/organizations.list")
		lookupTable._load_lookup(feature="name", file_name="../sample/names.list")
		result = lookupTable.find_all(text="Hello Jithin, where is aneesh?. Is facebook down?")
		self.assertEqual(result, [("facebook", "organization"), ("Jithin", "name"), ("aneesh", "name"), ])
Example #17
0
	def test_available_features_returns_none_if_features_not_added_yet(self):
		lookupTable = LookUpTable()
		result = lookupTable.available_features()
		self.assertEqual(result, None)