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
/api/docs/
get documents list: import requests
url = 'http://localhost:8000/api/docs/'
response = requests.get(url)
print(response.content)
Response will be an array of document IDs.
/api/doc_detail/
get document details: 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": []
}
sentences
array contains the sentences start/end offsets.annotations
array contains the UMLS concept mentions (details).phenotypes
array contains the mentions of entities in the customised gazetteer.
/api/search_docs/{query}/
, where query
can be regular expressions.
search documents: 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.
/api/search_anns/{query}/
, where query
can be regular expressions.
search annotations: 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.
/api/doc_content_mapping/
get document details using a 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
}
/api/mappings/
get available 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