Monthly Archives: March 2011

SPARQL Algebra

For those intrepid enough, I’ve pushed version 0.0.2 of sparql-algebra. It relies on unreleased changes to RDF.rb and sxp-ruby, so you need to use bundler with the included Gemfile.

SPARQL Algebra implements the s-expression-based SPARQL algebra described in SPARQL 1.1 and Jena. Remaining work needed for _describe_ operator and query optimizations. This is the base for translation from SPARQL Grammar [4], which requires just a bit more work to be fully compliant. Both of these, along with support for an HTTP endpoint and solution serializer, will be sufficient to implement a complete SPARQL solution in pure Ruby.

SPARQL Algebra passes all but four W3C DAWG tests (data-r2), with those four not being worth implementing, in my opinion. As an example of an SSE based on the SPARQL grammar, consider the following:

PREFIX  foaf:  <>

SELECT ?mbox ?name
   ?x foaf:mbox ?mbox .
   OPTIONAL { ?x foaf:name  ?name } .

which is equivalent to the following SSE:

(prefix ((foaf: <>))
   (project (?mbox ?name)
       (bgp (triple ?x foaf:mbox ?mbox))
       (bgp (triple ?x foaf:name ?name)))))

There are outstanding pull requests to RDF.rb and sxp-ruby that are required to release it to RubyGems, but you’re encouraged to play with it and send feedback!

Thanks to Arto and Ben for the initial work they did on this, and other enabling projects, as well as creating an excellent executable test suite!


SPARQL::Grammar now complete, generating SPARQL::Algebra classes, allowing a complete end-to-end SPARQL solution for Ruby.