0

PART 1:

These are the triplets which already exists.

<http:o1>   <http:name>   "name"^^xsd:string
<http:o1>   <http:place>   "place"^^xsd:string
<http:o1>   <http:hasContained>   <http:o2>
<http:o2>   <http:name>   "name1"^^xsd:string
<http:o2>   <http:place>   "place2"^^xsd:string
<http:o2>   <http:hasContained>   <http:o3>
<http:o3>   <http:name>   "name3"^^xsd:string
<http:o3>   <http:place>   "place3"^^xsd:string

I want to delete node properties which are 2 nodes away from the o1 node.

delete where { <http:o1> <http:hasContained>/<http:hasContained> ?s. ?s ?p ?o}

I came up with this query to remove o3 node related triplets. But when I run this query, I am getting some errors.

Malformed query: Encountered " "/" "/ "" at line 1, column 731.
Was expecting one of:
    "(" ...
    "[" ...
    <NIL> ...
    <ANON> ...
    "true" ...
    "false" ...
    <Q_IRI_REF> ...
    <PNAME_NS> ...
    <PNAME_LN> ...
    <BLANK_NODE_LABEL> ...
    <VAR1> ...
    <VAR2> ...
    <INTEGER> ...
    <INTEGER_POSITIVE> ...
    <INTEGER_NEGATIVE> ...
    <DECIMAL> ...
    <DECIMAL_POSITIVE> ...
    <DECIMAL_NEGATIVE> ...
    <DOUBLE> ...
    <DOUBLE_POSITIVE> ...
    <DOUBLE_NEGATIVE> ...
    <STRING_LITERAL1> ...
    <STRING_LITERAL2> ...
    <STRING_LITERAL_LONG1> ...
    <STRING_LITERAL_LONG2> ... 

With some alternate queries, I could do the job.

But what is the mistake in the above query?

Why path property query not working with delete where?

PART 2:

For the same triplets data, the query to remove all the triplets used is

delete {?s ?p ?o} where { <http:o1> (<http:hasContained>/<http:hasContained>?)? ?s. ?s ?p ?o}

which is not deleting any data from the triple store. Whereas by using construct, I am able to retrieve the data with the same where clause.

construct {?s ?p ?o} where { <http:o1> (<http:hasContained>/<http:hasContained>?)? ?s. ?s ?p ?o}

What is the issue in these queries, Am I missing something?

harish chava
  • 252
  • 2
  • 19

2 Answers2

3

Per my understanding of SPARQL syntax, the DELETE WHERE ... shorthand does not allow property paths. However, the full form DELETE ... WHERE ... works, so you can do this:

DELETE {?s ?p ?o}
WHERE {
    <http:o1> <http:hasContained>/<http:hasContained> ?s. ?s ?p ?o
}
Ora Lassila
  • 392
  • 1
  • 3
  • This kind of query works. Please comment on the latter part of the question. – harish chava Apr 29 '20 at 03:59
  • All the triples produced by the CONSTRUCT version were deleted by the DELETE version, that is. – Ora Lassila Apr 29 '20 at 11:42
  • The latter 2 queries are different compared to the first query. I want to delete all tripkets (3 hierarchical, o1 ,o2, o3 )data from datastore with that query. – harish chava Apr 29 '20 at 16:49
  • Queries for PART 2 of question are not working @Ora Lassila – harish chava Apr 29 '20 at 16:56
  • How do you expect PART 2 should work? The CONSTRUCT form matches all the triples (effectively, it returns the whole graph). The DELETE form deletes all those triples (effectively, deletes the whole graph). Just ran it, all triples gone. – Ora Lassila Apr 30 '20 at 09:55
  • Delete query is not working for me(not deleting any triplet from the graph). I am using eclipse-rdf4j-3.1.0-sdk, Could it be a version issue? – harish chava Apr 30 '20 at 15:12
  • Could you post some code so we can take a look how you are doing this. – Ora Lassila Apr 30 '20 at 16:21
2

We've been reviewing the SPARQL Spec. on this one. Can you validate if the version below works for you?

  delete { <http:o1> <http:hasContained>/<http:hasContained> ?s. ?s ?p ?o} where { <http:o1> <http:hasContained>/<http:hasContained> ?s. ?s ?p ?o}
Brad Bebee
  • 121
  • 1
  • See Ora's comment below. We confirmed that property paths are not in the [QuadPattern](https://www.w3.org/TR/sparql11-query/#rQuadPattern) for SPARQL 1.1. You need the full syntax. – Brad Bebee Apr 28 '20 at 22:20
  • Please comment on later part of question, where delete is not working but construct is working for same where clause. – harish chava Apr 29 '20 at 03:23
  • The above query doesn't work, Because the delete only takes QuadPattern. But we have given path expression into it. – harish chava Apr 29 '20 at 03:57