def test_chat_match_alternative(self): search_str = 'Zebra' res = { 'count': 1, 'similarity': 1, 'value': { 'subject': ('eels', 'Zebra Moray'), 'keywords': (('eel', 'snake-like'), ('zebra', 'strip', 'moray')), 'phrase': ('Zebra Moray', ), 'info': ({ 'name': 'Diet', 'value': 'Sea urchins, mollusks, and crustaceans.' }, ), 'isLeaf': True }, 'lastCount': 1, 'lastSimilarity': 1, 'matching': ('zebra', ), 'certainty': 2 } thisChat = Chat(flatten(resources), ['fishes', 'nothingthere']) self.assertEqual(thisChat.match(search_str), res)
def test_chat_match_prefer_up_tree(self): resources2 = [ { "name": "counseling", "keywords": ("counseling", ), "phrase": ("About counseling", ), "options": ("What counseling are you looking for?", ), "children": ({ "name": "Guidance", "keywords": ("guidance", ), "info": (), "isLeaf": True, "phrase": ("Guidance Service", ), }, ) }, ] search_str = 'counseling' res = { 'count': 1, 'similarity': 1, 'value': { 'subject': ('counseling', ), 'keywords': (('counsel', ), ), 'phrase': ('About counseling', ), 'options': ('What counseling are you looking for?', ), 'children': ('Guidance Service', ) }, 'lastCount': 1, 'lastSimilarity': 1, 'matching': ('counsel', ), 'certainty': 1 } thisChat = Chat(flatten(resources2), ()) self.assertEqual(thisChat.match(search_str), res)
def test_chat_match(self): search_str = 'Angler' res = { 'count': 1, 'lastCount': 1, 'lastSimilarity': 1, 'matching': ('angler', ), 'similarity': 1, 'value': { 'subject': ('fishes', 'deep sea fishes', 'Angler Fish'), 'keywords': (('fish', 'seafood', 'animal'), ('deep', 'bottom-dwellers'), ('angler', 'lophiiformes')), 'phrase': ('Angler Fish', ), 'info': ({ 'name': 'It has a light' }, ), 'isLeaf': True }, 'certainty': 1 } thisChat = Chat(flatten(resources), ['fishes', 'deep sea fishes']) self.assertEqual(thisChat.match(search_str), res)
def run_it(flattened_res, language, subject, search_str): this_chat = Chat(flattened_res, subject, language) return this_chat.match(search_str)