Re: How do I get RDF.rb to produce RDF collections in RDF/XML with a rdf:parseType="Collection" serialisation

On Aug 22, 2011, at 2:31 AM, Marcel Otto wrote:

Hi,

I've loaded a RDF/XML file with a collection (by
rdf:parseType="Collection") into a RDF.rb graph and looked at the
containing statement, consisting of equivalent rdf:first and rdf:rest
triples. If I write this graph back to a RDF/XML file, I get the proper
serialisation with rdf:parseType="Collection" back. But if I build it
manually, I only get a serialisation of the rdf:first and rdf:rest
triples back (not rdf:parseType="Collection" serialisation; note, that
writing the same graph to a N3 file, produces a nice serialisation with
parantheses).

Do you have an example? RDF/XML only serializes with parseType="Collection" unless any member is a literal. FYI, you can try this using http://rdf.greggkellogg.net/distiller/ by using the form input view, input type to "n3" or "ttl" and output type to "rdfxml".

Is there a way to get the RDF/XML writer to produce a rdf:parseType
serialisation with a manually built graph?

Certainly, try it with the following:

<> <#list> (<a> <b>) .

I am aware of the fact, that both serialisations are equivalent,
according to the RDF specification, but it looks so ugly, and given the
importance of collections for OWL, an OWL ontology becomes almost
unreadable.

By the way: I've also tried RDF::List, but this seems to be unusable
with RDF/XML, since if I try to write it, I get a "RDF::WriterError:
Attempt to serialize #<RDF::List...>, not supported in RDF/XML".

You can use RDF::List to create a set of statements that can generate statements, but this is not directly supported by the various writers. As a convenience, when programming, you might try the following:

g = RDF::Graph.new
l = RDF::List[RDF::FOAF.Document, RDF::FOAF.Person]
g << [RDF::URI("http://example.com/class"), RDF::OWL.unionOf, l.subject]
l.each_statement {|st| g << st}

As is, you cannot simply add a triple containing a List and expect it to expand automatically. It's not a bad idea, but it would complicate the processing. You might file a feature request at http://github.com/bendiken/rdf, although Arto hasn't been taking a very active interest in the gem for a while.

Thanks in advance
Marcel

Gregg

Received on Monday, 22 August 2011 20:45:31 UTC