ad-freiburg / qlever-ui

A user interface for QLever
Apache License 2.0
19 stars 12 forks source link

normalizeQuery() produces invalid SPARQL #53

Open patrickbr opened 12 months ago

patrickbr commented 12 months ago

The method normalizeQuery() https://github.com/ad-freiburg/qlever-ui/blob/1ad9df580008cf470c30b2d586001f9dc10642e6/backend/static/js/helper.js#L26-L33 fails to return valid SPARQL in the following cases:

  1. When a comment appears in a line containing a < (for example a FILTER query using comparators)
  2. When a # appears in a string literal

There might be other cases I have missed.

LorenzBuehmann commented 10 months ago

Maybe not related, but for the Map view the following query fails because of the MINUS clause I guess?

PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX wiki: <http://en.wikipedia.org/wiki/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select distinct ?s ?loc {
  ?s p:P31 ?stmt . ?stmt ps:P31 ?type . ?type wdt:P279+ wd:Q1220959 . # wd:Q16831714 .
   ?s wdt:P625 ?loc .
   MINUS {?stmt wdt:P582 ?end}
}

Link to query in UI

The error message is

{
    "exception": "Invalid SPARQL query: Token \"}\": mismatched input '}' expecting ",
    "metadata": {
        "line": 1,
        "positionInLine": 489,
        "query": "PREFIX p:  PREFIX ps:  PREFIX wiki:  PREFIX wdt:  PREFIX wd:  PREFIX rdf:  PREFIX rdfs:  select distinct ?s ?loc { ?s p:P31 ?stmt . ?stmt ps:P31 ?type . ?type wdt:P279+ wd:Q1220959 . MINUS { ?stmt wdt:P582 ?end } ?s wdt:P625 ?loc }} LIMIT 18446744073709551615",
        "startIndex": 489,
        "stopIndex": 489
    },
    "query": "PREFIX p:  PREFIX ps:  PREFIX wiki:  PREFIX wdt:  PREFIX wd:  PREFIX rdf:  PREFIX rdfs:  select distinct ?s ?loc { ?s p:P31 ?stmt . ?stmt ps:P31 ?type . ?type wdt:P279+ wd:Q1220959 . MINUS { ?stmt wdt:P582 ?end } ?s wdt:P625 ?loc }} LIMIT 18446744073709551615",
    "resultsize": 0,
    "status": "ERROR",
    "time": {
        "computeResult": 0,
        "total": 0
    }
}

it looks like the intermediate query being used to render the map is

PREFIX p:  PREFIX ps:  PREFIX wiki:  PREFIX wdt:  PREFIX wd:  PREFIX rdf:  PREFIX rdfs:  
select distinct ?s ?loc { ?s p:P31 ?stmt . ?stmt ps:P31 ?type . ?type wdt:P279+ wd:Q1220959 . MINUS { ?stmt wdt:P582 ?end } ?s wdt:P625 ?loc }} LIMIT 18446744073709551615

not sure what happens to the prefix part here but I guess the cause of the issue is the redundant curly bracket at the end.

patrickbr commented 10 months ago

Should now be fixed with cd8a019c. This version is however not live, yet.

patrickbr commented 10 months ago

The new version is now live.