Samizdat: Co-op Engine

Home | About | Documentation | Developers | Download

Graffiti 1.0 (2010-03-14)

Graffiti is an RDF store based on dynamic translation of RDF queries into SQL. Graffiti allows to map any relational database schema into RDF semantics and vice versa, to store any RDF data in a relational database. Since 2003, this RDF store was used as the primary means of data access in the Samizdat open publishing engine, and now it's released as a stand-alone module ready for use in other applications.



Graffiti uses Ruby/DBI to connect to database backend and provides a DBI-like interface to run RDF queries in Squish query language from Ruby applications. SynCache object cache is used for in-process cache of translated Squish queries.


  require 'dbi'
  require 'yaml'
  require 'graffiti'

  db = DBI.connect(dsn, user, password)
  config ='rdf.yaml') {|f| YAML.load( }
  store =, config)

    SELECT ?date, ?title
    WHERE (dc::date ?r ?date FILTER ?date >= :start)
          (dc::title ?r ?title)
    ORDER BY ?date DESC}, 10, 0, :start => - 24*3600)

Query Language

Graffiti implements Squish RDF query language with several extensions. A query may include following clauses:

A basic update language is also implemented. A Squish assert statement uses the same structure as a query, with SELECT clause replaced by either one or both of the following clauses:

Assert statement will only update one solution per invocation, if more solutions match the graph pattern, only the first will be updated.

Relational Data

Relational data has to be adapted for RDF access using Graffiti. The adaptation is non-intrusive and will not break compatibility with existing SQL queries.

Following schema changes are required for all cases:

Following changes may be necessary to support optional RDF mapping features:

Example of RDF map and corresponding triggers can be found in doc/examples/.