Let’s start with the Query API of ActiveRDF that match SPARQL. If you don’t understand a word, start reading the related entries or drop me a mail.
First of everything, the model (rdfs). I’ve made a little UML schema to help you. RDF Schema is similar to UML, but it’s a graph.
There is:
- a
Person
- with a
name
- a
Student
- who is a
Person
- a
Teacher
- who is a
Person
too - a
Course
- with a
name
, oneTeacher
and zero or moreStudent
s
The cardinality cannot be achieved with RDF Schema, OWL is the right (but not the only) way to put cardinality on a schema.
Now the data, a nice graph with two students, a professor and a course :
Our first query gonna be very trivial. (Already done by ActiveRDF in fact)
Namespace.register :simples, \ 'http://yoan.dosimple.ch/beta/simple.rdfs#' # rdf:type and simples:Teacher type = Namespace.lookup(:rdf,:type) teacher = Namespace.lookup(:simples, :Teacher) # the same than: SIMPLES::Teacher.find_all puts Query.new.distinct(:name) \ .where(:name, type, teacher) \ .execute # output: #<http://yoan.dosimple.ch/beta/simple.rdf#professor>
Find every teacher. Now we gonna try to find the students’ name :
# simples:Student and simples:name student = Namespace.lookup(:simples, :Student) name = Namespace.lookup(:simples, :name) puts Query.new.distinct(:name) \ .where(:s, type, student) \ .where(:s, name, :name) \ .execute # output: #Yoan Blanc #Batiste Bieler
So easy ! Next, a bigger query on the whole graph!
# simples:teacher, simples:students teach = Namespace.lookup(:simples, :teacher) study = Namespace.lookup(:simples, :student) puts Query.new.distinct(:cname, :tname). \ where(:s, name, "Yoan Blanc"). \ where(:c, study, :s). \ where(:c, name, :cname). \ where(:c, teach, :t). \ where(:t, name, :tname). \ execute # output: #RDF and RDF Schema #Professor’s name
Find every courses of the student called “Yoan Blanc” and return the name of the course and the teacher’s name of them.
Next step of that is to build a Web Application that use a Semantic Database as backend. I wanna play with FOAF (for the social part), SKOS (for the tagging) and maybe a homemade RDF Schema inspired by Annotea. Sounds like the first web 2.0 application I’ve met years ago. Keep it touch.