Permalink
Browse files

Clojure code improvements by Alex Ott

  • Loading branch information...
1 parent 6246171 commit f17d7f837c579e774b88d73eebdf8779db338fc3 @mark-watson committed Mar 12, 2011
View
BIN lib/clojure-contrib.jar
Binary file not shown.
View
BIN lib/clojure.jar
Binary file not shown.
View
15 src/nlp_clojure.clj
@@ -3,22 +3,21 @@
;; Alternative commercial license used under special arrangement (contact markw <at> markwatson <dot> com):
;; http://markwatson.com/commerciallicense.txt
-(ns nlp_clojure)
-
-(import '(com.knowledgebooks.nlp AutoTagger KeyPhraseExtractionAndSummary ExtractNames)
- '(com.knowledgebooks.nlp.util NameValue ScoredList))
+(ns nlp-clojure
+ (:import (com.knowledgebooks.nlp AutoTagger KeyPhraseExtractionAndSummary ExtractNames)
+ (com.knowledgebooks.nlp.util NameValue ScoredList)))
(def auto-tagger (AutoTagger.))
(def name-extractor (ExtractNames.))
-;; utility:
-(defn to-string [obj] (.toString obj))
+(defn get-auto-tags [text]
+ (map str (seq (.getTags auto-tagger text))))
-(defn get-auto-tags [text] (seq (map to-string (.getTags auto-tagger text))))
(defn get-names [text]
(let [[names places] (.getProperNames name-extractor text)]
[(seq (.getStrings names))
(seq (.getStrings places))]))
+
(defn get-summary [text]
- (.getSummary (new KeyPhraseExtractionAndSummary text)))
+ (.getSummary (KeyPhraseExtractionAndSummary. text)))
View
30 src/rdf_clojure.clj
@@ -3,20 +3,34 @@
;; Alternative commercial license used under special arrangement (contact markw <at> markwatson <dot> com):
;; http://markwatson.com/commerciallicense.txt
-(ns rdf_clojure)
+(ns rdf-clojure
+ (:import (com.knowledgebooks.rdf Triple)
+ (com.knowledgebooks.rdf AllegroGraphServerProxy)
+ (com.knowledgebooks.rdf SesameEmbeddedProxy)
+ ))
-(import '(com.knowledgebooks.rdf Triple) '(com.knowledgebooks.rdf AllegroGraphServerProxy) '(com.knowledgebooks.rdf SesameEmbeddedProxy))
;;(defn rdf-proxy [] (AllegroGraphServerProxy.))
(defn rdf-proxy [] (SesameEmbeddedProxy.))
-(defn delete-repository [ag-proxy name] (.deleteRepository ag-proxy name))
-(defn create-repository [ag-proxy name] (.createRepository ag-proxy name))
-(defn register-freetext-predicate [ag-proxy predicate-name] (.registerFreetextPredicate ag-proxy predicate-name))
-(defn initialize-geoLocation [ag-proxy radius] (.initializeGeoLocation ag-proxy (float radius)))
-(defn add-triple [ag-proxy s p o] (.addTriple ag-proxy s p o))
+;; TODO: use macros to define bindings from clojure?
+(defn delete-repository [ag-proxy name]
+ (.deleteRepository ag-proxy name))
+(defn create-repository [ag-proxy name]
+ (.createRepository ag-proxy name))
+(defn register-freetext-predicate [ag-proxy predicate-name]
+ (.registerFreetextPredicate ag-proxy predicate-name))
+(defn initialize-geoLocation [ag-proxy radius]
+ (.initializeGeoLocation ag-proxy (float radius)))
+(defn add-triple [ag-proxy s p o]
+ (.addTriple ag-proxy s p o))
+
+;; TODO: for returns lazy sequence, is ag-proxy will still available?
(defn query [ag-proxy sparql]
(for [triple (seq (.query ag-proxy sparql))]
[(.get triple 0) (.get triple 1) (.get triple 2)]))
-(defn text-search [ag-proxy query-string] (.textSearch ag-proxy query-string))
+
+(defn text-search [ag-proxy query-string]
+ (.textSearch ag-proxy query-string))
+
(defn get-locations [ag-proxy lat lon radius]
(.getLocations ag-proxy lat lon radius))
View
12 src/sparql_client_clojure.clj
@@ -3,12 +3,8 @@
;; Alternative commercial license used under special arrangement (contact markw <at> markwatson <dot> com):
;; http://markwatson.com/commerciallicense.txt
-(ns sparql_client_clojure)
+(ns sparql-client-clojure
+ (:import (com.knowledgebooks.rdf SparqlClient)))
-(import '(com.knowledgebooks.rdf SparqlClient))
-
-(defn convert-to-map [vb]
- (into {} vb))
-
-(defn sparql-query [endpoint_uri query]
- (seq (map convert-to-map (.variableBindings (new SparqlClient endpoint_uri query)))))
+(defn sparql-query [endpoint-uri query]
+ (seq (map #(into {} %) (.variableBindings (new SparqlClient endpoint-uri query)))))

0 comments on commit f17d7f8

Please sign in to comment.