Closed njh closed 13 years ago
Not seing the problem in 0.3.0. However, I'm going to write a number of round-trip specs to ensure that the generated RDF/XML parses back to the original triples.
Note, in 0.3.0, you can specify prefixes to bind when invoking the writer, or you can have it use all built-in vocabularies with the :standard_prefixes option. Also, you can take the prefixes found when reading and re-bind them to the writer to transform between different serialization formats but retain the same namespace bindings.
Having different problems with rdf 0.3.0 and rdf-rdfxml 0.2.3:
can't modify frozen object
/Library/Ruby/Gems/1.8/gems/rdf-rdfxml-0.2.3/lib/rdf/rdfxml/patches/qname_hacks.rb:16:in `vocab='
/Library/Ruby/Gems/1.8/gems/rdf-rdfxml-0.2.3/lib/rdf/rdfxml/patches/qname_hacks.rb:35:in `[]'
/Library/Ruby/Gems/1.8/gems/rdf-0.3.0/lib/rdf/vocab.rb:195:in `method_missing'
Known problem resolved in 0.3.0. You can try running from the GitHub source until I release the 0.3.0 gem to RubyGems, which should be later today.
Working fine with the new 0.3.0 set of gems. Thanks!
Do you have an example of using the :standard_prefixes option to restore the old behaviour?
This is the syntax that I was using before, but unfortunately it does not take an options parameter.
$ irb -rrdf/rdfxml
>> graph = RDF::Graph.new {|g| g << [RDF::URI('http://example.com/joe'), RDF::FOAF.name, "Joe Bloggs"]}
=> #<RDF::Graph:0x81013638(<>)>
>> graph.dump(:rdfxml)
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:ns0=\"http://xmlns.com/foaf/0.1/\">\n <rdf:Description rdf:about=\"http://example.com/joe\">\n <ns0:name>Joe Bloggs</ns0:name>\n </rdf:Description>\n</rdf:RDF>\n"
I haven't used Graph#dump, and this gem is slightly more difficult to work with than RdfContext with respect to simply output like this. Graph#dump could probably be re-factored. File a bug against RDF on Enumerable#dump and Writer.dump that they should allow options to be passed to the writer, then you could do something like the following:
graph.dump(:rdfxml, :standard_prefixes => true)
In the mean time, a function such as the following should work:
class RDF::Graph
def to_rdfxml(options = {})
RDF::Writer.for(:rdfxml).buffer(options) do |writer|
writer << self
end
end
end
graph = RDF::Graph.new {|g| g << [RDF::URI('http://example.com/joe'), RDF::FOAF.name, "Joe Bloggs"]}
graph.to_rdfxml(:standard_prefixes => true)
Thank you very much for your help. I have created this issue: https://github.com/bendiken/rdf/issues/71
The thing that was confusing me was that in rdf.rb version 0.3.0, the options argument is being ignored in RDF::Writer.dump().
I am seeing a number of xmlns:ns0="RDF::Vocabulary" declarations in the RDF::XML I am generating, example: http://dbpedialite.org/things/934787.rdf
I am using rdf-rdfxml version 0.2.3.