support loading ned result from disk

pull/2/head
Kai 5 years ago
parent 9fe35377e3
commit 0d650ebcc5

@ -146,7 +146,15 @@ def ner(tsv, ner_rest_endpoint):
'left', 'right', 'top', 'bottom']), ner_result
def ned(tsv, ner_result, ned_rest_endpoint, return_full=False, threshold=None):
def ned(tsv, ner_result, ned_rest_endpoint, json_file=None, threshold=None):
if os.path.exists(json_file):
print('Loading {}'.format(json_file))
ned_result = json.load(json_file)
else:
resp = requests.post(url=ned_rest_endpoint + '/parse', json=ner_result)
@ -154,7 +162,7 @@ def ned(tsv, ner_result, ned_rest_endpoint, return_full=False, threshold=None):
ner_parsed = json.loads(resp.content)
ned_rest_endpoint = ned_rest_endpoint + '/ned?return_full=' + str(return_full).lower()
ned_rest_endpoint = ned_rest_endpoint + '/ned?return_full=' + str(json_file is not None).lower()
ned_rest_endpoint += '&threshold={}'.format(threshold) if threshold is not None else ''
@ -320,7 +328,7 @@ def find_entities(tsv_file, tsv_out_file, ner_rest_endpoint, ned_rest_endpoint,
if ned_rest_endpoint is not None:
tsv, ned_result = ned(tsv, ner_result, ned_rest_endpoint, return_full=ned_json_file is not None)
tsv, ned_result = ned(tsv, ner_result, ned_rest_endpoint, json_file=ned_json_file)
if ned_json_file is not None:

Loading…
Cancel
Save