我正在尝试为 RDF 加载 Clojure 库 clj-plaza在 Clojure REPL 中像这样:
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)在协议(protocol) 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)))
我似乎真的无法指出这里出了什么问题,在源代码中似乎所有问题都加起来了。
最佳答案
(defn document-to-model ...)
片段没有实现load-stream
;它实现了一个名为 document-to-model
的函数,该函数调用带有一堆参数的 load-stream
,第一个参数 -- *rdf-model*
-- 需要是 RDFModel
协议(protocol)扩展到的类型(或直接实现协议(protocol)或相应接口(interface)的类型)。
clj-plaza
在命名空间 plaza.rdf.implementations.sesame
中提供了 RDFModel
的两个实现(参见 (deftype SesameModel ...
,line 218 在源代码中)和 plaza.rdf.implementations.jena
(参见 (deftype JenaModel ...
,line 167 ). require
-ing 它们应该足以引入所述实现;然后您可以将它们与适当类型的 *rdf-model*
一起使用。
关于java - Clojure:协议(protocol)中没有方法的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3281780/