W3C home > Mailing lists > Public > semantic-web@w3.org > June 2012

Re: Template language for SPARQL?

From: Ivan Mikhailov <imikhailov@openlinksw.com>
Date: Sat, 09 Jun 2012 11:53:31 +0700
To: David Booth <david@dbooth.org>
Cc: semantic-web <semantic-web@w3.org>
Message-ID: <1339217611.21322.29.camel@octo.iv.dev.null>
Hello David,

On Thu, 2012-05-31 at 21:45 -0400, David Booth wrote:
> [Resending, as my previous message never showed up.]
> I would like to be able to write something like this:
>   SELECT ?s
>   WHERE { ?s a ${CLASS} . }
> and have ${CLASS} substituted in from an environment variable or other
> parameter, but SPARQL does not currently provide anything like this, and
> it's clearly beyond what the working group could put in SPARQL 1.1.  
> So I'm wondering . . . 
> What have others been using as a template language for SPARQL?  
> I know TopQuadrant uses an RDF representation for SPARQL CONSTRUCT
> queries in conjunction with SPIN, 
> http://www.w3.org/Submission/2011/02/ 
> but it shreds the SPARQL query into tiny RDF pieces, which is rather
> unfriendly for a human to read.  It would be much nicer to have
> something like the above.
> How are others handling the need to parameterize their SPARQL queries
> like this?

OpenLink Virtuoso allows SPARQL in any place where a plain SQL query is
allowed, i.e. in stored procedures, in XSLT, in SQL queries (as SPARQL
subqueries), in requests via any protocols like ODBC. So we've extended
syntax for variables:

?:varname is variable with name "varname" in the calling context (SQL
variables of stored procedure, XSLT variables of the template where
<xsl:for-each-row sparql="..."> is called)

?::paramname is for named parameters of ODBC etc., i.e. for parameters
that are accessible from plain SQL as :paramname.
BTW we've extended SPARQL protocol as well so if parameter name starts
with '?' then it is available in the SPARQL. Say, &%
3Fparamname=paramvalue in the URL of SPARQL request makes it possible to
use ?::paramname in the text of the query.

?? and ?:0, ?:1, ?:2, ... are positional parameters of ODBC or similar
calling context.

This feature, combined with ability of calling SQL procedures in FILTERs
and the like, reduce the need for inlining values into the query. And
we're not limited with SPARQL only, so if one had to compose the text of
the query, he can make it in SQL stored procedure with comfort, then
execute. E.g. right now I've added a serialization format for SPARQL
result sets so the result set is printed as BINDINGS ... { ... } clause,
ready to paste into some other query.

Best Regards,

Ivan Mikhailov
OpenLink Software
Received on Saturday, 9 June 2012 04:53:59 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 19:48:37 UTC