Skip to content

Instantly share code, notes, and snippets.

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
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 =,data=text, headers=headers)
if (response.status_code != 200):
print("error from server: %s" % response.status_code)
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] = [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