Rena: A Library for RDF and the Semantic Web

Rena is a new library for working with RDF that seems to be a Ruby port of the popular Jena semantic web framework for Java. As noted by the author, it’s still in the “experimental” stage but already shows some promise.

As with Jena, the basic object model parallels the RDF model. Rena has not yet adopted Jena 2.0′s factory-based approach to creating model instances, so you instead just instantiate the desired model class directly. For example, here’s how to create an in-memory model, add a resource and define some properties for it:

require 'rena' require 'rena/dc'

docURI = “http://www.fxruby.org/doc” docTitle = “FXRuby User’s Guide” docDate = “2004-10-24″

Create an empty Model

model = Rena::MemModel.new

Create the resource

myDoc = model.create_resource(docURI)

Add some properties

myDoc.addproperty(Rena::DC::Title, Rena::PlainLiteral.new(docTitle)) myDoc.addproperty(Rena::DC::Date, Rena::PlainLiteral.new(docDate))

Dump

model.save(STDOUT, :content_type => ‘application/rdf+xml’)

Here, we’re taking advantage of the built-in support for some of the Dublin Core elements. The output of that final call to MemModel#save is the RDF/XML serialization of this model:
<?xml version='1.0'?>
<rdf:RDF xmlns:ns0='http://purl.org/dc/elements/1.1/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>

<rdf:Description ns0:title='FXRuby User's Guide' ns0:date='2004-10-24' rdf:about='http://www.fxruby.org/doc'/> </rdf:RDF>

I haven’t gotten around to trying out the parsing or querying support yet, but it looks like the author’s goal is to more or less emulate what’s being done with Jena. Hopefully this one will progess quickly.

Posted July 15th, 2004 in Ruby, Semantic Web.

Comments are closed.