Search code examples
rdfsparqljenaowltriplestore

sparql cascade in deleting individuals


i'm using Jena to interact with parliament triple store. The following sparql update query is to insert a new individual of a class Tenant i defined in my ontology:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ex: <http://www.example.org/Example#>
INSERT DATA 
{
  ex:tenant1 a ex:Tenant;
               ex:hasName "admin";
               ex:hasStatus "Enabled".
}

where both hasName and hasStatus are two properties defined in this ontology. Then if i would delete ex:tenant1 individual, is there any way in sparqle to delete in cascade all the triples that has ex:tenant1 as subject? So, deleting only ex:tenant1 a ex:Tenant, i'd like to delete any references to it. I hope i was clear in explaining my problem and thanks you in advance for your help.


Solution

  • Sure. Just

    PREFIX ex: <http://www.example.org/Example#>
    DELETE WHERE { ex:tenant1 ?p ?o } 
    

    This is based on the documentation:

    3.1.3.3 DELETE WHERE

    ….

    Example 11:

    This example request removes all statements about anything with a given name of "Fred" from the default graph:

    PREFIX foaf:  <http://xmlns.com/foaf/0.1/>
    
    DELETE WHERE { ?person foaf:givenName 'Fred';
                           ?property      ?value }