我正在尝试按照ruby RDF gem的文档对图形进行初始化。 (http://www.rubydoc.info/gems/rdf/RDF/Graph)
文档提供以下示例:
graph = Graph.new("http://rubygems.org/")
我试过运行这个确切的命令,我得到一个错误(我真的不明白)。 (请注意,我在使用本地计算机上的文件时成功加载了图表,所以我认为尝试从http网址加载图表时会遇到一些问题。)
我正在通过命令行界面Gem Thor运行命令。下面是可执行文件,然后返回错误。
档案lbp
#!/usr/bin/env ruby
require 'rdf'
require 'rdf/rdfxml'
require 'rdf/ntriples'
require 'thor'
require 'pry'
class LbpCli < Thor
desc "hello", "say hello to NAME"
def hello(name)
puts "Hello #{name}!"
end
desc "init", "create projectifles dirs in current working directory"
def init(dir="projectfiles")
directories = ["#{dir}/Conf", "#{dir}/Textfiles", "#{dir}/citationlists"]
FileUtils.mkpath(directories)
end
desc "projecfile", "make projetfile from SCTA"
def projectfile
graph = RDF::Graph.new("http://rubygems.org")
end
end
LbpCli.start(ARGV)
projectfile是相关方法。下面是命令运行并返回错误。
文件lbp
使用方法projectfile
$ ./lbp projectfile
/Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/rdf-1.1.7/lib/rdf/model/graph.rb:126:in `initialize': Can't apply context unless initialized with `data` supporting contexts (ArgumentError)
from ./lbp:28:in `new'
from ./lbp:28:in `projectfile'
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from ./lbp:45:in `<main>'
修改
如果我通过明确地创建resource
来改变构造:
resource = RDF::Resource(RDF::URI.new("http://rdf.rubyforge.org/"))
graph = RDF::Graph.load(resource)
我收到一个新错误:
bin $ ./lbp projectfile
/Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/rdf-1.1.7/lib/rdf/util/file.rb:66:in `open_file': uninitialized constant RDF::Util::File::OpenSSL (NameError)
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/rdf-1.1.7/lib/rdf/reader.rb:136:in `open'
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/rdf-1.1.7/lib/rdf/mixin/mutable.rb:43:in `load'
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/rdf-1.1.7/lib/rdf/model/graph.rb:81:in `block in load'
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/rdf-1.1.7/lib/rdf/model/graph.rb:131:in `call'
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/rdf-1.1.7/lib/rdf/model/graph.rb:131:in `initialize'
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/rdf-1.1.7/lib/rdf/model/graph.rb:80:in `new'
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/rdf-1.1.7/lib/rdf/model/graph.rb:80:in `load'
from ./lbp:29:in `projectfile'
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
from /Users/JCWitt/.rvm/gems/ruby-2.2.0@lbp/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from ./lbp:47:in `<main>'
答案 0 :(得分:1)
文档提供以下示例:
graph = Graph.new("http://rubygems.org/")
确实,这已经过时了,必须更新文档。加载图表的正确方法如下:
graph = Graph.load("http://rubygems.org/")
但是,这不会加载任何三元组。你可以试试这个:
graph = RDF::Graph.load("http://ruby-rdf.github.io/rdf/etc/doap.nt")
如果我通过显式创建资源来稍微改变构造:
resource = RDF::Resource(RDF::URI.new("http://rdf.rubyforge.org/"))
graph = RDF::Graph.load(resource)
是的,两者都没有三倍,RDF::Resource(RDF::URI.new(...))
是多余的,因为RDF::URI
是RDF::Resource
的子类。我之前展示的负载应该可以胜任。
自述文件中的文档(可在此处找到:http://www.rubydoc.info/github/ruby-rdf/rdf以及其他文档)更清晰一些。我通过示例确认它们与1.1版本一起使用,但显然错过了这个。我将通过并重新检查示例并重新生成文档。