[ANN] Ruby-rdf

Hi folks,

I have put up an initial version of ruby-rdf. on Rubyforge.
http://rubyforge.org/projects/ruby-rdf/. I haven’t
released any files yet because I am still working out how to use Rake
and rubyforge but you should be able to download
from CVS.

ruby-rdf is a wrapper around the Redland RDF Application Framework.
http://www.redland.opensource.ac.uk/

This versions needs the installation of redland installed with ruby
support
./configure --with-ruby
make
make install

Here’s some examples from one of the unit tests

require 'test/unit’
require 'rdf’
require 'rdf/constants’
require ‘rdf/model’

class TestModel < Test::Unit::TestCase

def setup
@foaf = Namespace.new(‘http://xmlns.com/foaf/0.1/’)
@faa = Namespace.new(“http://www.faa.gov/faa#”)
end

def test_initialize()
model = Model.new()
assert_equal(0,model.size)
st =
Statement.new(Uri.new(“http://foo”),Uri.new(“http://bar”),“baz”)
st2 =
Statement.new(Uri.new(“http://xmlns/"),Uri.new(“http://name”),"bar”)
model.add_statement(st)
model.add_statement(st2)
assert_equal(2,model.size)
end

def test_api()
model = Model.new()

model.add_statement(Statement.new(@faa[‘dom@some.gov’],@foaf[‘name’],“Do
minic”))
model.add_statement
Statement.new(@faa[‘kris’],@foaf[‘firstName’],“Kris”)
model.add_statement
Statement.new(@faa[‘kris’],@foaf[‘phone’],“333-123-2387”)
model.add(@faa[‘kris’],@foaf[‘name’],“Kris Frame”)
model.add( Uri.new(‘dom’),Uri.new(‘project’),‘2334’)
domnode = model.subject(@foaf[‘name’],“Dominic”)
assert_equal(@faa[‘dom@some.gov’], domnode)

assert_equal(‘333-123
-2387’,model.object(@faa[‘kris’],@foaf[‘phone’]).to_s)
model.predicates(@faa[‘kris’],“Kris”){|p| puts p }
model.triples{|s,p,o| puts “subject: #{s}, pred: #{p}, object:
#{o}”}
model.find( nil,@foaf[‘name’],nil){|s,p,o| puts o }
serializer = Serializer.new()

serializer.to_file(‘out2.rdf’,model,Uri.new(“http://www.faa.gov/
people#”))
# serializer.namespace(@foaf,‘foaf’) # not working yet

end

def test_delete()
model = Model.new()
dom = BNode.new(‘dom’)
model.add(dom,@foaf[‘firstName’],‘Dominic’)
model.add(dom,@foaf[‘surname’],‘Sisneros’)
assert_equal(2,model.size)
st = Statement.new(dom,@foaf[‘firstName’],‘Dominic’)
assert(model.include?(st))
model.delete_statement(st)
assert(!model.include_statement?(st),“model should not include
statement”)
assert_equal(1,model.size)
model.delete(dom,@foaf[‘surname’],‘Bogus’)
assert_equal(1,model.size)
model.delete(dom,@foaf[‘surname’],‘Sisneros’)
assert_equal(0,model.size)
end

def testadd_statements(model)
dom = BNode.new(‘dom’)
kris = BNode.new(‘kris’)
model.add(dom,@foaf[‘firstName’],‘Dominic’)
model.add(dom,@foaf[‘surname’],‘Sisneros’)
model.add_statement Statement.new(kris,@foaf[‘firstName’],“Kris”)
model.add_statement
Statement.new(kris,@foaf[‘phone’],“425-227-2387”)
end

def test_delete()
model = Model.new
dom = BNode.new(‘dom’)
kris = BNode.new(‘kris’)
model.add(dom,@foaf[‘firstName’],‘Dominic’)
model.add(dom,@foaf[‘surname’],‘Sisneros’)
model.add_statement Statement.new(kris,@foaf[‘firstName’],“Kris”)
model.add_statement Statement.new(kris,@foaf[‘phone’],“192-192-192”)
assert_equal(4,model.size)
delete_statements = []
model.find(dom,nil,nil){|s,p,o| delete_statements <<
Statement.new(s,p,o)}
delete_statements.each{|st| model.delete_statement(st)}
assert_equal(2,model.size)
end

end

dominic sisneros wrote:

Hi folks,

I have put up an initial version of ruby-rdf. on Rubyforge.
http://rubyforge.org/projects/ruby-rdf/. I haven’t
released any files yet because I am still working out how to use Rake
and rubyforge but you should be able to download
from CVS.

ruby-rdf is a wrapper around the Redland RDF Application Framework.
http://www.redland.opensource.ac.uk/

There is also a Ruby-rdf project at
http://www.w3.org/2001/12/rubyrdf/intro.html

I believe it is no longer actively maintained (though he code is still
available), and has nothing to do with the ruby-rdf project on
RubyForge. But as they both use fairly generic names, confusion is easy.

Dominic: Would you consider wrapping the Redland RDF Ruby libs in a
namespace module, perhaps “Redland”, to prevent possible collisions with
other Ruby RDF lib authors that would want (quite reasonably) to call
their base file ‘rdf’?

The Ruby code for the Redland wrapper show the use of

require ‘rdf’

I would prefer to see

require ‘redland/rdf’

and have code use
@foaf = Redland::Namespace.new(‘FOAF Vocabulary Specification’)

or maybe
@foaf = Redland::RDF::Namespace.new(‘FOAF Vocabulary Specification’)

Or whatever is best for indicating that this is a particular RDF lib, or
a particular type of lib that works with Redland.

(In general, I tend to think that if a lib is not part of the standard
lib them it should have a distinguishing namespace module and clarifying
project name. But I’m aware of exceptions that seem reasonable, and I
know there’s been a thread on this before.)

Thanks,

James Britt

It seems to me that its rdf first, and a particular implementation
second. I’d tend to suggest rdf/redland over redland/rdf.

Cheers

Dave

···

On Mar 26, 2004, at 22:03, James Britt wrote:

The Ruby code for the Redland wrapper show the use of

require ‘rdf’

I would prefer to see

require ‘redland/rdf’

Dave Thomas wrote:

The Ruby code for the Redland wrapper show the use of

require ‘rdf’

I would prefer to see

require ‘redland/rdf’

It seems to me that its rdf first, and a particular implementation
second. I’d tend to suggest rdf/redland over redland/rdf.

That makes sense. Each section narrows the focus.

James

···

On Mar 26, 2004, at 22:03, James Britt wrote: