Skip to content

Instantly share code, notes, and snippets.

@zwurgl
Created April 16, 2020 16:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
def call_sherpa(text,model,annotator,server,token)
url = server+"/projects/"+model+"/annotators/"+annotator+"/_annotate"
results = {}
text = text.encode(encoding='utf-8')
headers = {"Accept": "application/json",
"Content-Type": "text/plain",
"Authorization": "Bearer " + token}
response = requests.post(url,data=text, headers=headers)
if (response.status_code != 200):
print("error from server: %s" % response.status_code)
return
json_response = json.loads(response.text)
documenttext = json_response['text']
annotations = json_response['annotations']
for annotation in annotations:
start = annotation['start']
end = annotation['end']
term = documenttext[start:end]
type = annotation['labelName']
if type in results:
results[type].extend([term])
else:
results[type] = [term]
for key in results.keys():
list_set = set(results[key])
results[key] = list(list_set)
return results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment