-
Notifications
You must be signed in to change notification settings - Fork 1
/
core.clj
50 lines (44 loc) · 1.06 KB
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(ns tawny.bubo.core
(:require [tawny.owl :as o]))
(defmacro entity
"Add type information to parameters for a pattern."
{:style/indent 1}
[bindings & body]
`(let [
~@(interleave
(map second bindings)
bindings)]
~@body))
(defmacro defpattern [& body]
`(defn ~@body))
(defn- stem [filename]
(first
(clojure.string/split
(last
(clojure.string/split filename #"[/]"))
#"[.]")))
(defn save
([]
(save :owl))
([format]
(o/save-ontology
(str (stem *file*) "." (name format)))))
;; make defpattern add metadata?
(defn- arity
[f]
(let [invokes (filter #(= "invoke" (.getName %1)) (.getDeclaredMethods (class f)))]
(apply max (map #(alength (.getParameterTypes %1)) invokes))))
(defn string-apply
[f num-or-first & strings]
(let [num
(if (number? num-or-first)
num-or-first
(arity f))
strings
(if (number? num-or-first)
strings
(cons num-or-first strings))]
(doall
(map
#(apply f %)
(partition num strings)))))