Orazio Contarino
Orazio Contarino

Reputation: 103

Sparql delete entity and all its linked elements

I have a Fuseki DB with triples like the following:

<https://tomcat.antudo.it/data/bucket.json-WSP1WS8#row=1>
<https://tomcat.antudo.it/data/bucket.json-WSP1WS8#ws7col0>
"ws6dat1aa"
...
<https://tomcat.antudo.it/data/bucket.json-WSP1WS8#row=2>
<https://tomcat.antudo.it/data/bucket.json-WSP1WS8#ws6col2>
"ws6dat2aa"
...
<http://www.w3.org/2002/07/owl#bottomDataProperty>
<http://www.w3.org/2002/07/owl#propertyDisjointWith>
<https://tomcat.antudo.it/data/bucket.json-WSP1WS8#ws7col0>

I want to delete everything related to:

<https://tomcat.antudo.it/data/bucket.json-WSP1WS8#row=1>

The problem is that i'm not able to write a query that also target triples like that one:

<http://www.w3.org/2002/07/owl#bottomDataProperty>
<http://www.w3.org/2002/07/owl#propertyDisjointWith>
<https://tomcat.antudo.it/data/bucket.json-WSP1WS8#ws7col0>

I have used the following query to delete triples about a list of entities:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
DELETE { 
  ?x ?y ?z
} 
WHERE { 
  {
   ?x ?y ?z.
   ?x rdfs:seeAlso <https://tomcat.antudo.it/data/#dcat_test.csv-WSP1WS6>.
  }
  union
    {
   ?x ?y ?z.
   ?x rdfs:seeAlso <https://tomcat.antudo.it/data/#dcat_test.csv-WSP1WS7>.
  }
}

I think i have to do something similar to that: SPARQL: Delete instance and all of its properties with linked subproperties but i'm stuck. Any help will be appreciated

Upvotes: 1

Views: 825

Answers (1)

scotthenninger
scotthenninger

Reputation: 4001

The following should work if you want to delete the resource entirely from the graph. Note that you need to remove the triples "both ways".

DELETE { 
  <https://tomcat.antudo.it/data/bucket.json-WSP1WS8#row=1> ?p ?o .
  ?s1 ?p1 <https://tomcat.antudo.it/data/bucket.json-WSP1WS8#row=1> .
} 
WHERE { 
   <https://tomcat.antudo.it/data/bucket.json-WSP1WS8#row=1> ?p ?o .
   OPTIONAL {
      ?s1 ?p1 <https://tomcat.antudo.it/data/bucket.json-WSP1WS8#row=1> .
   }
}

Upvotes: 2

Related Questions