Ejemplo n.º 1
0
def test_entity_finder_ignore_punctuation():
    finder = LegacyEntityFinder()
    values = setup_data()
    finder.setup_entity_values(values)
    found_matches = finder.find_entity_values("I want a cake, maybe carrot?")
    assert(len(found_matches["carrot"]) == 1)
    assert("CakeType" in found_matches["carrot"])
Ejemplo n.º 2
0
def test_entity_finder_multi_word_values():
    finder = LegacyEntityFinder()
    values = setup_data()
    finder.setup_entity_values(values)
    found_matches = finder.find_entity_values("I want some red wine and a cake")
    assert(len(found_matches["red wine"]) == 1)
    assert("Drinks" in found_matches["red wine"])
Ejemplo n.º 3
0
def test_entity_finder_multiple_matches():
    finder = LegacyEntityFinder()
    values = setup_data()
    finder.setup_entity_values(values)
    found_matches = finder.find_entity_values("I want a Carrot cake and then more carrot cake")
    assert(len(found_matches["Carrot"]) == 1)
    assert("CakeType" in found_matches["Carrot"])
Ejemplo n.º 4
0
def test_entity_finder_case_insensitive():
    finder = LegacyEntityFinder()
    values = setup_data()
    finder.setup_entity_values(values)
    found_matches = finder.find_entity_values("I want a carrot cake")
    assert(len(found_matches["carrot"]) == 1)
    assert("CakeType" in found_matches["carrot"])
Ejemplo n.º 5
0
def test_entity_finder_duplicate_matches():
    finder = LegacyEntityFinder()
    values = setup_data()
    finder.setup_entity_values(values)
    found_matches = finder.find_entity_values("I want a chocolate cake and a chocolate biscuit")
    assert(len(found_matches["chocolate"]) == 2)
    assert("CakeType" in found_matches["chocolate"])
    assert("Biscuit" in found_matches["chocolate"])
Ejemplo n.º 6
0
def test_entity_finder_substring_matches():
    finder = LegacyEntityFinder()
    values = setup_data()
    finder.setup_entity_values(values)
    found_matches = finder.find_entity_values("I want a Diet Coke")
    assert(len(found_matches) == 1)
    assert(len(found_matches["Diet Coke"]) == 1)
    assert("Drinks" in found_matches["Diet Coke"])
Ejemplo n.º 7
0
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"])
Ejemplo n.º 8
0
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"])
Ejemplo n.º 9
0
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"])
Ejemplo n.º 10
0
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"])
Ejemplo n.º 11
0
    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
Ejemplo n.º 12
0
def test_entity_finder_no_matches():
    finder = LegacyEntityFinder()
    values = setup_data()
    finder.setup_entity_values(values)
    found_matches = finder.find_entity_values("I want a cake")
    assert(len(found_matches) == 0)
Ejemplo n.º 13
0
def test_entity_finder_no_entities():
    finder = LegacyEntityFinder()
    values = {}
    finder.setup_entity_values(values)
    found_matches = finder.find_entity_values("I want a Carrot cake")
    assert(len(found_matches) == 0)