def sofia_process_text(): """Process text with Sofia and return INDRA Statements.""" if request.method == 'OPTIONS': return {} response = request.body.read().decode('utf-8') body = json.loads(response) text = body.get('text') auth = body.get('auth') sp = sofia.process_text(text, auth=auth) return _stmts_from_proc(sp)
def sofia_process_text(): """Process text with Sofia and return INDRA Statements.""" if request.method == 'OPTIONS': return {} response = request.body.read().decode('utf-8') body = json.loads(response) text = body.get('text') auth = body.get('auth') sp = sofia.process_text(text, auth=auth) return _stmts_from_proc(sp)
def post(self): """Process text with Sofia and return INDRA Statements. Parameters ---------- text : str A string containing the text to be processed with Sofia. auth : Optional[list] A username/password pair for the Sofia web service. If not given, the SOFIA_USERNAME and SOFIA_PASSWORD values are loaded from either the INDRA config or the environment. Returns ------- statements : list[indra.statements.Statement.to_json()] A list of extracted INDRA Statements. """ args = request.json text = args.get('text') auth = args.get('auth') sp = sofia.process_text(text, auth=auth) return _stmts_from_proc(sp)
def test_text_process_webservice(): txt = 'rainfall causes floods' sp = sofia.process_text(txt) assert len(sp.statements) == 1 assert sp.statements[0].subj.concept.name == 'rainfall' assert sp.statements[0].obj.concept.name == 'floods'
def test_text_process_webservice(): txt = 'rainfall causes floods' sp = sofia.process_text(txt) assert len(sp.statements) == 1 assert sp.statements[0].subj.concept.name == 'rainfall' assert sp.statements[0].obj.concept.name == 'floods'