ad-freiburg / qlever

Very fast SPARQL Engine, which can handle very large knowledge graphs like the complete Wikidata, offers context-sensitive autocompletion for SPARQL queries, and allows combination with text search. It's faster than engines like Blazegraph or Virtuoso, especially for queries involving large result sets.
Apache License 2.0
313 stars 38 forks source link

Federated queries with wdt:P18 (image) crash #1375

Open tuukka opened 3 weeks ago

tuukka commented 3 weeks ago

I'm trying to get images related to OSM-Wikidata links, but my queries crash.

One error message (the query completes if I change the inner select to just SELECT ?item) :

Error processing query

Assertion `!isString()` failed. Please report this to the developers. In file "/local/data-ssd/qlever/qlever-code/src/parser/TripleComponent.h " at line 191
Your query was:

PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osm: <https://www.openstreetmap.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX osm2rdfkey: <https://osm2rdf.cs.uni-freiburg.de/rdf/key#>
SELECT ?item ?osm_id ?osmName ?image ?geometry WHERE {
  SERVICE <https://qlever.cs.uni-freiburg.de/api/wikidata> {
    SELECT ?item ?image {
      ?item wdt:P31/wdt:P279* wd:Q473972 .
      ?item wdt:P18 ?image .
    }
  }
  ?osm_id osm2rdfkey:wikidata ?item .
  ?osm_id osmkey:boundary "protected_area" .
#  { ?osm_id rdf:type osm:way . } UNION { ?osm_id rdf:type osm:relation . }

  ?osm_id geo:hasGeometry/geo:asWKT ?geometry .
  ?osm_id osmkey:name ?osmName
}
ORDER BY ?item

Alternatively, if I mark the wdt:P18 as optional, I get another error message:

Error processing query

Parse error at byte position 8: A check for a required element failed The next 500 bytes are: .
Your query was:

PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osm: <https://www.openstreetmap.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX osm2rdfkey: <https://osm2rdf.cs.uni-freiburg.de/rdf/key#>
SELECT ?item ?osm_id ?osmName ?image ?geometry WHERE {
  SERVICE <https://qlever.cs.uni-freiburg.de/api/wikidata> {
    SELECT ?item ?image {
      ?item wdt:P31/wdt:P279* wd:Q473972 .
      OPTIONAL { ?item wdt:P18 ?image . }
    }
  }
  ?osm_id osm2rdfkey:wikidata ?item .
  ?osm_id osmkey:boundary "protected_area" .
#  { ?osm_id rdf:type osm:way . } UNION { ?osm_id rdf:type osm:relation . }

  ?osm_id geo:hasGeometry/geo:asWKT ?geometry .
  ?osm_id osmkey:name ?osmName
}
ORDER BY ?item
joka921 commented 3 weeks ago

Thanks for reporting this. The underlying issue is the following: QLever currently doesn't like if the result of a Service has contains a blank node (that is probably the cause of the !isString issue... or if the Service returns undefined/optional values (your problem with optionals). We currently have someone (@UNEXENU) working on the SERVICE implementation to get rid of such issues (among others).

A current workaround for your concrete query is to filter out the blank nodes (which you are probably not interested in anyway) by adding a FILTER (!ISBLANK(?image)) inside the SERVICE clause: [click me] (https://qlever.cs.uni-freiburg.de/osm-planet/iGdZki)

tuukka commented 3 weeks ago

Thank you! The workaround is suitable for me. To allow OPTIONAL, I can even change the missing values to a placeholder value: https://qlever.cs.uni-freiburg.de/osm-planet/wbFBTJ