[redland-dev] query range in SPARQL
Andre Meyer
meyer at acm.org
Thu Oct 5 10:21:41 UTC 2006
Wow, that's wonderful! The devil's in the details...
In order to find the neighbours within a given distance I added the
FILTER as follows:
x0 = 50
y0 = 50
d = 25
q = RDF.SPARQLQuery("""PREFIX di: <http://python.openspace.nl/di#>
SELECT ?s ?x ?y
WHERE
{ ?s di:x ?x ;
di:y ?y .
FILTER ((?x-%s)*(?x-%s) + (?y-%s)*(?y-%s) < %s*%s) .
}""" % (x0, x0, y0, y0, d, d))
thanks!
Andre
On 10/5/06, Seaborne, Andy <andy.seaborne at hp.com> wrote:
>
> The query has:
>
> { (?s di:x ?x) . (?s di:y ?y) . }
>
> but in SPARQL triple patterns aren't delimited by (). Unfortunately, in
> SPARQL, () are RDF lists and your query really looks like:
>
>
> PREFIX di: <http://python.openspace.nl/di#>
> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> # Added for
> clarity
>
> SELECT ?s ?x ?y
> WHERE
> { _:b0 rdf:first ?s ;
> rdf:rest _:b1 .
> _:b1 rdf:first di:x ;
> rdf:rest _:b2 .
> _:b2 rdf:first ?x ;
> rdf:rest rdf:nil .
> _:b3 rdf:first ?s ;
> rdf:rest _:b4 .
> _:b4 rdf:first di:y ;
> rdf:rest _:b5 .
> _:b5 rdf:first ?y ;
> rdf:rest rdf:nil .
> }
>
> which may not be what you intended.
>
> If the () are removed, then the query is:
>
> PREFIX di: <http://python.openspace.nl/di#>
>
> SELECT ?s ?x ?y
> WHERE
> { ?s di:x ?x ;
> di:y ?y .
> }
>
> http://www.sparql.org/validator.html
>
> Andy
>
> -------- Original Message --------
> > From: Andre Meyer <>
> > Date: 4 October 2006 19:25
> >
> > That's a good one!!! Hope this works for all kinds of functions one
> > might want to use.
> >
> > Nevertheless, I still can't manage to query properly. Trying to use
> the
> > Python example I got the attached file, which finds nothing, with or
> > without filter.
> >
> > thanks
> > Andre
>
--
Dr. Andre P. Meyer http://python.openspace.nl/meyer
TNO Defence, Security and Safety http://www.tno.nl/
Delft Cooperation on Intelligent Systems http://www.decis.nl/
Ah, this is obviously some strange usage of the word 'safe' that I
wasn't previously aware of. - Douglas Adams
More information about the redland-dev
mailing list