diff --git a/python/annotate_text.py b/python/annotate_text.py index 3b42ec9..b96ab8f 100644 --- a/python/annotate_text.py +++ b/python/annotate_text.py @@ -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,8 +38,9 @@ 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 @@ -47,4 +48,8 @@ def 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) \ No newline at end of file +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) \ No newline at end of file diff --git a/ruby/annotate_text.rb b/ruby/annotate_text.rb index 59e4577..dcb3037 100644 --- a/ruby/annotate_text.rb +++ b/ruby/annotate_text.rb @@ -9,9 +9,9 @@ def get_json(url) JSON.parse(open(url, "Authorization" => "apikey token=#{API_KEY}").read) end -def puts_annotations(annotations) +def puts_annotations(annotations, get_class = true) annotations.each do |result| - class_details = get_json(result["annotatedClass"]["links"]["self"]) + class_details = get_class ? get_json(result["annotatedClass"]["links"]["self"]) : result["annotatedClass"] puts "Class details" puts "\tid: " + class_details["@id"] puts "\tprefLabel: " + class_details["prefLabel"] @@ -41,13 +41,18 @@ def puts_annotations(annotations) end end -# 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=" + CGI.escape(text_to_annotate)) -# puts out annotation details +# Prints out annotation details puts_annotations(annotations) # Annotate with hierarchy information annotations = get_json(REST_URL + "/annotator?max_level=3&text=" + CGI.escape(text_to_annotate)) puts_annotations(annotations) + +# Annotate with prefLabel, synonym, definition returned +annotations = get_json(REST_URL + "/annotator?include=prefLabel,synonym,definition&text=" + CGI.escape(text_to_annotate)) +puts_annotations(annotations) \ No newline at end of file