After the Pain-in-the-a** issue of yesterday. I’ll try to be more practical today with a gentle introduction to ActiveRDF.
First, install it. You need Ruby and Ruby Gems (it’s just like the Pythonic eggs).
gem install activerdf gem install activerdf_rdflite gem install sqlite3-ruby
Now, pick up a RDF Schema somewhere (sucked from there) convert it into NTriples (with rapper).
Now create some datas.
<?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:foaf="http://xmlns.org/foaf/0.1/" xmlns:simple="http://yoan.dosimple.ch/beta/simple.rdfs#" xml:base="http://yoan.dosimple.ch/beta/simple.rdf#"> <simple:Teacher rdf:ID="professor"> <simple:name>Professor</simple:name> </simple:Teacher> <simple:Course rdf:ID="rdf"> <simple:name>RDF and RDF Schema</simple:name> <simple:teacher rdf:resource="#professor" /> <simple:students> <rdf:Seq> <rdf:li rdf:resource="#yoan" /> <rdf:li rdf:resource="#batiste" /> </rdf:Seq> </simple:students> </simple:Course> <simple:Student rdf:ID="yoan"> <simple:name>Yoan Blanc</simple:name> <foaf:weblog>http://yoan.dosimle.ch/blog/ </foaf:weblog> <foaf:know rdf:resource="#batiste" /> </simple:Student> <simple:Student rdf:ID="batiste"> <simple:name>Batiste Bieler</simple:name> <foaf:weblog>http://batiste.dosimle.ch/blog/ </foaf:weblog> <foaf:know rdf:resource="#yoan" /> </simple:Student> </rdf:RDF>
And do a Triple with it. The RDF Validator and Converter can help you.
So we can start.
$ irb
We are into the interactive ruby shell.
require 'active_rdf'
ActiveRDF is loaded
pool = ConnectionPool.add_data_source :type => :rdflite, \ :location=> 'database.db', :keyword=>true
There is our pool, you can change to :redland
if you prefer.
pool.load 'schema.nt' pool.load 'data.nt'
Then our datas are loaded, in NTriple format, not RDF/XML.
Namespace.register :simple 'http://yoan.dosimple.ch/test/simple.rdfs#' ObjectManager.construct_classes
Register our namespace (you’ll understand) and build the classes, like ActiveRecord do.
SIMPLE::Person.find_by_name("Professor")
Get a person.
SIMPLE::Person.find_by_name("Yoan Blanc").weblog
Yeah, we’ve got it. Of course, I helped myself with this article : “Getting Started Guide” from the ActiveRDF wiki.
Next step is to do some queries, it’s not very trivial, some I need some time to achieve this...