Re: Having problem with rdf.rb 0.3.1

Hi Greg, thanks for the report!

You did, indeed, stumble across a bug, however it is in the error-recovery section of the code, so fixing that will just propagate the "unknown RDF format" error anyway. The reason an error would be generated is that, by default, the reader only knows about NTriples, and the content-type returned from source is text/rdf+n3 (which is actually incorrect too, it should just return text/n3). In order to parse Notation3 content (which is a super-set of NTriples), you'll need to include the rdf-n3 gem as well. Best way to accomplish this, without worrying about what formats to include explicitly, is to use the linkeddata meta-gem, which includes RDF.rb along with several other companion gems for parsers such as XHTML+RDFa, RDF/XML, N3 and Trix.

NTriples is included as part of RDF.rb, and your call setting that format explicitly should work. You'll probably need to require "rdf/ntriples" directly for that to get picked up, again this would happen automatically with linkeddata.

However, looking at the document, it is, in fact, not NTriples, but Turtle or Notation3, so you'll need to use the rdf-n3 gem to parse this. Try the following:

require 'linkeddata'
graph = RDF::Graph.load("http://dbpedia.org/data/Elvis_Presley.ntriples", :content_type => "text/n3")

I'll make sure the problem is fixed in RDF.rb. I've added text/rdf+n3 (as well as some other pseudonyms) to the rdf-n3 gem, which I'll update shortly.

Gregg

On Jan 27, 2011, at 12:15 PM, Greg Lappen wrote:

Hello all,

Not sure how active this email list is (hopefully someone out there is listening!) but I am using the rdf gem to try loading some rdf data from the web, and it's bombing out.  Here's what I get:

[greg@localhost openmedia]$ irb
irb
ree-1.8.7-2010.02 > require 'rdf'
require 'rdf'
 => true
ree-1.8.7-2010.02 > graph = RDF::Graph.load("http://dbpedia.org/data/Elvis_Presley.ntriples<http://dbpedia.org/data/Elvis_Presley..ntriples>")
graph = RDF::Graph.load("http://dbpedia.org/data/Elvis_Presley.ntriples")
{:base_uri=>#<RDF::URI:0x8097e32c(http://dbpedia.org/data/Elvis_Presley.ntriples)>, :content_type=>"text/rdf+n3", :file_name=>"http://dbpedia.org/data/Elvis_Presley.ntriples"}
NameError: undefined local variable or method `content_type' for RDF::Reader:Class
from /Users/greg/.rvm/gems/ree-1.8.7-2010.02@openmedia/gems/rdf-0.3.1/lib/rdf/reader.rb:126:in `open'
from /Users/greg/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/open-uri.rb:135:in `open_uri'
from /Users/greg/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/open-uri.rb:518:in `open'
from /Users/greg/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/open-uri.rb:30:in `open'
from /Users/greg/.rvm/gems/ree-1.8.7-2010.02@openmedia/gems/rdf-0.3.1/lib/rdf/util/file.rb:28:in `open_file'
from /Users/greg/.rvm/gems/ree-1.8.7-2010.02@openmedia/gems/rdf-0.3.1/lib/rdf/reader.rb:117:in `open'
from /Users/greg/.rvm/gems/ree-1.8.7-2010.02@openmedia/gems/rdf-0.3.1/lib/rdf/mixin/mutable.rb:40:in `load'
from /Users/greg/.rvm/gems/ree-1.8.7-2010.02@openmedia/gems/rdf-0.3.1/lib/rdf/model/graph.rb:95:in `load!'
from /Users/greg/.rvm/gems/ree-1.8.7-2010.02@openmedia/gems/rdf-0.3.1/lib/rdf/model/graph.rb:56:in `load'
from /Users/greg/.rvm/gems/ree-1.8.7-2010.02@openmedia/gems/rdf-0.3.1/lib/rdf/model/graph.rb:84:in `call'
from /Users/greg/.rvm/gems/ree-1.8.7-2010.02@openmedia/gems/rdf-0.3.1/lib/rdf/model/graph.rb:84:in `initialize'
from /Users/greg/.rvm/gems/ree-1.8.7-2010.02@openmedia/gems/rdf-0.3.1/lib/rdf/model/graph.rb:55:in `new'
from /Users/greg/.rvm/gems/ree-1.8.7-2010.02@openmedia/gems/rdf-0.3.1/lib/rdf/model/graph.rb:55:in `load'
from (irb):2

It appears that the rdf gem cannot find a reader/format, and tries to throw an error, but that is failing due to an undefined local variable called "content_type".

I put some debugging in, and determined that inside RDF::Reader#open, format_options is this:
{:base_uri=>#<RDF::URI:0x8097e32c(http://dbpedia.org/data/Elvis_Presley.ntriples)>, :content_type=>"text/rdf+n3", :file_name=>"http://dbpedia.org/data/Elvis_Presley.ntriples<http://dbpedia..org/data/Elvis_Presley.ntriples>"}

So I tried this next:

graph = RDF::Graph.load("http://dbpedia.org/data/Elvis_Presley.ntriples", :format=>:ntriples)

which gave this error:
RDF::FormatError: unknown RDF format: ntriples

Anyone know what the correct way to specify the format, or what I'm doing wrong here?

Thanks much!  Just getting started in rdf and was able to very quickly write an rdf storage adapter for couchdb thanks to your skeleton adapter project on github, so thanks for the awesome work on this gem!

Greg

Received on Thursday, 27 January 2011 22:50:55 UTC