>
107 | ;; :unique
108 | ;; :localname [vars ..]
109 | ;; :md5 [vars ..]
110 | ;; :regex [match replace vars..]
111 | ;; :fn (fn [bindings] ..)
112 | ;; :as reify-opts}
113 |
114 | ;; this will take the above type of form and return a function
115 | ;; that will function to refify symbols for that form when passed the bindings
116 |
117 | (defmulti reify-rule-form-fn
118 | (fn [rule reify-form]
119 | (cond
120 | (not (sequential? reify-form)) :default
121 | (not (map? (second reify-form))) :default ;is this actually an error?
122 | (keyword? (:ln (second reify-form))) (:ln (second reify-form))
123 | :else (first (:ln (second reify-form))))))
124 |
125 |
126 | (defn extend-reify-map [reify-opts fn & [dependency-vars]]
127 | (assoc reify-opts
128 | :reify-fn fn
129 | :dependencies dependency-vars))
130 |
131 | (defmethod reify-rule-form-fn :default [rule [var reify-opts]]
132 | (extend-reify-map reify-opts
133 | (fn [bindings]
134 | (with-reify-name-bindings reify-opts
135 | (reify-unique)))))
136 |
137 | (defmethod reify-rule-form-fn :unique [rule [var reify-opts]]
138 | (extend-reify-map reify-opts
139 | (fn [bindings]
140 | (with-reify-name-bindings reify-opts
141 | (reify-unique)))))
142 |
143 | (defmethod reify-rule-form-fn :localname [rule
144 | [var {[fn-name & params] :ln
145 | :as reify-opts}]]
146 | (extend-reify-map reify-opts
147 | (fn [bindings]
148 | (with-reify-name-bindings reify-opts
149 | (apply reify-localname (subst-bindings params bindings))))
150 | (variables params)))
151 |
152 | (defmethod reify-rule-form-fn :md5 [rule
153 | [var {[fn-name & params] :ln
154 | :as reify-opts}]]
155 | (extend-reify-map reify-opts
156 | (fn [bindings]
157 | (with-reify-name-bindings reify-opts
158 | (apply reify-md5 (subst-bindings params bindings))))
159 | (variables params)))
160 |
161 | (defmethod reify-rule-form-fn :regex [rule
162 | [var {[fn-name match replace & vars] :ln
163 | :as reify-opts}]]
164 | (extend-reify-map reify-opts
165 | (fn [bindings]
166 | (with-reify-name-bindings reify-opts
167 | (apply reify-regex match replace
168 | (subst-bindings vars bindings))))
169 | ;;(apply reify-regex match replace (map bindings vars))))
170 | (variables vars)))
171 |
172 |
173 | (defmethod reify-rule-form-fn :fn [rule
174 | [var {[fn-name fcn] :ln
175 | :as reify-opts}]]
176 | (extend-reify-map reify-opts
177 | (fn [bindings]
178 | (with-reify-name-bindings reify-opts
179 | (reify-sym (fcn bindings))))))
180 | ;; ideally these should be rigged to go last
181 | ;; just move them last after?
182 | ;; pull them all off and put them on at the end
183 |
184 |
185 | (defn default-reify-rule-form-fn []
186 | (extend-reify-map {}
187 | (fn [bindings]
188 | (reify-unique))))
189 |
190 |
191 | (defn reification-dependencies [reify-list]
192 | (mapcat (fn [[v {deps :dependencies}]]
193 | (concat `((~v ~nil))
194 | (map (partial list v) deps)))
195 | reify-list))
196 |
197 | (defn sort-reification-based-on-dependencies [reify-list]
198 | (let [original-map (reduce (fn [m [v options]]
199 | (assoc m v options))
200 | {}
201 | reify-list)]
202 | (remove (fn [[var reify-def]]
203 | (nil? reify-def))
204 | (map (fn [var]
205 | (vector var (original-map var)))
206 | (dep/topo-sort
207 | (reduce (fn [graph [var dependency]]
208 | (dep/depend graph var dependency))
209 | (dep/graph)
210 | (reification-dependencies reify-list)))))))
211 |
212 |
213 | (defn add-reify-fns [{reify :reify :as rule}]
214 | (assoc rule
215 | :reify
216 | (sort-reification-based-on-dependencies
217 | (map (fn [entry]
218 | (if (sequential? entry)
219 | (let [[var opts :as form] entry]
220 | [var (reify-rule-form-fn rule form)])
221 | (vector entry (default-reify-rule-form-fn))))
222 | reify))))
223 |
224 | ;;; --------------------------------------------------------
225 | ;;; forward chaining
226 | ;;; --------------------------------------------------------
227 |
228 | ;; the variables in the reification section aren't actually independent
229 | ;; some of the variables being reified rely on other variables that
230 | ;; need to be reified. so they need to be ordered or managed in some way
231 |
232 | (defn reify-bindings [reify-with-fns bindings]
233 | (reduce (fn [new-bindings [var {reify-fn :reify-fn}]]
234 | ;;check for key in bindings already (rule out optionals)
235 | (if (new-bindings var)
236 | new-bindings
237 | (assoc new-bindings var (reify-fn new-bindings))))
238 | bindings
239 | reify-with-fns))
240 |
241 | ;;instantiates a rule and puts the triples in the target kb
242 | (defn run-forward-rule [source-kb target-kb source-rule]
243 | (let [{head :head
244 | body :body
245 | reify :reify
246 | :as rule} (add-reify-fns source-rule)]
247 | (pprint rule)
248 | (query-visit source-kb
249 | (fn [bindings]
250 | (dorun
251 | (map (partial add! target-kb)
252 | (doall
253 | (subst-bindings head
254 | ;;bindings
255 | (reify-bindings reify
256 | bindings))))))
257 | body ;need to add reify find clauses on optionally
258 | {:select-vars (concat (variables head)
259 | (variables reify))})))
260 |
261 |
262 | (defn ask-forward-rule [source-kb {head :head
263 | body :body
264 | :as rule}]
265 | (ask source-kb body))
266 |
267 | (defn count-forward-rule [source-kb {head :head
268 | body :body
269 | :as rule}]
270 | (query-count source-kb
271 | body
272 | {:select-vars (variables head)}))
273 |
274 |
275 |
276 | ;; (query-visit source-kb
277 | ;; (fn [bindings]
278 | ;; (prn bindings)
279 | ;; (dorun (map (fn [triple]
280 | ;; (prn triple)
281 | ;; (add! target-kb triple))
282 | ;; ;;(partial add! target-kb)
283 | ;; (dorun (map (fn [triple]
284 | ;; (prn triple)
285 | ;; (statement kb triple))
286 | ;; ;;(partial statement kb)
287 | ;; (reify-assertions
288 | ;; (subst-bindings head bindings)))))))
289 | ;; body))
290 |
291 |
292 |
293 | ;;; --------------------------------------------------------
294 | ;;;
295 | ;;; --------------------------------------------------------
296 |
297 |
298 |
299 | ;;; --------------------------------------------------------
300 | ;;;
301 | ;;; --------------------------------------------------------
302 |
303 |
304 | ;;; --------------------------------------------------------
305 | ;;; END
306 | ;;; --------------------------------------------------------
307 |
308 |
309 |
--------------------------------------------------------------------------------
/kr-sesame/kr-sesame-core/src/main/clojure/edu/ucdenver/ccp/kr/sesame/kb.clj:
--------------------------------------------------------------------------------
1 | (ns edu.ucdenver.ccp.kr.sesame.kb
2 | (use ;edu.ucdenver.ccp.kr.variable
3 | edu.ucdenver.ccp.kr.kb
4 | edu.ucdenver.ccp.kr.rdf
5 | edu.ucdenver.ccp.kr.sparql
6 | edu.ucdenver.ccp.kr.sesame.rdf
7 | edu.ucdenver.ccp.kr.sesame.sparql
8 | ;; [edu.ucdenver.ccp.kr.rdf :exclude (resource)]
9 | ;; clojure.java.io
10 | )
11 | (import
12 | org.openrdf.model.URI
13 | org.openrdf.model.Resource
14 | org.openrdf.model.Statement
15 |
16 | org.openrdf.model.impl.StatementImpl
17 | org.openrdf.model.impl.URIImpl
18 |
19 | org.openrdf.repository.Repository
20 | org.openrdf.repository.http.HTTPRepository
21 | org.openrdf.repository.RepositoryConnection
22 |
23 | org.openrdf.repository.sail.SailRepository;
24 | org.openrdf.sail.memory.MemoryStore;
25 |
26 | org.openrdf.query.resultio.TupleQueryResultFormat
27 | ))
28 |
29 | ;;; --------------------------------------------------------
30 | ;;; specials
31 | ;;; --------------------------------------------------------
32 |
33 | (def ^:dynamic *default-server* nil)
34 | (def ^:dynamic *repository-name* nil)
35 | (def ^:dynamic *username* nil)
36 | (def ^:dynamic *password* nil)
37 |
38 | (def ^:dynamic *kb-features* (list sparql-1-0 sparql-1-1))
39 |
40 |
41 | ;;; --------------------------------------------------------
42 | ;;; triple store connection and setup
43 | ;;; --------------------------------------------------------
44 |
45 |
46 |
47 | ;;; --------------------------------------------------------
48 | ;;; connections
49 | ;;; --------------------------------------------------------
50 |
51 | ;;this is nonsese becasue to the circular defintions
52 | ;; and what can and cannot be forward delcared
53 | (declare sesame-initialize
54 | new-sesame-connection
55 | close-existing-sesame-connection)
56 |
57 | (defn sesame-connection [kb]
58 | (new-sesame-connection kb))
59 |
60 | (defn close-sesame-connection [kb]
61 | (close-existing-sesame-connection kb))
62 |
63 |
64 | ;;; --------------------------------------------------------
65 | ;;; namespaces
66 | ;;; --------------------------------------------------------
67 |
68 | ;;; --------------------------------------------------------
69 | ;;; protocol implementation
70 | ;;; --------------------------------------------------------
71 |
72 | ;;TODO seperate server and connection??
73 |
74 | (defrecord SesameKB [server connection kb-features]
75 | KB
76 |
77 | (native [kb] server)
78 | (initialize [kb] (sesame-initialize kb))
79 | (open [kb] (new-sesame-connection kb))
80 | (close [kb] (close-sesame-connection kb))
81 | (features [kb] kb-features)
82 |
83 | rdfKB
84 |
85 | (root-ns-map [kb] (sesame-server-ns-map kb))
86 | ;; (ns-maps [kb] ns-maps-var)
87 | ;; (ns-map-to-short [kb] (:ns-map-to-short (deref ns-maps-var)))
88 | ;; (ns-map-to-long [kb] (:ns-map-to-long (deref ns-maps-var)))
89 | (register-ns [kb short long] (sesame-register-ns kb short long))
90 |
91 | (create-resource [kb name] (sesame-create-resource kb name))
92 | (create-property [kb name] (sesame-create-property kb name))
93 | (create-literal [kb val] (sesame-create-literal kb val))
94 | (create-literal [kb val type] (sesame-create-literal kb val type))
95 |
96 | ;;TODO convert to creating proper string literals
97 | ;; (create-string-literal [kb str] (sesame-create-string-iteral kb val))
98 | ;; (create-string-literal [kb str lang]
99 | ;; (sesame-create-string literal kb val type))
100 | (create-string-literal [kb str] (sesame-create-literal kb str))
101 | (create-string-literal [kb str lang]
102 | (sesame-create-literal kb str lang))
103 |
104 |
105 | (create-blank-node [kb name] (sesame-create-blank-node kb name))
106 | (create-statement [kb s p o] (sesame-create-statement kb s p o))
107 |
108 | (add-statement [kb stmt] (sesame-add-statement kb stmt))
109 | (add-statement [kb stmt context] (sesame-add-statement kb stmt context))
110 | (add-statement [kb s p o] (sesame-add-statement kb s p o))
111 | (add-statement [kb s p o context] (sesame-add-statement kb s p o context))
112 |
113 | (add-statements [kb stmts] (sesame-add-statements kb stmts))
114 | (add-statements [kb stmts context] (sesame-add-statements kb stmts context))
115 |
116 | (ask-statement [kb s p o context] (sesame-ask-statement kb s p o context))
117 | (query-statement [kb s p o context] (sesame-query-statement kb s p o context))
118 |
119 |
120 | (load-rdf-file [kb file] (sesame-load-rdf-file kb file))
121 | (load-rdf-file [kb file type] (sesame-load-rdf-file kb file type))
122 |
123 | ;;the following will throw exception for unknown rdf format
124 | (load-rdf-stream [kb stream] (sesame-load-rdf-stream kb stream))
125 |
126 | (load-rdf-stream [kb stream type] (sesame-load-rdf-stream kb stream type))
127 |
128 |
129 |
130 | sparqlKB
131 |
132 | (ask-pattern [kb pattern]
133 | (sesame-ask-pattern kb pattern))
134 | (ask-pattern [kb pattern options]
135 | (sesame-ask-pattern kb pattern options))
136 |
137 | (query-pattern [kb pattern]
138 | (sesame-query-pattern kb pattern))
139 | (query-pattern [kb pattern options]
140 | (sesame-query-pattern kb pattern options))
141 |
142 | (count-pattern [kb pattern]
143 | (sesame-count-pattern kb pattern))
144 | (count-pattern [kb pattern options]
145 | (sesame-count-pattern kb pattern options))
146 |
147 | (visit-pattern [kb visitor pattern]
148 | (sesame-visit-pattern kb visitor pattern))
149 | (visit-pattern [kb visitor pattern options]
150 | (sesame-visit-pattern kb visitor pattern options))
151 |
152 | (construct-pattern [kb create-pattern pattern]
153 | (sesame-construct-pattern kb create-pattern pattern))
154 | (construct-pattern [kb create-pattern pattern options]
155 | (sesame-construct-pattern kb create-pattern pattern options))
156 | (construct-visit-pattern [kb visitor create-pattern pattern]
157 | (sesame-construct-visit-pattern kb visitor create-pattern pattern))
158 | (construct-visit-pattern [kb visitor create-pattern pattern options]
159 | (sesame-construct-visit-pattern kb visitor create-pattern pattern options))
160 |
161 |
162 | (ask-sparql [kb query-string]
163 | (sesame-ask-sparql kb query-string))
164 | (query-sparql [kb query-string]
165 | (sesame-query-sparql kb query-string))
166 | (count-sparql [kb query-string]
167 | (sesame-count-sparql kb query-string))
168 | (visit-sparql [kb visitor query-string]
169 | (sesame-visit-sparql kb visitor query-string))
170 |
171 | (construct-sparql [kb sparql-string]
172 | (sesame-construct-sparql kb sparql-string))
173 | (construct-visit-sparql [kb visitor sparql-string]
174 | (sesame-construct-visit-sparql kb visitor sparql-string))
175 |
176 | )
177 |
178 | ;; TODO factor this out to a "connection" package
179 |
180 | ;;; "constructors"
181 | ;;; --------------------------------------------------------
182 |
183 | ;; the way new SesameKBConnection is being called it isn't preserving
184 | ;; the additional keys that are added on to the sesame server
185 | ;; specifically the :value-factory
186 |
187 | ;; (defn new-sesame-server []
188 | ;; (let [repository (HTTPRepository. *default-server* *repository-name*)]
189 | ;; (.setPreferredTupleQueryResultFormat repository
190 | ;; TupleQueryResultFormat/SPARQL)
191 | ;; (if (and *username* *password*)
192 | ;; (.setUsernameAndPassword repository *username* *password*))
193 | ;; (assoc (SesameKB. repository (initial-ns-mappings) nil)
194 | ;; :value-factory (.getValueFactory repository))))
195 |
196 | (defn copy-sesame-slots [target-kb source-kb]
197 | (copy-rdf-slots (copy-kb-slots target-kb source-kb)
198 | source-kb))
199 |
200 |
201 | (defn sesame-kb-helper [repository]
202 | (initialize-ns-mappings
203 | (assoc (SesameKB. repository nil *kb-features*)
204 | :value-factory (.getValueFactory repository))))
205 |
206 |
207 | ;; (defn new-sesame-server [& {:keys [server repo-name username password]
208 | ;; :or {server *default-server*
209 | ;; repo-name *repository-name*
210 | ;; username *username*
211 | ;; password *password*}}]
212 | ;; (println "server" server " name" repo-name)
213 | ;; (println "username" username " password" password)
214 | ;; (let [repository (HTTPRepository. server repo-name)]
215 | ;; (.setPreferredTupleQueryResultFormat repository
216 | ;; TupleQueryResultFormat/SPARQL)
217 | ;; (if (and username password)
218 | ;; (.setUsernameAndPassword repository username password))
219 | ;; (assoc (SesameKB. repository (initial-ns-mappings) nil)
220 | ;; :value-factory (.getValueFactory repository))))
221 |
222 | (defn new-sesame-server [& {:keys [server repo-name username password]
223 | :or {server *default-server*
224 | repo-name *repository-name*
225 | username *username*
226 | password *password*}}]
227 | ;; (println "server" server " name" repo-name)
228 | ;; (println "username" username " password" password)
229 | (let [repository (org.openrdf.repository.http.HTTPRepository. server
230 | repo-name)]
231 | (.setPreferredTupleQueryResultFormat repository
232 | TupleQueryResultFormat/SPARQL)
233 | (if (and username password)
234 | (.setUsernameAndPassword repository username password))
235 | (sesame-kb-helper repository)))
236 |
237 | ;; (defn new-sesame-server-helper [server & [repo-name username password]]
238 | ;; (apply new-sesame-server
239 | ;; (concat [:server server]
240 | ;; (if repo-name [:repo-name repo-name] nil)
241 | ;; (if username [:username username] nil)
242 | ;; (if password [:password password] nil))))
243 |
244 |
245 | (defn new-sesame-connection [kb]
246 | (copy-sesame-slots (assoc (SesameKB. (:server kb)
247 | (.getConnection (:server kb))
248 | (features kb))
249 | :value-factory (:value-factory kb))
250 | kb))
251 |
252 | (defn close-existing-sesame-connection [kb]
253 | (when (:connection kb)
254 | (.close (:connection kb)))
255 | (copy-sesame-slots (assoc (SesameKB. (:server kb) nil (features kb))
256 | :value-factory (:value-factory kb))
257 | kb))
258 |
259 |
260 | ;; (defmethod kb org.openrdf.repository.http.HTTPRepository [class-name]
261 | ;; (new-sesame-server))
262 |
263 | ;; (defmethod kb org.openrdf.repository.Repository [class-name]
264 | ;; (new-sesame-server))
265 |
266 | (defmethod kb org.openrdf.repository.http.HTTPRepository [arg]
267 | (if (class? arg)
268 | (new-sesame-server)
269 | (sesame-kb-helper arg)))
270 |
271 |
272 | (defmethod kb org.openrdf.repository.Repository [arg]
273 | (if (class? arg)
274 | (new-sesame-server)
275 | (sesame-kb-helper arg)))
276 |
277 | (defmethod kb org.openrdf.sail.memory.MemoryStore [arg]
278 | (if (class? arg)
279 | (let [repo (SailRepository. (MemoryStore.))]
280 | ;; (.setPreferredTupleQueryResultFormat repo
281 | ;; TupleQueryResultFormat/SPARQL)
282 | (.initialize repo)
283 | (sesame-kb-helper repo))
284 | (sesame-kb-helper arg)))
285 |
286 | ;; need to add more kb constructors in here for taking in various sesame objects
287 | ;; repository, sail, etc. instances
288 |
289 |
290 | (defn sesame-initialize [kb]
291 | (synch-ns-mappings kb))
292 |
293 | ;; (defn new-sesame-memory-kb []
294 | ;; (let [repo (SailRepository. (MemoryStore.))]
295 | ;; (.initialize repo)
296 | ;; ;(.setPreferredTupleQueryResultFormat repo TupleQueryResultFormat/SPARQL)
297 | ;; (assoc (SesameKB. repo (initial-ns-mappings) nil)
298 | ;; :value-factory (.getValueFactory repo))))
299 |
300 | (defn new-sesame-memory-kb []
301 | (kb org.openrdf.sail.memory.MemoryStore))
302 |
303 |
304 | (defmethod kb :sesame-mem [_]
305 | (new-sesame-memory-kb))
306 |
307 |
308 | ;;; --------------------------------------------------------
309 | ;;; END
310 | ;;; --------------------------------------------------------
311 |
--------------------------------------------------------------------------------
/EPLv1.0.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Eclipse Public License - Version 1.0
8 |
25 |
26 |
27 |
28 |
29 |
30 | Eclipse Public License - v 1.0
31 |
32 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
33 | PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR
34 | DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
35 | AGREEMENT.
36 |
37 | 1. DEFINITIONS
38 |
39 | "Contribution" means:
40 |
41 | a) in the case of the initial Contributor, the initial
42 | code and documentation distributed under this Agreement, and
43 | b) in the case of each subsequent Contributor:
44 | i) changes to the Program, and
45 | ii) additions to the Program;
46 | where such changes and/or additions to the Program
47 | originate from and are distributed by that particular Contributor. A
48 | Contribution 'originates' from a Contributor if it was added to the
49 | Program by such Contributor itself or anyone acting on such
50 | Contributor's behalf. Contributions do not include additions to the
51 | Program which: (i) are separate modules of software distributed in
52 | conjunction with the Program under their own license agreement, and (ii)
53 | are not derivative works of the Program.
54 |
55 | "Contributor" means any person or entity that distributes
56 | the Program.
57 |
58 | "Licensed Patents" mean patent claims licensable by a
59 | Contributor which are necessarily infringed by the use or sale of its
60 | Contribution alone or when combined with the Program.
61 |
62 | "Program" means the Contributions distributed in accordance
63 | with this Agreement.
64 |
65 | "Recipient" means anyone who receives the Program under
66 | this Agreement, including all Contributors.
67 |
68 | 2. GRANT OF RIGHTS
69 |
70 | a) Subject to the terms of this Agreement, each
71 | Contributor hereby grants Recipient a non-exclusive, worldwide,
72 | royalty-free copyright license to reproduce, prepare derivative works
73 | of, publicly display, publicly perform, distribute and sublicense the
74 | Contribution of such Contributor, if any, and such derivative works, in
75 | source code and object code form.
76 |
77 | b) Subject to the terms of this Agreement, each
78 | Contributor hereby grants Recipient a non-exclusive, worldwide,
79 | royalty-free patent license under Licensed Patents to make, use, sell,
80 | offer to sell, import and otherwise transfer the Contribution of such
81 | Contributor, if any, in source code and object code form. This patent
82 | license shall apply to the combination of the Contribution and the
83 | Program if, at the time the Contribution is added by the Contributor,
84 | such addition of the Contribution causes such combination to be covered
85 | by the Licensed Patents. The patent license shall not apply to any other
86 | combinations which include the Contribution. No hardware per se is
87 | licensed hereunder.
88 |
89 | c) Recipient understands that although each Contributor
90 | grants the licenses to its Contributions set forth herein, no assurances
91 | are provided by any Contributor that the Program does not infringe the
92 | patent or other intellectual property rights of any other entity. Each
93 | Contributor disclaims any liability to Recipient for claims brought by
94 | any other entity based on infringement of intellectual property rights
95 | or otherwise. As a condition to exercising the rights and licenses
96 | granted hereunder, each Recipient hereby assumes sole responsibility to
97 | secure any other intellectual property rights needed, if any. For
98 | example, if a third party patent license is required to allow Recipient
99 | to distribute the Program, it is Recipient's responsibility to acquire
100 | that license before distributing the Program.
101 |
102 | d) Each Contributor represents that to its knowledge it
103 | has sufficient copyright rights in its Contribution, if any, to grant
104 | the copyright license set forth in this Agreement.
105 |
106 | 3. REQUIREMENTS
107 |
108 | A Contributor may choose to distribute the Program in object code
109 | form under its own license agreement, provided that:
110 |
111 | a) it complies with the terms and conditions of this
112 | Agreement; and
113 |
114 | b) its license agreement:
115 |
116 | i) effectively disclaims on behalf of all Contributors
117 | all warranties and conditions, express and implied, including warranties
118 | or conditions of title and non-infringement, and implied warranties or
119 | conditions of merchantability and fitness for a particular purpose;
120 |
121 | ii) effectively excludes on behalf of all Contributors
122 | all liability for damages, including direct, indirect, special,
123 | incidental and consequential damages, such as lost profits;
124 |
125 | iii) states that any provisions which differ from this
126 | Agreement are offered by that Contributor alone and not by any other
127 | party; and
128 |
129 | iv) states that source code for the Program is available
130 | from such Contributor, and informs licensees how to obtain it in a
131 | reasonable manner on or through a medium customarily used for software
132 | exchange.
133 |
134 | When the Program is made available in source code form:
135 |
136 | a) it must be made available under this Agreement; and
137 |
138 | b) a copy of this Agreement must be included with each
139 | copy of the Program.
140 |
141 | Contributors may not remove or alter any copyright notices contained
142 | within the Program.
143 |
144 | Each Contributor must identify itself as the originator of its
145 | Contribution, if any, in a manner that reasonably allows subsequent
146 | Recipients to identify the originator of the Contribution.
147 |
148 | 4. COMMERCIAL DISTRIBUTION
149 |
150 | Commercial distributors of software may accept certain
151 | responsibilities with respect to end users, business partners and the
152 | like. While this license is intended to facilitate the commercial use of
153 | the Program, the Contributor who includes the Program in a commercial
154 | product offering should do so in a manner which does not create
155 | potential liability for other Contributors. Therefore, if a Contributor
156 | includes the Program in a commercial product offering, such Contributor
157 | ("Commercial Contributor") hereby agrees to defend and
158 | indemnify every other Contributor ("Indemnified Contributor")
159 | against any losses, damages and costs (collectively "Losses")
160 | arising from claims, lawsuits and other legal actions brought by a third
161 | party against the Indemnified Contributor to the extent caused by the
162 | acts or omissions of such Commercial Contributor in connection with its
163 | distribution of the Program in a commercial product offering. The
164 | obligations in this section do not apply to any claims or Losses
165 | relating to any actual or alleged intellectual property infringement. In
166 | order to qualify, an Indemnified Contributor must: a) promptly notify
167 | the Commercial Contributor in writing of such claim, and b) allow the
168 | Commercial Contributor to control, and cooperate with the Commercial
169 | Contributor in, the defense and any related settlement negotiations. The
170 | Indemnified Contributor may participate in any such claim at its own
171 | expense.
172 |
173 | For example, a Contributor might include the Program in a commercial
174 | product offering, Product X. That Contributor is then a Commercial
175 | Contributor. If that Commercial Contributor then makes performance
176 | claims, or offers warranties related to Product X, those performance
177 | claims and warranties are such Commercial Contributor's responsibility
178 | alone. Under this section, the Commercial Contributor would have to
179 | defend claims against the other Contributors related to those
180 | performance claims and warranties, and if a court requires any other
181 | Contributor to pay any damages as a result, the Commercial Contributor
182 | must pay those damages.
183 |
184 | 5. NO WARRANTY
185 |
186 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
187 | PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
188 | OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
189 | ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
190 | OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
191 | responsible for determining the appropriateness of using and
192 | distributing the Program and assumes all risks associated with its
193 | exercise of rights under this Agreement , including but not limited to
194 | the risks and costs of program errors, compliance with applicable laws,
195 | damage to or loss of data, programs or equipment, and unavailability or
196 | interruption of operations.
197 |
198 | 6. DISCLAIMER OF LIABILITY
199 |
200 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
201 | NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
202 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
203 | WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
204 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
205 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
206 | DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
207 | HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
208 |
209 | 7. GENERAL
210 |
211 | If any provision of this Agreement is invalid or unenforceable under
212 | applicable law, it shall not affect the validity or enforceability of
213 | the remainder of the terms of this Agreement, and without further action
214 | by the parties hereto, such provision shall be reformed to the minimum
215 | extent necessary to make such provision valid and enforceable.
216 |
217 | If Recipient institutes patent litigation against any entity
218 | (including a cross-claim or counterclaim in a lawsuit) alleging that the
219 | Program itself (excluding combinations of the Program with other
220 | software or hardware) infringes such Recipient's patent(s), then such
221 | Recipient's rights granted under Section 2(b) shall terminate as of the
222 | date such litigation is filed.
223 |
224 | All Recipient's rights under this Agreement shall terminate if it
225 | fails to comply with any of the material terms or conditions of this
226 | Agreement and does not cure such failure in a reasonable period of time
227 | after becoming aware of such noncompliance. If all Recipient's rights
228 | under this Agreement terminate, Recipient agrees to cease use and
229 | distribution of the Program as soon as reasonably practicable. However,
230 | Recipient's obligations under this Agreement and any licenses granted by
231 | Recipient relating to the Program shall continue and survive.
232 |
233 | Everyone is permitted to copy and distribute copies of this
234 | Agreement, but in order to avoid inconsistency the Agreement is
235 | copyrighted and may only be modified in the following manner. The
236 | Agreement Steward reserves the right to publish new versions (including
237 | revisions) of this Agreement from time to time. No one other than the
238 | Agreement Steward has the right to modify this Agreement. The Eclipse
239 | Foundation is the initial Agreement Steward. The Eclipse Foundation may
240 | assign the responsibility to serve as the Agreement Steward to a
241 | suitable separate entity. Each new version of the Agreement will be
242 | given a distinguishing version number. The Program (including
243 | Contributions) may always be distributed subject to the version of the
244 | Agreement under which it was received. In addition, after a new version
245 | of the Agreement is published, Contributor may elect to distribute the
246 | Program (including its Contributions) under the new version. Except as
247 | expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
248 | rights or licenses to the intellectual property of any Contributor under
249 | this Agreement, whether expressly, by implication, estoppel or
250 | otherwise. All rights in the Program not expressly granted under this
251 | Agreement are reserved.
252 |
253 | This Agreement is governed by the laws of the State of New York and
254 | the intellectual property laws of the United States of America. No party
255 | to this Agreement will bring a legal action under this Agreement more
256 | than one year after the cause of action arose. Each party waives its
257 | rights to a jury trial in any resulting litigation.
258 |
259 |
260 |
261 |
262 |
--------------------------------------------------------------------------------
/kr-core/src/test/clojure/edu/ucdenver/ccp/test/kr/test_sparql.clj:
--------------------------------------------------------------------------------
1 | (ns edu.ucdenver.ccp.test.kr.test-sparql
2 | (use clojure.test
3 | ;;clojure.test.junit
4 |
5 | edu.ucdenver.ccp.test.kr.test-kb
6 |
7 | edu.ucdenver.ccp.kr.variable
8 | edu.ucdenver.ccp.kr.kb
9 | edu.ucdenver.ccp.kr.rdf
10 | edu.ucdenver.ccp.kr.sparql)
11 | (import java.net.URI))
12 |
13 | ;;; --------------------------------------------------------
14 | ;;; constansts
15 | ;;; --------------------------------------------------------
16 |
17 | (def uri-a (URI. "http://www.example.org/a"))
18 | (def uri-p (URI. "http://www.example.org/p"))
19 | (def uri-b (URI. "http://www.example.org/b"))
20 | (def uri-x (URI. "http://www.example.org/x"))
21 |
22 |
23 | (def test-triples-uri
24 | '((ex/a rdf/type foaf/Person )
25 | (ex/a foaf/name "Alice" )
26 | (ex/a foaf/mbox "" )
27 | (ex/a foaf/mbox "" )
28 | (ex/a foaf/knows ex/b)
29 | (ex/b rdf/type foaf/Person )
30 | (ex/b foaf/name "Bob" )))
31 |
32 |
33 | (def test-triples-6-1
34 | '((ex/a rdf/type foaf/Person )
35 | (ex/a foaf/name "Alice" )
36 | (ex/a foaf/mbox "" )
37 | (ex/a foaf/mbox "" )
38 |
39 | (ex/b rdf/type foaf/Person )
40 | (ex/b foaf/name "Bob" )))
41 |
42 | (def test-triples-6-3
43 | '((ex/a foaf/name "Alice" )
44 | (ex/a foaf/homepage "" )
45 |
46 | (ex/b foaf/name "Bob" )
47 | (ex/b foaf/mbox "" )))
48 |
49 | (def test-triples-7
50 | '((ex/a dc10/title "SPARQL Query Language Tutorial" )
51 | (ex/a dc10/creator "Alice" )
52 |
53 | (ex/b dc11/title "SPARQL Protocol Tutorial" )
54 | (ex/b dc11/creator "Bob" )
55 |
56 | (ex/c dc10/title "SPARQL" )
57 | (ex/c dc11/title "SPARQL (updated)" )))
58 |
59 | (def test-triples-10-2-1
60 | '((ex/a foaf/givenname "Alice" )
61 | (ex/a foaf/family_name "Hacker" )
62 |
63 | (ex/b foaf/firstname "Bob" )
64 | (ex/b foaf/surname "Hacker" )))
65 |
66 | (def test-triples-numbers-equality
67 | '((ex/a foaf/givenname "Alice" )
68 | (ex/a foaf/surname "Hacker" )
69 | (ex/a foaf/age [40 xsd/integer])
70 |
71 | (ex/b foaf/firstname "Bob" )
72 | (ex/b foaf/surname "Hacker" )
73 | (ex/b foaf/age 40) ;the default should be xsd/integer
74 |
75 | (ex/c foaf/firstname "Fred" )
76 | (ex/c foaf/surname "Hacker" )
77 | (ex/c foaf/age [50 xsd/integer])));50)))
78 |
79 | (def test-triples-lang
80 | '((ex/a foaf/firstname "Alice" )
81 | (ex/b foaf/firstname ["Bob" "en"])
82 | (ex/c foaf/firstname ["Bob"])))
83 |
84 | (def test-triples-custom-type
85 | '((ex/a ex/p ["foo" ex/custom])
86 | (ex/b ex/p ["foo" ex/custom2])))
87 |
88 | (def test-triples-custom-type-uri
89 | `((ex/a ex/p ["foo" ex/custom])
90 | (ex/b ex/p ["foo" ~(URI. "http://www.example.org/custom")])))
91 |
92 |
93 |
94 | ;;; --------------------------------------------------------
95 | ;;; helpers
96 | ;;; --------------------------------------------------------
97 |
98 | ;;; --------------------------------------------------------
99 | ;;; tests
100 | ;;; --------------------------------------------------------
101 |
102 | (kb-test test-kb-loading-triples test-triples
103 | (is *kb*))
104 |
105 | (kb-test test-simple-ask test-triples
106 | (is (ask '((_/person foaf/name ?/name)
107 | (_/person foaf/mbox ?/email)))))
108 |
109 | (kb-test test-simple-select test-triples
110 | (is (= 2
111 | (count (query '((_/person foaf/name ?/name)
112 | (_/person foaf/mbox ?/email)))))))
113 |
114 | (kb-test test-optional test-triples-6-1
115 | (is (= 3
116 | (count
117 | (query '((?/person foaf/name ?/name)
118 | (:optional
119 | (?/person foaf/mbox ?/email))))))))
120 |
121 | (kb-test test-count-query test-triples-6-1
122 | (is (= 3
123 | (count-query '((?/person foaf/name ?/name)
124 | (:optional
125 | (?/person foaf/mbox ?/email)))))))
126 |
127 |
128 | (kb-test test-optional-select-6-3 test-triples-6-3
129 | (is (= 2
130 | (count
131 | (query '((?/person foaf/name ?/name)
132 | (:optional (?/person foaf/mbox ?/email))
133 | (:optional (?/person foaf/homepage ?/hpage))))))))
134 |
135 | (kb-test test-union-select-7 test-triples-7
136 | (is (= 2
137 | (count
138 | (query
139 | '(:union
140 | ((?/book dc10/title ?/title)
141 | (?/book dc10/creator ?/author))
142 | ((?/book dc11/title ?/title)
143 | (?/book dc11/creator ?/author))))))))
144 |
145 | (kb-test test-union-select-10-2-1 test-triples-10-2-1
146 | (is (= 2
147 | (count
148 | (query
149 | '((:union ((?/x foaf/firstname ?/gname))
150 | ((?/x foaf/givenname ?/gname)))
151 | (:union ((?/x foaf/surname ?/fname))
152 | ((?/x foaf/family_name ?/fname)))))))))
153 |
154 | (kb-test test-bound-operator test-triples-6-1
155 | (is (= 2 ;this is 2 but should be one if ?/person doesn't capture
156 | (count
157 | (query '((?/person foaf/name ?/name)
158 | (:optional
159 | (?/person foaf/mbox ?/email))
160 | (:bound ?/email))))))
161 | (is (= 1 ;just bob
162 | (count
163 | (query '((?/person foaf/name ?/name)
164 | (:optional
165 | (?/person foaf/mbox ?/email))
166 | (:not (:bound ?/email))))))))
167 |
168 | (kb-test test-not-operator test-triples-6-1
169 | (is (= 1 ;just bob
170 | (count
171 | (query '((?/person foaf/name ?/name)
172 | (:optional
173 | (?/person foaf/mbox ?/email))
174 | (:not (:bound ?/email)))))))
175 | (is (= 1 ;just bob
176 | (count
177 | (query '((?/person foaf/name ?/name)
178 | (:optional
179 | (?/person foaf/mbox ?/email))
180 | (! (:bound ?/email))))))))
181 |
182 | (kb-test test-numbers test-triples-numbers-equality
183 | (is (= 2 ;two because of reflection
184 | (count (query '((?/person foaf/surname ?/name)
185 | (?/person foaf/age ?/age1)
186 | (?/person2 foaf/surname ?/name)
187 | (?/person2 foaf/age ?/age2)
188 | (= ?/age1 ?/age2)
189 | (!= ?/person ?/person2)
190 | )))))
191 | (is (= 2
192 | (count (query '((?/person foaf/surname ?/name)
193 | (?/person foaf/age ?/age1)
194 | (?/person2 foaf/surname ?/name)
195 | (?/person2 foaf/age ?/age2)
196 | (> ?/age1 ?/age2)
197 | ))))))
198 |
199 | (kb-test test-n-ary-or test-triples-numbers-equality
200 | (is (= 3
201 | (count (query '((?/person foaf/surname ?/name)
202 | (?/person foaf/age ?/age)
203 | (:or (= ?/age 30)
204 | (= ?/age 40)
205 | (= ?/age 50))))))))
206 |
207 | (kb-test test-boxed-number test-triples-numbers-equality
208 | (is (= 2
209 | (count (query '((?/person foaf/surname ?/name)
210 | (?/person foaf/age 40))))))
211 | (is (= 0
212 | (count (query '((?/person foaf/surname ?/name)
213 | (?/person foaf/age [40]))))))
214 | (is (= 2
215 | (count (query '((?/person foaf/surname ?/name)
216 | (?/person foaf/age [40 xsd/integer]))))))
217 |
218 | (is (= 2
219 | (count (query '((?/person foaf/surname ?/name)
220 | (?/person foaf/age ["40" xsd/integer])))))))
221 |
222 |
223 | (kb-test test-lang test-triples-lang
224 | (is (= 3
225 | (count (query '((?/person foaf/firstname ?/x))))))
226 | ;;TODO this langague tag is wrong there shouldn't need to be
227 | ;; nested escaped quotes
228 | (is (= 2
229 | (count (query '((?/person foaf/firstname ?/x)
230 | (= (:lang ?/x) ["en"]))))))
231 | ;; the next to are auto-languaged into "en"
232 | (is (= 1
233 | (count (query '((?/person foaf/firstname "Bob"))))))
234 | (is (= 1
235 | (count (query '((?/person foaf/firstname "Alice"))))))
236 | ;; forced "en"
237 | (is (= 1
238 | (count (query '((?/person foaf/firstname ["Alice" "en"]))))))
239 | ;; boxed forcing off auto-language thus missing
240 | (is (= 0
241 | (count (query '((?/person foaf/firstname ["Alice"]))))))
242 | ;;note the lower case 'b' on the failure test
243 | (is (= 0
244 | (count (query '((?/person foaf/firstname "bob")))))))
245 |
246 |
247 |
248 |
249 | (kb-test test-query-visitor test-triples-lang
250 | (let [count (atom 0)]
251 | (query-visit (fn [bindings] (swap! count inc))
252 | '((?/person foaf/firstname ?/x)))
253 | (is (= 3 @count)))
254 |
255 | (query-visit (fn [bindings] (is (= 2 (count bindings))))
256 | '((?/person foaf/firstname ?/x)))
257 |
258 | (query-visit (fn [bindings]
259 | (let [key-set (set (map first bindings))]
260 | (is (key-set '?/x))
261 | (is (key-set '?/person))))
262 | '((?/person foaf/firstname ?/x))))
263 |
264 | ;; there is a bug where "3"^^
265 | ;; was coming out as "3" instead of 3
266 | (kb-test test-integer-clj-ify test-triples-numbers-equality
267 | (is (= 40
268 | ('?/age (first (query '((?/person foaf/givenname "Alice")
269 | (?/person foaf/age ?/age))))))))
270 |
271 |
272 |
273 | (kb-test test-backquote-operators test-triples-numbers-equality
274 | (is (= 2 ;two because of reflection
275 | (count (query `((?/person foaf/surname ?/name)
276 | (?/person foaf/age ?/age1)
277 | (?/person2 foaf/surname ?/name)
278 | (?/person2 foaf/age ?/age2)
279 | (= ?/age1 ?/age2)
280 | (!= ?/person ?/person2)
281 | )))))
282 | (is (= 2
283 | (count (query `((?/person foaf/surname ?/name)
284 | (?/person foaf/age ?/age1)
285 | (?/person2 foaf/surname ?/name)
286 | (?/person2 foaf/age ?/age2)
287 | (> ?/age1 ?/age2)
288 | ))))))
289 |
290 |
291 | (kb-test test-strings-in-operators test-triples-6-3
292 | (is (= 2
293 | (count (query `((?/person foaf/name ?/name))))))
294 | (is (= 1
295 | (count (query `((?/person foaf/name ?/name)
296 | (= "Bob" ?/name))))))
297 | ;; box to drop the language tag since none given
298 | (is (= 0
299 | (count (query `((?/person foaf/name ?/name)
300 | (= ["Bob"] ?/name)))))))
301 |
302 | (kb-test test-regex-operator test-triples-6-3
303 | (is (= 2
304 | (count (query `((?/person foaf/name ?/name))))))
305 | (is (= 1
306 | (count (query `((?/person foaf/name ?/name)
307 | (:regex ?/name "^ali" "i")))))))
308 |
309 |
310 | (kb-test test-uri-pat test-triples-uri
311 | (is (= 1
312 | (count (query '((?/person1 foaf/knows ?/person2))))))
313 | (is (= 1
314 | (count (query '((ex/a foaf/knows ?/person2))))))
315 | (is (= 1
316 | (count (query '((?/person1 foaf/knows ex/b))))))
317 | (is (= 0
318 | (count (query '((ex/b foaf/knows ?/person2))))))
319 | (is (= 1
320 | (count (query `((?/person1 foaf/knows ~uri-b))))))
321 | (is (= 1
322 | (count (query `((~uri-a foaf/knows ?/person2))))))
323 | (is (ask `((~uri-a foaf/knows ~uri-b))))
324 | )
325 |
326 |
327 | (kb-test test-custom-type test-triples-custom-type
328 | (is (= 2
329 | (count (query '((?/person1 ex/p ?/custom))))))
330 | (is (= 1
331 | (count (query '((?/a ex/p ["foo" ex/custom])))))))
332 |
333 | (kb-test test-custom-type-uri test-triples-custom-type-uri
334 | (is (= 2
335 | (count (query '((?/person1 ex/p ?/custom))))))
336 | (is (= 2
337 | (count (query '((?/a ?/p ["foo" ex/custom]))))))
338 | (is (= 2
339 | (count
340 | (query `((?/a
341 | ?/p
342 | ["foo" ~(URI. "http://www.example.org/custom")])))))))
343 |
344 |
345 |
346 | ;;; --------------------------------------------------------
347 | ;;; END
348 | ;;; --------------------------------------------------------
349 |
--------------------------------------------------------------------------------