为什么模型查询不返回查询结果? (clj-广场)

发布于 2024-10-15 05:33:16 字数 1119 浏览 1 评论 0原文

我正在使用 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"})

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 returns a list of bindings from the query:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浸婚纱 2024-10-22 05:33:16

这是一个错误。

这是一个修复。在它被合并回来并在 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>} ...

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>} ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文