API Usage - Honghan/klannotation GitHub Wiki
KLAnnotation API Documentation
General RESTful query URL pattern is like the following.
/api/{func}/({param1}/{param2}/...)
Responses are JSON coded.
NB: passphrase protected projects
If your project has been setup to use passphrase, you will need to add passphrase to each function call as one URL parameter. For example,
import requests
url = 'http://localhost:8000/api/docs/?passphrase=123'
response = requests.get(url)
print(response.content)
List of functions
get documents list: /api/docs/
import requests
url = 'http://localhost:8000/api/docs/'
response = requests.get(url)
print(response.content)
Response will be an array of document IDs.
get document details: /api/doc_detail/
import requests
url = 'http://localhost:8000/api/doc_detail/001.txt'
response = requests.get(url)
print(response.content)
Response will be a dictionary like the following.
{
"content": "full-text-of-the-document",
"anns": {} //JSON dictionary, see details on the structure below.
}
anns is a structure like the following.
{
"sentences": [],
"annotations": [],
"phenotypes": []
}
sentencesarray contains the sentences start/end offsets.annotationsarray contains the UMLS concept mentions (details).phenotypesarray contains the mentions of entities in the customised gazetteer.
search documents: /api/search_docs/{query}/, where query can be regular expressions.
NB: search might be slow when the documents are more than 10k
import requests
url = 'http://localhost:8000/api/search_docs/AFib/'
response = requests.get(url)
print(response.content)
Response will be a list of ids, which are of those matched to the searches.
search annotations: /api/search_anns/{query}/, where query can be regular expressions.
query is matched to preferred labels, CUI, str (original string) and customised dictionary term types
NB: search might be slow when the documents are more than 10k
import requests
url = 'http://localhost:8000/api/search_anns/AFib/'
response = requests.get(url)
print(response.content)
Response will be a list of ids, which are of those whose annotations are matched to the searches.
get document details using a mapping: /api/doc_content_mapping/
import requests
url = 'http://localhost:8000/api/doc_content_mapping/001.txt/HPO mapping'
response = requests.get(url)
print(response.content)
Response will be a dictionary like the following. Only mapped UMLS concepts are kept
{
"content": "full-text-of-the-document",
"anns": JSON dictionary
}
get available mappings: /api/mappings/
import requests
url = 'http://localhost:8000/api/mappings/'
response = requests.get(url)
print(response.content)
Response will be a list of strings, denoting mapping names like HPO mapping