Skip to content

Commit

Permalink
jaro
Browse files Browse the repository at this point in the history
  • Loading branch information
justin2004 committed Mar 2, 2023
1 parent c8ea7bf commit 0fcb078
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
:url "https://github.com/justin2004/datething"
:dependencies [[org.clojure/clojure "1.10.0"]
[wit/duckling "0.4.24"]
[info.debatty/java-string-similarity "2.0.0"]
[org.apache.jena/apache-jena-libs "4.2.0" :extension "pom"]]
:repl-options {:init-ns datething.parse}
:profile {:uberjar {:aot :all
:debug true}}
:main datething.parse) ; i think i just need this to get AOT when i run `lein uberjar`
:main datething.jaro) ; i think i just need this to get AOT when i run `lein uberjar`
; TODO just do AOT instead
38 changes: 38 additions & 0 deletions src/datething/jaro.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(ns datething.jaro
(:gen-class
:extends org.apache.jena.sparql.function.FunctionBase2)
(:require [clojure.pprint :as pp]))

; (def jw (new info.debatty.java.stringsimilarity.JaroWinkler))
; (.distance jw "atlanta, ga" "atlanta")

(defn -exec ^org.apache.jena.sparql.expr.NodeValue [^org.apache.jena.sparql.expr.NodeValue & v ]
(do
; (.println java.lang.System/err "you passed in")
; (.println java.lang.System/err v)
(let [asked0 (.asVar (.get (.getList (nth v 2)) ; asked is the Var passed into the function
0))
asked1 (.asVar (.get (.getList (nth v 2)) ; asked is the Var passed into the function
1))
looked0 (str (.getLiteralValue (.get (nth v 1) ; looked is the Var's value as found (looked up) in the bindings
asked0)))
looked1 (str (.getLiteralValue (.get (nth v 1) ; looked is the Var's value as found (looked up) in the bindings
asked1)))
jaroDistance (.distance (new info.debatty.java.stringsimilarity.JaroWinkler)
looked0 looked1) ]

; (.println java.lang.System/err "asked0")
; (.println java.lang.System/err looked0)
; (.println java.lang.System/err "asked1")
; (.println java.lang.System/err looked1)
(new org.apache.jena.sparql.expr.nodevalue.NodeValueFloat jaroDistance))))

(comment (defn -exec ^org.apache.jena.sparql.expr.NodeValue [^org.apache.jena.sparql.expr.NodeValue & v]
(do (let [asked (.asVar (.get (.getList (nth v 2)) ; asked is the Var passed into the function
0))
looked (str (.getLiteralValue (.get (nth v 1) ; looked is the Var's value as found (looked up) in the bindings
asked)))
parsed (str (:value (:value (first (duck/parse :en$core ; parsed is the parsed Var's value
looked
[:time])))))]
(new org.apache.jena.sparql.expr.nodevalue.NodeValueString parsed)))))

0 comments on commit 0fcb078

Please sign in to comment.