开发者

Why doesn't model-query return query results? (clj-plaza)

I am using clj-plaza (0.0.5-SNAPSHOT) to query a Sesame/Jena Model. The function model-query does not appear to execute the query. It returns the internal representation of a clj-plaza query instead.

(init-jena-framework)
(def *m* (build-model))

(with-model *m*
 (model-add-triples
  (model-to-triples 
    (document-to-model "http://www.rdfdata.org/dat/rdfdata.rdf" 
                       :rdf))))

(def all-subjects-query 
 (defquery
  (query-set-vars [:?subject])
  (query-set-pattern (make-pattern [[:?subject ?p ?o]]))
  (query-set-type :select))

;; As expected
(model-query-triples *m* all-subjects-query)
=> clojure.lang.LazySeq@2e1e8502

;; Does not execute query (?)
(model-query *m* all-subjects-query)
=> {:kind :select, :pattern [[:?object :?p :?o]], :vars [:?object]}

The official tutorial claims model-query re开发者_StackOverflow社区turns a list of bindings from the query:

({:?object "http://randomurl.com/asdf"}
 {:?object "http://asdf.com/qwer"})


This is a bug.

Here is a fix. Until it is merged back and updated on clojars, feel free to use my fork.

A workaround would be to use (query model query) (instead of model-query)after importing the corresponding Jena or Sesame implementation.

For Sesame:

(use 'plaza.rdf.implementations.sesame)
(init-sesame-framework)
(def *m* (build-model))

(with-model *m*
 (model-add-triples
  (model-to-triples 
    (document-to-model "http://www.rdfdata.org/dat/rdfdata.rdf" 
                       :rdf))))

(def all-subjects-query 
 (defquery
  (query-set-vars [:?subject])
  (query-set-pattern (make-pattern [[:?subject ?p ?o]]))
  (query-set-type :select))

(query *m* all-subjects-query)

=> [{:?s #<SesameResource http://www.rdfdata.org/dat/rdfdata.rdf>} 
{:?s #<SesameResource http://www.rdfdata.org/dat/rdfdata.rdf>} 
{:?s #<SesameResource http://www.rdfdata.org/dat/rdfdata.rdf>} 
{:?s #<SesameResource http://www.rdfdata.org/dat/rdfdata.rdf>} 
{:?s #<SesameResource http://rdfweb.org/topic/FOAFBulletinBoard>} 
{:?s #<SesameResource http://rdfweb.org/topic/FOAFBulletinBoard>} ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜