我使用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]}
官方tutorial声明model-query
会返回查询中的绑定列表:
({:?object "http://randomurl.com/asdf"}
{:?object "http://asdf.com/qwer"})
答案 0 :(得分:1)
这是一个错误。
这是fix。在将其合并回来并在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>} ...