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