Ejemplo n.º 1
0
def list_all_entities():
    """POST request, generate a response listing the details of all the entities.

    Args:
        raw text: the user should post an article (raw text format) to this api.

    Returns:
        json: list the details of the entities in the article, in the json format
    """

    article = request.data.decode()
    my_doc = Doc(article)
    dic = []
    mapping = my_doc.map_position_start_index()

    for ent in my_doc.get_doc().ents:
        ent_dic = {}
        start_index = ent.start_char
        position = my_doc.get_position(start_index, mapping)
        label = my_doc.get_label(ent)

        ent_dic["entity"] = ent.text
        ent_dic["position"] = position
        ent_dic["label"] = label

        dic.append(ent_dic)
    return jsonify(dic)