Friday, June 3, 2011

Two ways to Query Linked Data with ARQ

ARQ provides two ways to query Linked Data, i.e. remote SPARQL Endpoints.  The first one us to use the "sparqlService" method on the QueryExecutionFactory. 


QueryExecution qe = QueryExecutionFactory.sparqlService("", query);

The other way can be done with a QueryExecutionFactory that is also attached to a Jena Model, however you specifcy the "service" in the SPARQL directly.


QueryExecution qe =  QueryExecutionFactory.create(query,model);

    SERVICE <> {
        ?s ?p <>

Enjoy traversing the linked data!


  1. There is a slight difference between the two: the first lets you do arbitrary SPARQL and the second only basic graph patterns are sent to the end point ( no solution modifiers DISTINCT, ORDER BY, LIMIT etc. ; although these can be done on the outer query locally ).

  2. Hi Tim - thanks, I omitted those details. The local/remote processing dichotomy is definitely something that makes the transition of SQL developers to SPARQL developers more challenging. For Groovy SPARQL, I wound up adding the support to initialize off of a Jena Model for this very reason.

    The Groovy SPARQL also uses Syntax.syntaxARQ to get things like COUNT and other Jena specifics that might not be widely adopted - but are definitely useful for those working with a fully compatible Jena triple store.