1

我正在使用clj-plaza(0.0.5-SNAPSHOT) 来查询 Sesame/Jena 模型。该函数model-query似乎没有执行查询。clj-plaza它改为返回查询的内部表示。

(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]}

官方教程声称model-query从查询中返回绑定列表:

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

1 回答 1

1

这是一个错误。

这是一个修复。在它被合并回来并在 clojars 上更新之前,请随意使用我的fork

一种解决方法是在导入相应的 Jena 或 Sesame 实现之后使用(query model query)(而不是)。model-query

芝麻:

(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>} ...
于 2011-02-03T13:04:03.080 回答