Comments (1)
I solved this issue by finding my error of use 'POST' method incorrectly. Following code is you can use when you have text files in a speicfic folder (TEXT DIR) and want annotate them and export each file as a json.
import traceback
import sys
import re
import glob
import json
import urllib
import urllib2
from time import gmtime, strftime
from time import sleep
INPUT_DIR = '../data/text/'
OUTPUT_DIR = '../data/json/'
API_KEY= ''
annotatorUrl = 'http://data.bioontology.org/annotator'
ontology_list = 'ICD9CM,LOINC'
tui_list = 'T017,T029,T023,T030'
def get_json(text):
params = {
'text':text,
'longest_only':'true',
'whole_word_only':'true',
'stop_words':'',
'ontologies':ontology_list,
'ontologiesToKeepInResult':'',
'isVirtualOntologyId':'true',
'semantic_types':tui_list,
'apikey':API_KEY
}
headers = {'Authorization': 'apikey token=' + API_KEY}
data = urllib.urlencode(params)
request = urllib2.Request(annotatorUrl, data, headers)
# request.add_header('Content-type','text/xml')
response = urllib2.urlopen(request)
data_json = json.loads(response.read().decode('utf-8'))
# print 'http status: '+ str(response.getcode())
return data_json
def main():
for filename in glob.glob(INPUT_DIR+'*.txt'):
# for each file load file
text = ''
lines = open(filename,"r").read().splitlines()
for l in lines:
text = text + l.rstrip()
# remove special characters
text = re.sub('[^A-Za-z0-9]+', ' ', text)
try:
# get json
data = get_json(text)
# save to json file
filename_nodir = filename.split('/')[-1].split('.')[0]
json_fn = '' + filename_nodir + '.json'
with open(OUTPUT_DIR+json_fn, 'w') as outfile:
json.dump(data, outfile)
print strftime("%Y-%m-%d %H:%M:%S") + ' SUCCESS ' + filename_nodir
except:
print strftime("%Y-%m-%d %H:%M:%S") + ' FAIL ' + filename_nodir
raise
if __name__ == "__main__":
main()
from ncbo_annotator.
Related Issues (19)
- local instance of annotator HOT 3
- Hierarchy size is incorrectly calculated for some annotations
- Internal Server Error when expand_mappings=true is used in conjunction with include= HOT 2
- Semantic types aren't universally recognized HOT 2
- hyphenated terms not found by annotator given non-hyphenated words HOT 5
- Result sets include classes that no longer exist in latest submission
- Develop a way to remove individual ontology from Annotator cache
- deprecation warnings `Redis#exists(key)` will return an Integer in redis-rb 4.3 #3
- deprecation warnings `Redis#exists(key)` will return an Integer in redis-rb 4.3 HOT 1
- Optimize Mgrep dictionary generation process HOT 1
- Add incremental logging when the dictionary is being created
- label creator
- Missing ancestors in hierarchy from annotator? HOT 1
- Warnings: Pipelining commands on a Redis instance is deprecated and will be removed in Redis 5.0.0 HOT 1
- test_generate_dictionary_file unit test intermittently fails
- annotator cache generation failure - Unsupported command argument type: RDF::URI HOT 1
- Issues with some special characters in annotatorplus api HOT 3
- Unit tests encounter errors when retrieving metrics, but overall tests still pass.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ncbo_annotator.