Skip to content

Instantly share code, notes, and snippets.

View sherpa_print_output.py
output = pd.DataFrame()
text = open(txtfile, "r",encoding='UTF-8', errors='ignore').read()
result = call_sherpa(text,project,model,server,mytoken)
result['document'] = txtfile
output = output.append(result, ignore_index=True)
output = output.set_index('document')
output.to_csv(MYOUTPUTFILE, sep='\t')
View sherpa_call_sherpa.py
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):
View sherpa_get_projects.py
def get_projects(server,token):
url = server + "/projects"
headers2 = {'Authorization': 'Bearer ' + token}
#print("calling sherpa server '%s' ..." % url)
response = requests.get(url,headers=headers2)
json_response = json.loads(response.text)
projects = ", ".join([project['name'] for project in json_response])
print("Available projects on %s: %s" % (server, projects))
View sherpa_authentication.py
import json
import requests
server = 'https://sherpa.kairntech.com/api'
login_info = json.dumps({"email": 'YOUR-LOGIN',
"password": 'YOUR-PASSWORD'})
headers = {"Accept": "application/json",
"Content-Type": "application/json"}
def get_token(server, login_info):