Clojure:协议中没有方法的实现

发布于 2024-09-11 03:14:09 字数 1439 浏览 2 评论 0原文

我正在尝试在 Clojure REPL 中加载 RDF clj-plaza 的 Clojure 库,如下所示

user=> (use 'plaza.rdf.core)
nil

:有一个名为 plaza 的文件夹、一个名为 rdf 的子文件夹和文件 core.clj 可用,据我所知,Clojure REPL 会按应有的方式加载该库。

现在,如果我

user=> (alter-root-rdf-ns “http://www.example.org/”)
"http://www.example.org"

再次这样做,据我所知 core.clj 库正在按其应有的方式报告。 现在,

(def e (document-to-model “http://www.snee.com/rdf/elvisimp.rdf” :xml))
java.lang.IllegalArgumentException: No implementation of method: :load-stream of protocol: #’plaza.rdf.core/RDFModel found for class: nil (NO_SOURCE_FILE:2)

如果我尝试 f.ex,我会得到相同的结果。

(make-triples [["http://triple1" "http://triple2" "http://triple3"]])

源代码中 (core.clj) RDFModel 协议中有一个名为 load-stream 的方法,

(defprotocol RDFModel
  "Operations for the manipulation of RDF"
  ....
  (load-stream [model stream format] "Load triples from a stream")
  ....

并且实现了 load-stream

(defn document-to-model
  "Adds a set of triples read from a serialized document into a model"
  ([stream format]
    (load-stream *rdf-model* stream format)))

我似乎无法真正指出这里出了什么问题,在源代码中,这一切似乎都加起来了。

I am trying to load the Clojure library for RDF clj-plaza in Clojure REPL like so:

user=> (use 'plaza.rdf.core)
nil

I have a folder named plaza, and a subfolder named rdf and the file core.clj available and as far as I can tell, Clojure REPL loads the library as it should.

Now, if I do

user=> (alter-root-rdf-ns “http://www.example.org/”)
"http://www.example.org"

And again, as far as I can tell the core.clj library is reporting as it should.
Now I do

(def e (document-to-model “http://www.snee.com/rdf/elvisimp.rdf” :xml))
java.lang.IllegalArgumentException: No implementation of method: :load-stream of protocol: #’plaza.rdf.core/RDFModel found for class: nil (NO_SOURCE_FILE:2)

I get the same result if I try f.ex.

(make-triples [["http://triple1" "http://triple2" "http://triple3"]])

In the source code (core.clj) there is a method called load-stream in the protocol RDFModel

(defprotocol RDFModel
  "Operations for the manipulation of RDF"
  ....
  (load-stream [model stream format] "Load triples from a stream")
  ....

And load-stream is implemented

(defn document-to-model
  "Adds a set of triples read from a serialized document into a model"
  ([stream format]
    (load-stream *rdf-model* stream format)))

I can't really seem to pinpoint what is wrong here, in the source code it all seems to add up.

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

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

发布评论

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

评论(2

め可乐爱微笑 2024-09-18 03:14:09

(defn document-to-model ...) 代码段未实现 load-stream;它实现了一个名为 document-to-model 的函数,该函数使用一堆参数调用 load-stream,其中第一个参数 - *rdf-model*< /code> —— 需要是 RDFModel 协议已扩展的类型(或者直接实现协议或相应的接口)。

clj-plaza 在命名空间 plaza.rdf.implementations.sesame 中提供了 RDFModel 的两个实现(请参阅 (deftype SesameModel .. ., 源代码中的第 218 行)和 plaza.rdf.implementations.jena (参见 (deftype JenaModel ..., 第 167 行)。需要-ing 它们应该足以引入所述实现;然后您可以将它们与适当类型的 *rdf-model* 一起使用。

The (defn document-to-model ...) snippet does not implement load-stream; it implements a function called document-to-model which calls load-stream with a bunch of arguments, the first of which -- *rdf-model* -- needs to be of a type to which the RDFModel protocol has been extended (or which implements the protocol or the corresponding interface directly).

clj-plaza provides two implementations of RDFModel, in the namespaces plaza.rdf.implementations.sesame (see (deftype SesameModel ..., line 218 in the source) and plaza.rdf.implementations.jena (see (deftype JenaModel ..., line 167). require-ing them should be enough to pull in said implementations; then you can use them with *rdf-model*s of appropriate type.

2024-09-18 03:14:09

(require... 之后的一步是 (init-jena-framework) 或 (init-sesame-framework)。

one more step after (require... is to (init-jena-framework) or (init-sesame-framework).

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