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)
def visualization(): """ POST request, can be made via Postman. Notes: the format of the body of the POST request must be 'raw text'. Args: raw text: the body of the POST request should be raw text. Returns: String: Return a URL containing the reference number of this POST, the user can use the URL in the browser to see the visualized entity extract result """ article = request.data.decode() # String my_doc = Doc(article) reference_number = str(uuid.uuid4()) html = displacy.render(my_doc.get_doc(), style="ent") catch.add_reference(reference_number, html) return jsonify({ 'your reference': f"http://{request.host}/get?reference={reference_number}" })