def test_remove_if_found_in_larger_string(self): all_found = [ {'term': 'blue', 'start': 0, 'tokens': ['blue'], 'position': '0_4', 'end': 4, 'found_item': [ {'type': 'color', 'match_type': 'alias', 'key': 'blue', 'display_name': 'blue', 'source': 'content'}]}, {'term': 'heels', 'start': 10, 'tokens': ['heels'], 'position': '10_15', 'end': 15, 'found_item': [ {'type': 'style', 'match_type': 'alias', 'key': 'heels', 'display_name': 'display_name', 'source': 'content'}]}, {'term': 'high heels', 'start': 5, 'tokens': ['high', 'heels'], 'position': '5_15', 'end': 15, 'found_item': [ {'type': 'style', 'match_type': 'alias', 'key': 'high heels', 'display_name': 'display_name', 'source': 'content'}]} ] target = Target({}) actual = target.format_found_entities(all_found) self.assertListEqual( [ { 'term': 'blue', 'start': 0, 'tokens': ['blue'], 'position': '0_4', 'end': 4, 'found_item': [ {'type': 'color', 'match_type': 'alias', 'key': 'blue', 'display_name': 'blue', 'source': 'content'} ] }, { 'term': 'high heels', 'start': 5, 'tokens': ['high', 'heels'], 'position': '5_15', 'end': 15, 'found_item': [ {'type': 'style', 'match_type': 'alias', 'key': 'high heels', 'display_name': 'display_name', 'source': 'content'} ] } ], actual )
def test_no_autocorrection(self): target = Target({}) target.find_matches = Mock() target.find_matches.return_value = { "found": "find_matches_found", "can_not_match": "find_matches_can_not_match" } target.autocorrect_query = Mock() target.autocorrect_query.return_value = None target.key_matches = Mock(return_value="key_matches:return_value") target.unique_non_detections = Mock() target.unique_non_detections.return_value = "unique_non_detections:return_value" target.format_found_entities = Mock() target.format_found_entities.return_value = "formated_found_entities" actual = target.detect_entities( "vocab", { "tokens": "preperation_result:tokens", "used_query": "preperation_result:used_query" } ) self.assertEqual(1, target.find_matches.call_count) self.assertEqual(3, target.find_matches.call_args_list[0][0][0]) self.assertEqual("preperation_result:tokens", target.find_matches.call_args_list[0][0][1]) self.assertEqual( target.find_matches.call_args_list[0][0][2], 'vocab' ) self.assertEqual(1, target.autocorrect_query.call_count) self.assertEqual('preperation_result:used_query', target.autocorrect_query.call_args_list[0][0][0]) self.assertEqual('formated_found_entities', target.autocorrect_query.call_args_list[0][0][1]) self.assertEqual(1, target.key_matches.call_count) self.assertEqual('formated_found_entities', target.key_matches.call_args_list[0][0][0]) self.assertEqual(1, target.unique_non_detections.call_count) self.assertEqual('find_matches_can_not_match', target.unique_non_detections.call_args_list[0][0][0]) self.assertDictEqual( { 'detections': 'key_matches:return_value', 'non_detections': 'unique_non_detections:return_value' }, actual )
def test_autocorrection(self): target = Target({}) target.find_matches = Mock() target.find_matches.return_value = { "found": "find_matches_found", "can_not_match": "find_matches_can_not_match" } target.autocorrect_query = Mock() target.autocorrect_query.return_value = "autocorrected_query_new_value" target.key_matches = Mock(return_value="key_matches:return_value") target.unique_non_detections = Mock() target.unique_non_detections.return_value = "unique_non_detections:return_value" target.format_found_entities = Mock() target.format_found_entities.return_value = "formated_found_entities" actual = target.detect_entities( "vocab", { "tokens": "preperation_result:tokens", "used_query": "preperation_result:used_query" }) self.assertEqual(1, target.find_matches.call_count) self.assertEqual(3, target.find_matches.call_args_list[0][0][0]) self.assertEqual("preperation_result:tokens", target.find_matches.call_args_list[0][0][1]) self.assertEqual('vocab', target.find_matches.call_args_list[0][0][2]) self.assertEqual(target.autocorrect_query.call_count, 1) self.assertEqual(target.autocorrect_query.call_args_list[0][0][0], 'preperation_result:used_query') self.assertEqual(target.autocorrect_query.call_args_list[0][0][1], 'formated_found_entities') self.assertEqual(target.key_matches.call_count, 1) self.assertEqual(target.key_matches.call_args_list[0][0][0], 'formated_found_entities') self.assertEqual(target.unique_non_detections.call_count, 1) self.assertEqual(target.unique_non_detections.call_args_list[0][0][0], 'find_matches_can_not_match') self.assertDictEqual( actual, { 'autocorrected_query': 'autocorrected_query_new_value', 'detections': 'key_matches:return_value', 'non_detections': 'unique_non_detections:return_value' })
def test_remove_if_found_in_larger_string(self): all_found = [{ 'term': 'blue', 'start': 0, 'tokens': ['blue'], 'position': '0_4', 'end': 4, 'found_item': [{ 'type': 'color', 'match_type': 'alias', 'key': 'blue', 'display_name': 'blue', 'source': 'content' }] }, { 'term': 'heels', 'start': 10, 'tokens': ['heels'], 'position': '10_15', 'end': 15, 'found_item': [{ 'type': 'style', 'match_type': 'alias', 'key': 'heels', 'display_name': 'display_name', 'source': 'content' }] }, { 'term': 'high heels', 'start': 5, 'tokens': ['high', 'heels'], 'position': '5_15', 'end': 15, 'found_item': [{ 'type': 'style', 'match_type': 'alias', 'key': 'high heels', 'display_name': 'display_name', 'source': 'content' }] }] target = Target({}) actual = target.format_found_entities(all_found) self.assertListEqual([{ 'term': 'blue', 'start': 0, 'tokens': ['blue'], 'position': '0_4', 'end': 4, 'found_item': [{ 'type': 'color', 'match_type': 'alias', 'key': 'blue', 'display_name': 'blue', 'source': 'content' }] }, { 'term': 'high heels', 'start': 5, 'tokens': ['high', 'heels'], 'position': '5_15', 'end': 15, 'found_item': [{ 'type': 'style', 'match_type': 'alias', 'key': 'high heels', 'display_name': 'display_name', 'source': 'content' }] }], actual)