def test_entity_finder_regex_single_word_only(): finder = LegacyEntityFinder() regex = setup_regex() finder.setup_regex_entities(regex) found_matches = finder.find_entity_values("I want a Large biscuit") assert(len(found_matches)) == 1 assert(len(found_matches["Large"]) == 1) assert("CakeSizeRegex" in found_matches["Large"])
def test_entity_finder_regex(): finder = LegacyEntityFinder() regex = setup_regex() finder.setup_regex_entities(regex) found_matches = finder.find_entity_values("I want a large cake") assert(len(found_matches)) == 2 assert(len(found_matches["large"]) == 1) assert("CakeSizeRegex" in found_matches["large"]) assert(len(found_matches["cake"]) == 1) assert("CakeTypeRegex" in found_matches["cake"])
def test_entity_finder_list_type_priority(): finder = LegacyEntityFinder() values = setup_data() regex = setup_regex() finder.setup_entity_values(values) finder.setup_regex_entities(regex) found_matches = finder.find_entity_values("Large") assert(len(found_matches)) == 1 assert(len(found_matches["Large"]) == 1) assert("CakeSize" in found_matches["Large"])
def test_entity_finder_regex_and_standard(): finder = LegacyEntityFinder() values = setup_data() regex = setup_regex() finder.setup_entity_values(values) finder.setup_regex_entities(regex) found_matches = finder.find_entity_values("I want a Large cake and some beer") assert(len(found_matches)) == 3 # Note this test also ensures that a word is not assert(len(found_matches["Large"]) == 1) assert("CakeSize" in found_matches["Large"]) assert(len(found_matches["beer"]) == 1) assert("Drinks" in found_matches["beer"]) assert(len(found_matches["cake"]) == 1) assert("CakeTypeRegex" in found_matches["cake"])
async def handle_findentities(self, request): ''' the function returns the supplied chat text with the entities identified ''' url = request.url if not request.can_read_body: self.logger.warning( 'Invalid NER findentities request, no body found, url was %s', url) raise web.HTTPBadRequest body = await request.json() self.logger.info("Find entity request, populating entities") # Note that this version does not persist entity values, # so use a temporary instance of the finder legacy_finder = LegacyEntityFinder() regex_good = True if 'entities' in body: self.logger.info("List entities found") legacy_finder.setup_entity_values(body['entities']) if 'regex_entities' in body: self.logger.info("Regex entities found") regex_good = legacy_finder.setup_regex_entities( body['regex_entities']) if not regex_good: self.logger.info('Invalid regex found in findentities') raise web.HTTPBadRequest(reason='Invalid regex found') else: self.logger.info('No regex submitted or regex compiled') self.logger.info("Find entity request, matching entities") values = legacy_finder.find_entity_values(body['conversation']) data = {'conversation': body['conversation'], 'entities': values} resp = web.json_response(data) return resp