def get_tagged_from_server(input_text):
    """
    Send the input_text to the CoreNLP server and retrieve the tokens, named entity tags and part-of-speech tags.
    """
    corenlp_output = nlp_corenlp.annotate(input_text, properties=corenlp_properties).get("sentences", [])[0]
    tagged = [(t['originalText'], t['ner'], t['pos']) for t in corenlp_output['tokens']]
    return tagged
Exemplo n.º 2
0
def predict_openie():
    request.get_json(force=True)
    try:
        if request.method == 'POST':
            text = request.json.get("inputtext")
            output = nlp_corenlp.annotate(text,
                                          properties={
                                              'annotators': 'dcoref',
                                              'outputFormat': 'json',
                                              'ner.useSUTime': 'false'
                                          })
            resolve(output)
            coreftext = get_resolved(output)
            output = nlp_corenlp.annotate(coreftext,
                                          properties={
                                              'annotators': 'openie',
                                              'outputFormat': 'json',
                                              'ner.useSUTime': 'false'
                                          })
            out = list(map(lambda x: x['openie'], output['sentences']))
            flat_list = [item for sublist in out for item in sublist]
            dfnc, entdf, desiglist = nlpent.ner(coreftext)
            dfnc = dfnc.to_dict(orient="records")
            entdf = entdf.to_dict(orient="records")
            keyconcepts = pd.DataFrame(list(getkeys(text)))
            keyconcepts.columns = ["Score", "Keywords"]
            keyconcepts = keyconcepts.to_dict(orient="records")
            return jsonify({
                "ie": flat_list,
                "dfnc": dfnc,
                "entdf": entdf,
                "kc": keyconcepts,
                "ds": desiglist
            })
        else:
            return "No result"
    except Exception as e:
        print(str(e))
        return jsonify({"ie": "No relation detected"})
Exemplo n.º 3
0
 def stan_core(self, text):
     try:
         output = nlp_corenlp.annotate(text,
                                       properties={
                                           'annotators': 'dcoref',
                                           'outputFormat': 'json',
                                           'ner.useSUTime': 'false'
                                       })
         self.resolve(output)
         sent_no_articles = self.get_resolved(output)
         sent_no_articles
     except:
         sent_no_articles = text
     return sent_no_articles