Exemplo n.º 1
0
def combine_output(request):
    """This functionality calls the combine_output_of_detection_logic_and_tag()  through api call

    Attributes:
        request: url parameters

    """
    message = request.GET.get('message')
    entity_data = request.GET.get('entity_data', '{}')
    entity_data_json = json.loads(entity_data)
    ner_logger.debug('Start: %s ' % message)
    output = combine_output_of_detection_logic_and_tag(entity_data=entity_data_json, text=message)
    ner_logger.debug('Finished %s : %s ' % (message, output))
    return HttpResponse(json.dumps({'data': output}), content_type='application/json')
Exemplo n.º 2
0
def run_ner(entities, message):
    """This function tags the message with the entity name and also identify the entity values.
    This functionality can be used when we have to identify entities from message without considering and
    structured_value and fallback_value.

    Attributes:
        entities: list of entity names that needs to be identified. For example, ['date', 'time', 'restaurant']
        message: message on which entity detection needs to run

    Output:
        will be list of dictionary
        {
            'entity_data':  PROCESSED_ENTITY_DICTIONARY,
            'tag': TAGGED_TEXT

        }

    Example:
        entities = ['date','time','restaurant']
        message = "Reserve me a table today at 6:30pm at Mainland China and on Monday at 7:00pm at Barbeque Nation"
        ner_output = run_ner(entities=entities, message=message)
        print ner_output

            >> "data": {
        "tag": "reserve me a table __date__ at __time__ at __restaurant__ and on __date__ at __time__ at __restaurant__",
        "entity_data": {
            "restaurant": [{
                "detection": "chat",
                "original_text": "barbeque nation",
                "entity_value": "Barbeque Nation"
            }, {
                "detection": "chat",
                "original_text": "mainland china",
                "entity_value": "Mainland China"
            }],
            "date": [{
                "detection": "chat",
                "original_text": " monday",
              "entity_value": {
                    "mm": 03,
                    "yy": 2017,
                    "dd": 13,
                    "type": "current_day"
                }
            }, {
                "detection": "chat",
                "original_text": "today",
                "entity_value": {
                    "mm": 03,
                    "yy": 2017,
                    "dd": 11,
                    "type": "today"
                }
            }],
            "time": [{
                "detection": "chat",
                "original_text": "6:30pm",
                "entity_value": {
                    "mm": 30,
                    "hh": 6,
                    "nn": "pm"
                }
            }, {
                "detection": "chat",
                "original_text": "7:00pm",
                "entity_value": {
                    "mm": 0,
                    "hh": 7,
                    "nn": "pm"
                }
            }]
        }
    }
}

    """
    entity_data = {}
    for entity in entities:
        entity_data[entity] = get_entity_function(entity=entity,
                                                  message=message)
    return combine_output_of_detection_logic_and_tag(entity_data, message)