Inkling Squish-to-SQL query rewriter

This tool takes a Squish query and transforms it into an SQL query targeted at a certain style of RDF database implemented in SQL. It was written by Libby Miller <libby.miller@bristol.ac.uk> based on a PHP version by Matt Biddulph <matt@picdiary.com>. See the how it works document for internal details.

Nearby in the Web

Some other RDF query tools, either systems that can consume Squish or Squish-ish syntax, or that help with building Squish2SQL-based applications.

Quick Start

To get started really fast on machine with Java installed:

Troubleshooting: there is no good formal spec for Squish yet, and the Java parser has some issues. Try tweaking your query slightly.

Java class dependencies

The rewriter is implemented in Squish2SQL.java and uses org.desire.rudolf.query.ParsedQuery to represent the Squish query, along with some helper classes. Squish2SQL was part of the Inkling class hierarchy but is currently given an unqualified name. See the Makefile for commandline example usage.

It should have pretty minimalistic dependencies, since it basically performs a text format conversion. The current version depends on PostgreSQL's JDBC libraries (pgjdbc2.jar) since it can perform search, in addition to converting between query syntaxes. The remaining dependencies are documented below.

Required Inkling classes

Classpath and JARs

So basically you need Inkling on your classpath, plus the PostgreSQL JDBC classes. For a minimalist install, especially if you don't intend to do any actual database querying, ie. just run this as a text file, you don't need anything except the rewrite-helpers.jar JAR file. This includes only the 4 Inkling classes needed (plus their .java src).

Standalone jar usage: java -cp jars/rewrite-helpers.jar Squish2SQL squish-filename

Example Usage

cat sql/test1.squish

   SELECT  ?thumb, ?name, ?mbox 
   WHERE 
     (foaf::depiction ?x ?uri) 
     (foaf::depiction ?z ?uri) 
     (foaf::mbox ?x mailto:libby.miller@bristol.ac.uk) 
     (foaf::mbox ?z ?mbox) 
     (foaf::name ?z ?name) 
     (foaf::thumbnail ?uri ?thumb) 
     (dc::description ?uri ?dd)  
   USING 
     foaf for http://xmlns.com/foaf/0.1/  
     dc for http://purl.org/dc/elements/1.1/


java -cp jars/rewrite-helpers.jar Squish2SQL sql/test1.squish
 
   SELECT DISTINCT 
    b2.value AS mbox, b5.value AS thumb, b7.value AS name  
   FROM   
    triples a1,  triples a2,  triples a3,  triples a4,
    triples a5,  triples a6,  triples a7,  
    resources b2,  resources b5,  resources b7  
   WHERE a1.predicate = '116868652'  
   AND   a2.predicate = '116868652'  
   AND a3.predicate = '1547507681'  
   AND    a3.object = '1145937192'  
   AND a4.predicate = '1547507681'  
   AND    a5.predicate = '1577895888'  
   AND a6.predicate = '-1848367484' 
   AND a7.predicate = '-221079518'  
   AND a1.subject=a3.subject   
   AND a1.object=a2.object  
   AND a2.object=a6.subject  
   AND a6.subject=a7.subject  
   AND a2.subject=a4.subject  
   AND a4.subject=a5.subject  
   AND b2.key=a4.object  
   AND b5.key=a6.object  
   AND b7.key=a5.object ;

Appending 'search dbname' will result in it attempting to actually do the query against a localhost PostgreSQL database called 'dbname'. Piping the output into 'psql dbname' can be used to similar effect, if you have the PostgreSQL client tool installed.

Availability

The required class libraries from Inkling have been packaged as .jar files: jars/rdfquery.jar (the normal Inkling distribution) or just the three classes we need: jars/rewrite-helpers.jar.

Hmm, should probably bundle the revised rewriter (Squish2SQL, previously PQ2SQL.java) in there too.

Notes

These rough notes made by Dan in advance of attempting a Ruby port.

danbri@rdfweb.org