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

parseUpdate refuses valid queries #1758

Open
eggplants opened this issue Mar 14, 2022 · 5 comments
Open

parseUpdate refuses valid queries #1758

eggplants opened this issue Mar 14, 2022 · 5 comments
Labels
bug Something isn't working SPARQL

Comments

@eggplants
Copy link
Contributor

eggplants commented Mar 14, 2022

SPARQLWrapper's way to judge given query's type is to match clauses with regex patterns. So I'm trying to use from rdflib.plugins.sparql.parser import parseQuery, parseUpdate for judging.

But I found few queries in test_wrapper.py was refused by parseUpdate.

  • parseUpdate("WITH <urn:graph> DELETE DATA { <urn:john> <urn:likes> <urn:surfing> }")
    • pyparsing.exceptions.ParseException: Expected end of text, found 'WITH' (at char 0), (line:1, col:1)
  • parseUpdate("PREFIX e: <http://example.org/> INSERT {e:a e:b e:c}")
    • pyparsing.exceptions.ParseException: Expected end of text, found 'INSERT' (at char 32), (line:1, col:33)

I think these queries are valid and some parser syntaxes related to parseUpdate are wrong.

ref: RDFLib/sparqlwrapper#213

@eggplants
Copy link
Contributor Author

@gromgull @gjhiggins Please give me your expert opinion...

@ghost
Copy link

ghost commented Mar 15, 2022

@gromgull @gjhiggins Please give me your expert opinion...

I have only very limited knowledge of SPARQL but I managed to pull these parser-satisfying usage examples out of the RDFLIb tests in the hope that they'll be useful to you:

from rdflib.plugins.sparql.parser import parseQuery
# Adding to the default graph
parseUpdate(
    "PREFIX e: <http://example.org/> INSERT DATA {e:a e:b e:c} ")
# Adding to a named graph
parseUpdate(
    "INSERT DATA {GRAPH <urn:context1> {<urn:example:tarek> <urn:example:likes> <urn:example:cheese> .}}")
# Deleting from the default graph
parseUpdate(
    "DELETE DATA {<urn:example:michel> <urn:example:likes> <urn:example:pizza>}")
# Deleting from a named graph
parseUpdate(
    "DELETE DATA {GRAPH <urn:graph> {<urn:john> <urn:likes> <urn:surfing>}}")

But you are correct in that it does appear that the usage pattern

"WITH <urn:graph> DELETE DATA { <urn:john> <urn:likes> <urn:surfing> }"

isn't supported.

@eggplants
Copy link
Contributor Author

I'll try to debug it when I have time...

@jishnu19048
Copy link

I would like to take up this issue and submit a pr.

@gitongithub
Copy link

While working on this issue along with @jishnu19048, I found that there is partial support for with clause.
This can be seen below:

# [41] Modify ::= ( 'WITH' iri )? ( DeleteClause Optional(InsertClause) | InsertClause ) ZeroOrMore(UsingClause) 'WHERE' GroupGraphPattern
Modify = Comp(
"Modify",
Optional(Keyword("WITH") + Param("withClause", iri))
+ (
Param("delete", DeleteClause) + Optional(Param("insert", InsertClause))
| Param("insert", InsertClause)
)
+ ZeroOrMore(ParamList("using", UsingClause))
+ Keyword("WHERE")
+ Param("where", GroupGraphPattern),
)

However, the expression is extended to capture DeleteClause token but not the DeleteData token because of which the usage pattern of "WITH <urn:graph> DELETE DATA { <urn:john> <urn:likes> <urn:surfing> }" goes unsupported.

We have come up with an addition to capture this and similar usage patterns and are testing them on different examples before finalizing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SPARQL
Projects
None yet
4 participants