rdf-n3 gem released

I just released version 0.0.2 of the rdf-n3 gem available from RubyGems<http://rubygems.org/gems/rdf-n3> and GitHub<http://github.com/gkellogg/rdf-n3>. It's marked as an early release, but it's pretty fully featured. Both are based on compliant parser/serializer from the rdf_context gem. Gems for rdf-rdfxml and rdf-rdfa have previously been released.

Most, but not all SWAP, CWM and Turtle W3C tests pass for the reader. Some issues remain that need to be resolved in RDF.rb; most of them are handled through patches within this gem to support canonicalization of literals, qname lookup optimizations and URI normalization. I'm working to resolve these issues within RDF.rb. Other issues more specific to N3 (literals as subjects, BNodes as predicates) need further resolution.

Note that the N3 reader is an N3-rdf level, meaning that it does not support rules and formulae ({?x} => {?x} and {} @forAll); requirements for this are not well specified. Full UTF-8 literal support currently requires ruby 1.9. Anyone interested in furthering the developement to support of full N3 is encouraged to fork the repo and participate!

The writer produces Turtle with Anonymous nodes defined recursively, as much as possible (this can be controlled through an option). Also, namespaces other than the standard must be defined within code to be used in serialization; this is a basic constraint of RDF.rb. For instance, to cause the Music Ontology namespace to be used within a serializer as a prefix, define a vocabulary class as follows:

class MO < RDF::Vocabulary(http://purl.org/ontology/mo/); end

This will add the mo: prefix and use it for serialization. I believe that the RDF graph will ultimately need to support namespace definitions created during parsing to support features in the RDFa API (see http://www.w3.org/TR/2010/WD-rdfa-api-20100608/#data-context setMapping for example), but for now classes need to be define to cause prefixes to be generated.

Reading and Writing is pretty much the same as for other RDF.rb style readers and writers:

require 'rdf/n3'

RDF::N3::Reader.open("etc/foaf.n3") do |reader|
  reader.each_statement do |statement|
    puts statement.inspect
  end
end

RDF::N3::Writer.open("etc/test.n3") do |writer|
  writer << graph
end

The gem depends principally on the Treetop gem for parsing, in addition to rdf.

"gem install rdf-n3" should do the trick.

Gregg

Received on Thursday, 24 June 2010 23:54:08 UTC