以N-Triples格式读取RDF数据

时间:2014-07-16 14:25:07

标签: ruby-on-rails ruby rubygems rvm rdf

我正在尝试执行rdf gem的示例,请参阅here

代码我尝试执行:

   require 'rdf'
   include RDF
   require 'rdf/ntriples'
   graph = RDF::Graph.load("http://ruby-rdf.github.com/rdf/etc/doap.nt")

我收到以下错误:

/home/USER/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/uri.rb:96:in `<top (required)>': URI is not a module (TypeError)
from /home/USER/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/USER/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/USER/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:23:in `<top (required)>'
from /home/USER/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/USER/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/util/file.rb:1:in `<top (required)>'
from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/reader.rb:136:in `open'
from rdf_foaf.rb:5:in `<main>'

我的设置:

ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
rvm 1.25.28 (stable)

rdf (1.1.4.2)
rdf-aggregate-repo (1.1.0)
rdf-isomorphic (1.1.0)
rdf-json (1.1.0)
rdf-microdata (1.1.1.3)
rdf-n3 (1.1.1)
rdf-rdfa (1.1.3.2)
rdf-rdfxml (1.1.0.1)
rdf-trig (1.1.3.1)
rdf-trix (1.1.0)
rdf-turtle (1.1.4)
rdf-xsd (1.1.1)

由于错误似乎来自uri.rb,我不知道如何处理它。 谁有解决这个问题的提示?

1 个答案:

答案 0 :(得分:1)

当您在脚本中include RDF时,可以使用RDF::URI访问URI。您的错误使得此命名空间似乎也适用于所需的文件。我不太熟悉Ruby在这种情况下如何处理include(我试图避免&#34;污染&#34;全局命名空间,通常只在类定义中使用include) 。

在任何情况下,此处都可以省略include RDF行,因为您使用RDF::Graph的完整参考。

require 'net/http'的调用使其有效,因为它会在URI类声明该名称之前加载RDF::URI