1

I'm using GraphDB and the triple store is spatially indexed.

When I'm using this query, called Q1:

PREFIX geo-pos: <http://www.w3.org/2003/01/geo/wgs84_pos#> 
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> 
PREFIX omgeo: <http://www.ontotext.com/owlim/geo#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
select ?a ?lat ?long 
WHERE {
    ?a omgeo:within(22.92 -142.38 75.23 183.69) . 
    ?a geo-pos:lat ?lat . 
    ?a geo-pos:long ?long .

} limit 5000

It only takes less than a second, omgeo:within(22.92 -142.38 75.23 183.69) is using the spatial index of the triple store.

Also, when I use this query, called Q2:

PREFIX geo-pos: <http://www.w3.org/2003/01/geo/wgs84_pos#> 
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> 
PREFIX omgeo: <http://www.ontotext.com/owlim/geo#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
select ?a ?lat ?long 
WHERE {
    ?a a ?o .
    filter(?o = someclass) .
    ?a geo-pos:long ?long .

} limit 5000

or this query, called Q3:

PREFIX geo-pos: <http://www.w3.org/2003/01/geo/wgs84_pos#> 
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> 
PREFIX omgeo: <http://www.ontotext.com/owlim/geo#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
select ?a ?lat ?long 
WHERE {
    ?a a someclass .    
    ?a geo-pos:lat ?lat . 
    ?a geo-pos:long ?long .
} limit 5000

They return the same results and both take about 1 second.

But if I use this query, called Q4:

PREFIX geo-pos: <http://www.w3.org/2003/01/geo/wgs84_pos#> 
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> 
PREFIX omgeo: <http://www.ontotext.com/owlim/geo#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
select ?a ?lat ?long 
WHERE {
    ?a omgeo:within(22.92 -142.38 75.23 183.69) . 
    ?a a ?o .
    filter(?o = someclass) .
    ?a geo-pos:lat ?lat . 
    ?a geo-pos:long ?long .

} limit 5000

It takes more than 60 seconds. Do you know why this happens? Even if Q2 and Q3 returns 0 result, which means that the someclass I queried about has no instance, Q4 still takes more than 60 seconds. Is there a more efficient way to write Q4?

2
  • Although your earlier query seems to have run fast enough, filter (?var = ...) is always a little suspect. values ?var { ... } may be better, since it's conceptually saying "use these values of this variable" whereas the filter says "get a bunch of solutions and then remove ones that don't match".a good engine should optimize this filter, but it's one area to look into, at least. Commented Oct 8, 2015 at 12:11
  • @JoshuaTaylor I tried 'values ?var {...}', it's the same as Q4. I also tried using 'PREFIX geo-pos: <w3.org/2003/01/geo/wgs84_pos#> PREFIX geo: <w3.org/2003/01/geo/wgs84_pos#> PREFIX omgeo: <ontotext.com/owlim/geo#> PREFIX xsd: <w3.org/2001/XMLSchema#> select ?a ?lat ?long WHERE { ?a omgeo:within(22.92 -142.38 75.23 183.69) . ?a a someclass . ?a geo-pos:lat ?lat . ?a geo-pos:long ?long . } limit 5000' it also takes about 60 seconds, the same as Q4 Commented Oct 8, 2015 at 15:03

2 Answers 2

2

If a query like your first two runs sufficiently quickly, and your intent is just to filter down the results, a query like the one you've written should do it for you (as far as I can tell). However, you could also combine the queries by making one a subquery. This shouldn't make a difference, but it might help. I.e., you can do something like:

select ?a ?lat ?long {
  values ?o { <some-class> }
  ?a a ?o .
  { select ?a ?lat ?long  {
      ?a omgeo:within(22.92 -142.38 75.23 183.69) . 
      ?a geo-pos:lat ?lat . 
      ?a geo-pos:long ?long .
    } limit 5000 }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this one is much faster. It might have something to do with how the query is really implemented under the hood. Maybe graphdb knows how to fix it.
0
  1. Why not just use ?a a someclass ?
  2. Have you tried Explain Query? http://graphdb.ontotext.com/documentation/standard/explain-plan.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.