SPARQL is now (April 2006) a W3C Candidate Recommendation which means it is stable enough for wide spread implementation. Actually, there are quite a few implementations already (SPARQL implementations page on ESW wiki).
SPARQL is defined by three documents:
and there are tutorials like this one.
RDQL predates SPARQL - in fact, RDQL design predates the current RDF specifications and some of the design decisions in RDQL are a reflection of that. The biggest of these is that RDF didn't have any datatyping so RDQL handles tests on, say, integers without checking the datatype (if it looks like an integer, it can be tested as integer).
SPARQL has all the features of RDQL and more:
- ability to add optional information to query results
- disjunction of graph patterns
- more expression testing (date-time support, for example)
- named graphs
but, above all, it is more tightly specified so queries in one implementation should behave the same in all other implementations.
ARQ - A Query Engine for Jena
ARQ builds on top of the existing Jena query support for matching of basic graph patterns (BGPs are the building block in SPARQL). ARQ can execute SPARQL and RDQL as well as an extended form of SPARQL. It has several extension points, such as Property functions. The ARQ query engine works with any Jena Graph or Model.
Converting RDQL code to SPARQL code
The functionality of RDQL is a subset of SPARQL so it's not hard to convert RDQL queries to SPARQL. What needs to be done is convert the triple syntax and convert any constraints.
SPARQL syntax uses a Turtle-like syntax which is familiar to anyone knowing N3.
Namespaces go at the start of the query, not after like
USING. There are no
() around triple
patterns; instaead there is a "
." (a single dot)
between triple patterns. An RDQL only ever has one graph pattern,
in SPARQL, blocks of triple patterns are
You can even use the command line
arq.qparse to read in an
RDQL query and write out the SPARQL query but it's a rough approximation
you'll need to check and it may not be completely legal SPARQL.
The constraints need the most care because SPARQL uses RDF datatyping and RDQL doesn't. Some common areas are:
- regular expressions
- string equality and numeric equality
A SPARQL regular expression looks like:
regex(expr, "pattern") regex(expr, "pattern", "i")
The catch is that the
expr must be a literal; it can't be a URI.
(Well - it can, but it will never match!). If you want to perform a regular
expression match on a URI, use the
str() built-in to get the string form of the URI.
= for numeric equality and
string equality. A number in RDQL was anything that can be parsed an a number, whether
it had a datatype or not (or even the wrong datatype). Likewise, anything could be
treated as a string (like URIs in regular expressions).
= which is taken from
XQuery/XPath Functions and Operators. It decides whether that is numeric equals,
string equals or URI-equals based on the kind of arguments it is given.
The ARQ API is in the package
com.hp.hpl.jena.query. The RDQL API
is deprecated, starting with Jena 2.4. The new API
is similar in style to the old one for
SELECT, with iteration over
the rows of the results (javadoc).
Differences include the widespread use of factories, naming consistent with the
SPARQL specifications, and different
exec operations for the
different kinds of SPARQL query.
QueryExecution objects should be
One change is that to get the triples that matched a query, instead of asking the binding for the triples
that were used in the matching, the application should now make a
Experimenting with SPARQL
There is a set of command line utilities to try out SPARQL queries from the command line.
A nice graphical interface is twinkle by Leigh Dodds.
Send question and comments about ARQ to jena-dev.
If you have experiences converting from RDQL to SPARQL, then let me know and I'll compile a list of common issues.