ruby-rdf / rdf-rdfxml

Ruby RDF/XML reader/writer for RDF.rb.
http://rubygems.org/gems/rdf-rdfxml
The Unlicense
17 stars 7 forks source link

Odd Error while testing gem #4

Closed mistergibson closed 13 years ago

mistergibson commented 13 years ago

Hello.

I was attempting to follow your example and encountered an error while testing. Code and Error follows:

RDF::RDFXML::Reader.open($datafile_path) do |reader| reader.each_statement do |statement| puts statement.inspect end end

NameError: undefined local variable or method content_type' for RDF::RDFXML::Reader:Class from /usr/lib/ruby/gems/1.8/gems/rdf-0.3.1/lib/rdf/reader.rb:125:inopen' from /usr/lib/ruby/1.8/open-uri.rb:32:in open_uri_original_open' from /usr/lib/ruby/1.8/open-uri.rb:32:inopen' from /usr/lib/ruby/gems/1.8/gems/rdf-0.3.1/lib/rdf/util/file.rb:28:in open_file' from /usr/lib/ruby/gems/1.8/gems/rdf-0.3.1/lib/rdf/reader.rb:117:inopen' from (irb):2

Any idea why I would be getting this error? Thanks in advance.

gkellogg commented 13 years ago

It's a bug in RDF.rb, which should be updated shortly.

mistergibson commented 13 years ago

I noticed your pull request, thanks for the upstream effort. I'm using 0.3.1 of rdf.rb and am not sure when the gem will be updated. As I really need this working - could you post a comment here when the corrections are incorporated? I can then do a pull if the gem isn't updated in time.

Thanks in Advance, and thanks for the prompt reply. :)

gkellogg commented 13 years ago

Arto should get it out shortly, there are couple of other things to go in.

You could always clone my fork in the mean time.

mistergibson commented 13 years ago

Actually I got the same error with your forked version.

gkellogg commented 13 years ago

The specs pass for me using that version of the gem, and I did try that example specifically, and it seems to work as advertised.

Can you provide some detail: what version of Ruby are you running?

Can you provide a test case and the error results you're seeing?

mistergibson commented 13 years ago

I am running Ruby 1.8.7-249-i486-Linux.

And ... actually the above code is all I've tried with identical results, no specific test cases beyond that.

gkellogg commented 13 years ago

What is the value of $datafile. The error and line number generated is exactly the same?

The patch generated is in the reader-content_type branch, so you may have neglected to switch to that branch before installing.

From the gem directory, try the following:

RDF::RDFXML::Reader.open("etc/doap.xml") {|r| puts r}

Please send the result of this output.

mistergibson commented 13 years ago

RDF::RDFXML::Reader.open("/var/lib/gems/1.8/gems/rdf-rdfxml-0.3.0/etc/doap.xml") {|r| puts r}

yields: #RDF::RDFXML::Reader:0xb69cf368 ... so that's perfect. Which led me to the next logical question - what is different about my files? Well, for one thing the files I'm working with don't typically use the rdf:RDF tag, but simply an RDF tag. When I correct that to something closer to your sample file and try:

RDF::RDFXML::Reader.open("odp_rdfxml.sample") {|r| puts r}

I get: /usr/lib/ruby/gems/1.8/gems/rdf-0.3.1/lib/rdf/reader.rb:125:in open':NameError: undefined local variable or methodcontent_type' for RDF::RDFXML::Reader:Class

I'm thinking at this point that it does not properly get the dtd info to define the resource types properly. Here is a dump of the odp_rdfxml.sample file:

<?xml version="1.0" encoding="UTF-8"?>

< Topic r:id="" > 1 /d:Title 2010-08-17 09:14:22 /d:Description < /Topic > < Topic r:id="Top" > 2 Top/d:Title 2010-08-16 06:05:15 /d:Description < /Topic > /rdf:RDF
gkellogg commented 13 years ago

It really looks to me like you're not using the reader-content_type branch of my fork, that has this change. The good news is that Arto has finally released his dydra project (http://dydra.com) and said he'd get a release of RDF.rb incorporating this change out today or tomorrow.

mistergibson commented 13 years ago

ok ... sorry - finally got the branch you sited installed. It did solve the first error, but I got this one now :

/usr/lib/ruby/gems/1.8/gems/rdf-0.3.1/lib/rdf/reader.rb:125:in `open':RDF::FormatError: unknown RDF format: file_nameodp_rdfxml.sample.inspect}

code and sample file being the same. Do you see anything glaring about the afore posted sample file?

gkellogg commented 13 years ago

It looks like you might have a bad path in your variable. Try the following in irb:

require 'rdf/rdfxml'
RDF::RDFXML::Reader.open("http://www.w3.org/2000/10/rdf-tests/rdfcore/Manifest.rdf") {|r| puts r}

You should be able to do the following, as well:

require 'linkeddata'
RDF::Graph.load("http://www.w3.org/2000/10/rdf-tests/rdfcore/Manifest.rdf").dump(:ntriples)
mistergibson commented 13 years ago

OK, the error is because it was using the filename extension as its content type detector. I renamed the sample file to end in .xml and it finally gave me a spiffy Reader object. Thanks for all your help with this issue. :)