Skip to content

Instantly share code, notes, and snippets.

@rtirrell
Created July 13, 2010 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtirrell/473714 to your computer and use it in GitHub Desktop.
Save rtirrell/473714 to your computer and use it in GitHub Desktop.
(ns oba-client
(:use [clojure-http.resourcefully :as res]
[clojure.contrib.str-utils :only [str-join]])
(:refer-clojure :exclude [get]))
(def default-timeout 30)
(def default-uri "http://rest.bioontology.org/obs/annotator")
(def all-annotator-parameters #{
:email
:filterNumber
:format
:isStopWordsCaseSensitive
:isVirtualOntologyID
:levelMax
:longestOnly
:ontologiesToExpand
:ontologiesToKeepInResult
:mappingTypes
:minTermSize
:scored
:semanticTypes
:stopWords
:wholeWordOnly
:withDefaultStopWords
:withSynonyms})
(defn parse [xml])
(defn execute-request [uri timeout parse-xml parameters text]
(let [parameters (assoc parameters :textToAnnotate text)]
(binding [*connect-timeout* timeout]
(let [response (res/post uri {} parameters)]
(if parse-xml
(parse (response :body-seq))
(response :body-seq))))))
(defn annotate
([] (annotate {}))
([options]
(let [uri (clojure.core/get options :uri default-uri)
timeout (clojure.core/get options :timeout default-timeout)
parse-xml ( options :parse-xml)]
(when-let [ontologies (options :ontologies)]
(do (assoc options :ontologiesToExpand ontologies)
(assoc options :ontologiesToKeepInResult ontologies)))
(let [parameters (select-keys options all-annotator-parameters)]
(doseq [[k v] parameters]
(if (vector? v) (assoc parameters k (str-join ", " v))))
(partial execute-request uri timeout parse-xml parameters)))))
(defn annotate-text []
((annotate) "hello!? out there?!"))
(annotate-text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment