You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Erich Bremer <er...@ebremer.com> on 2016/06/10 20:16:18 UTC

problem with a SPARQL Update query

The following SPARQL using Jena 3.1 works fine:

construct {?neo ?p ?o}
where {?s ?p ?o bind(iri(replace(str(?s),\"\\\\^\",\"r\")) as ?neo) filter 
regex(str(?s),\"(A\\\\^2)\",\"i\")}

It generates modified versions of any IRI's that contain the illegal 
character "^".

However, the following SPARQL, written to delete all triples which contain 
"^" in the subject IRI, throws an error:
delete where {?s ?p ?o filter regex(str(?s),\"(A\\\\^2)\",\"i\")}

Exception in thread "main" org.apache.jena.query.QueryParseException: 
Encountered " "filter" "filter "" at line 1, column 24.
Was expecting one of:
   "graph" ...
   "}" ...
   ";" ...
   "," ...
   "." ...
    at 
org.apache.jena.sparql.lang.ParserSPARQL11Update._parse(ParserSPARQL11Update.java:63)
    at 
org.apache.jena.sparql.lang.ParserSPARQL11Update.parse$(ParserSPARQL11Update.java:40)
    at org.apache.jena.sparql.lang.UpdateParser.parse(UpdateParser.java:39)
    at org.apache.jena.update.UpdateFactory.make(UpdateFactory.java:87)
    at org.apache.jena.update.UpdateFactory.parse(UpdateFactory.java:93)
    at org.apache.jena.update.UpdateRequest.add(UpdateRequest.java:60)
    at experimental.fixthebadIRI.main(fixthebadIRI.java:40)
C:\Users\erich\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: 
Java returned: 1
BUILD FAILED (total time: 3 seconds)

The pertinent code to run these queries is here:

   String qs2 = "construct {?neo ?p ?o} where {?s ?p ?o 
bind(iri(replace(str(?s),\"\\\\^\",\"r\")) as ?neo) filter 
regex(str(?s),\"(A\\\\^2)\",\"i\")}";
   Query query2 = QueryFactory.create(qs2);
   QueryExecution qe2 = QueryExecutionFactory.create(query2, m);
   Model x = qe2.execConstruct();
   m.add(x);

   String qs = "delete where {?s ?p ?o filter 
regex(str(?s),\"(A\\\\^2)\",\"i\")}";
   UpdateRequest request = UpdateFactory.create();
   request.add(qs);
   UpdateAction.execute(request,m);�

Is there something wrong with the code and/or query?

- Erich




Re: problem with a SPARQL Update query

Posted by Andy Seaborne <an...@apache.org>.
 > Is there something wrong with the code and/or query?

DELETE WHERE does not allow filters, only a basic graph pattern.

     Andy


On 10/06/16 21:16, Erich Bremer wrote:
> The following SPARQL using Jena 3.1 works fine:
>
> construct {?neo ?p ?o}
> where {?s ?p ?o bind(iri(replace(str(?s),\"\\\\^\",\"r\")) as ?neo)
> filter regex(str(?s),\"(A\\\\^2)\",\"i\")}
>
> It generates modified versions of any IRI's that contain the illegal
> character "^".
>
> However, the following SPARQL, written to delete all triples which
> contain "^" in the subject IRI, throws an error:
> delete where {?s ?p ?o filter regex(str(?s),\"(A\\\\^2)\",\"i\")}
>
> Exception in thread "main" org.apache.jena.query.QueryParseException:
> Encountered " "filter" "filter "" at line 1, column 24.
> Was expecting one of:
>    "graph" ...
>    "}" ...
>    ";" ...
>    "," ...
>    "." ...
>     at
> org.apache.jena.sparql.lang.ParserSPARQL11Update._parse(ParserSPARQL11Update.java:63)
>
>     at
> org.apache.jena.sparql.lang.ParserSPARQL11Update.parse$(ParserSPARQL11Update.java:40)
>
>     at org.apache.jena.sparql.lang.UpdateParser.parse(UpdateParser.java:39)
>     at org.apache.jena.update.UpdateFactory.make(UpdateFactory.java:87)
>     at org.apache.jena.update.UpdateFactory.parse(UpdateFactory.java:93)
>     at org.apache.jena.update.UpdateRequest.add(UpdateRequest.java:60)
>     at experimental.fixthebadIRI.main(fixthebadIRI.java:40)
> C:\Users\erich\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53:
> Java returned: 1
> BUILD FAILED (total time: 3 seconds)
>
> The pertinent code to run these queries is here:
>
>    String qs2 = "construct {?neo ?p ?o} where {?s ?p ?o
> bind(iri(replace(str(?s),\"\\\\^\",\"r\")) as ?neo) filter
> regex(str(?s),\"(A\\\\^2)\",\"i\")}";
>    Query query2 = QueryFactory.create(qs2);
>    QueryExecution qe2 = QueryExecutionFactory.create(query2, m);
>    Model x = qe2.execConstruct();
>    m.add(x);
>
>    String qs = "delete where {?s ?p ?o filter
> regex(str(?s),\"(A\\\\^2)\",\"i\")}";
>    UpdateRequest request = UpdateFactory.create();
>    request.add(qs);
>    UpdateAction.execute(request,m);
>
> Is there something wrong with the code and/or query?
>
> - Erich
>
>
>