Created
July 13, 2010 10:41
-
-
Save rtirrell/473714 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 #{ | |
: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