Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalizeQuery() produces invalid SPARQL #53

Open
patrickbr opened this issue Jul 7, 2023 · 3 comments
Open

normalizeQuery() produces invalid SPARQL #53

patrickbr opened this issue Jul 7, 2023 · 3 comments

Comments

@patrickbr
Copy link
Member

The method normalizeQuery()

function normalizeQuery(query, escapeQuotes = false) {
return query.replace(/(<[^>]+)#/g, "$1%23")
.replace(/#.*\n/mg, " ")
.replace(/(<[^>]+)%23/g, "$1#")
.replace(/\s+/g, " ")
.replace(/\s*\.\s*}/g, " }")
.trim();
}
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
Copy link

LorenzBuehmann commented Aug 17, 2023

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
Copy link
Member Author

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

@patrickbr
Copy link
Member Author

The new version is now live.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants