|
|
@@ -11,9 +11,9 @@ def get_json(url): |
|
|
opener.addheaders = [('Authorization', 'apikey token=' + API_KEY)]
|
|
|
return json.loads(opener.open(url).read())
|
|
|
|
|
|
-def print_annotations(annotations):
|
|
|
+def print_annotations(annotations, get_class=True):
|
|
|
for result in annotations:
|
|
|
- class_details = get_json(result["annotatedClass"]["links"]["self"])
|
|
|
+ class_details = get_json(result["annotatedClass"]["links"]["self"]) if get_class else result["annotatedClass"]
|
|
|
print "Class details"
|
|
|
print "\tid: " + class_details["@id"]
|
|
|
print "\tprefLabel: " + class_details["prefLabel"]
|
|
|
@@ -38,13 +38,18 @@ def print_annotations(annotations): |
|
|
|
|
|
print "\n\n"
|
|
|
|
|
|
-# Annotate using the provided text
|
|
|
text_to_annotate = "Melanoma is a malignant tumor of melanocytes which are found predominantly in skin but also in the bowel and the eye."
|
|
|
+
|
|
|
+# Annotate using the provided text
|
|
|
annotations = get_json(REST_URL + "/annotator?text=" + urllib2.quote(text_to_annotate))
|
|
|
|
|
|
# Print out annotation details
|
|
|
print_annotations(annotations)
|
|
|
|
|
|
# Annotate with hierarchy information
|
|
|
annotations = get_json(REST_URL + "/annotator?max_level=3&text=" + urllib2.quote(text_to_annotate))
|
|
|
-print_annotations(annotations)
|
|
|
+print_annotations(annotations)
|
|
|
+
|
|
|
+# Annotate with prefLabel, synonym, definition returned
|
|
|
+annotations = get_json(REST_URL + "/annotator?include=prefLabel,synonym,definition&text=" + urllib2.quote(text_to_annotate))
|
|
|
+print_annotations(annotations, False)
|
0 comments on commit
1793eb3