W3C home > Mailing lists > Public > public-sparql-dev@w3.org > July to September 2006

RE: Assigning values to variables

From: Seaborne, Andy <andy.seaborne@hp.com>
Date: Wed, 23 Aug 2006 16:10:30 +0100
Message-ID: <86FE9B2B91ADD04095335314BE6906E854D821@sdcexc04.emea.cpqcorp.net>
To: "Luke Steller" <Luke.Steller@infotech.monash.edu.au>
Cc: <public-sparql-dev@w3.org>




-------- Original Message --------
> From: Steve Harris <>
> Date: 23 August 2006 12:00
> 
> On Wed, Aug 23, 2006 at 08:46:29 +1000, Luke Steller wrote:
> > 
> > Hi All,
> > 
> > Is it possible to assign a value to a variable, apart from using
> > pattern matching? More specifically, for instance is it possible to
> > assign a literal - say a double returned by a function (custom
> > function) to a variable, which in turn is returned by the query. For
> > me it would be useful to have a query like:
> > 
> > PREFIX myfn: <java:com.luke.distance.> PREFIX ps: <http://luke#>
> > PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> > PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
> > SELECT ?printer ?distance
> > WHERE
> > {
> >    ?printer rdf:type ps:InkJetPrinterOperational.
> >    ?distance = myfn:LatLongDistance("-38.15291", "145.135775",
> > "-38.152197", "154.135783", "K") }
> > 
> > which returns the printer individual URI and the distance (a
double).
> > 
> > 
> > Is anything like this possible?
> 
> An alternative would be SELECT expressions, but those aren't in the
spec
> either:
> 
> PREFIX myfn: <java:com.luke.distance.>
> PREFIX ps: <http://luke#>
> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
> SELECT ?printer, myfn:LatLongDistance("-38.15291", "145.135775",
>    "-38.152197", "154.135783", "K") WHERE { ?printer rdf:type
> ps:InkJetPrinterOperational. }

SPARQL comment : it would be better with a name as well because results
are serialized in XML (and JSON) using the variable name.  A string such
as "myfn:LatLongDistance(...)" could be used but it's rather hard to
retrieve it again, being potentially space sensitive.

Personally, I'd prefer to add a proper assignment.

> 
> Some engines (including Jena I think) support predicate functions,
ala:
> 
> PREFIX myfn: <java:com.luke.distance.>
> PREFIX ps: <http://luke#>
> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
> SELECT ?printer ?distance
> WHERE
> {
>    ?printer rdf:type ps:InkJetPrinterOperational.
>    ?distance myfn:LatLongDistance [
> 	myfn:lat1 -38.15291;
>         myfn:long1 145.135775;
>         myfn:lat2 -38.152197;
> 	myfn:long2 154.135783;
> 	myfn:thing "K";
>     ]
> }
> 
> Or something similar.

Property functions in ARQ now (ARQ 1.4) support lists for subject and/or
object:

   ?distance myfn:LatLongDistance (
             -38.15291
             145.135775
             -38.152197
             154.135783
             "K" )

[those numbers are xsd:decimals, not doubles by the way, add "e0" to
make them doubles]

	Andy

> 
> - Steve
Received on Wednesday, 23 August 2006 15:10:46 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 8 January 2008 14:17:05 GMT