Günter Zöchbauer
Günter Zöchbauer

Reputation: 658263

Delete connected triples

@prefix userS: <http://example.org/2017/6/user_schema#> .
@prefix user: <http://example.org/2017/6/user#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

user:account_62eb31ea-e665-49ec-9675-4282ced149da
    userS:uniqueId <urn:uuid:62eb31ea-e665-49ec-9675-4282ced149da> ;
    rdf:type
        foaf:OnlineAccount ,
        userS:Entity ;
    foaf:accountName 'foo' ;
    foaf:accountServiceHomepage <http://example.com/myaccount>
.

user:user_62eb31ea-e665-49ec-9675-4282ced149da
    rdf:type
        foaf:Person ,
        userS:Administrator ,
        userS:User ;
    foaf:holdsAccount user:account_62eb31ea-e665-49ec-9675-4282ced149da ;
    foaf:mbox <mailto:[email protected]> ;
    # some meaningless BNODE example just for demonstration purposes
    # that should also be deleted
    user:xxx [ user:a user:b ] 
.

What I try to accomplish

What I came up with

PREFIX userS: <http://example.org/2017/6/user_schema#>
PREFIX user: <http://example.org/2017/6/user#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

WITH <http://bewellup.org/2017/6/product/bwu_product_user>
DELETE { 
  ?s ?p ?o .
}  
WHERE {  
  BIND (<urn:uuid:62eb31ea-e665-49ec-9675-4282ced149da> as ?accountId)
  {
    ?s rdf:type 
        foaf:OnlineAccount ;
        userS:uniqueId ?accountId .
    ?s ?p ?o .
  }
  UNION {
    ?account rdf:type 
        foaf:OnlineAccount ;
        userS:uniqueId ?accountId .
    ?s foaf:holdsAccount ?account .
    ?s ?p ?o .
  }
}

Is there a more concise or efficient way to delete all the created triples?

How do I also get the triples linked by BNODEs deleted?

Upvotes: 1

Views: 405

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 658263

PREFIX userS: <http://bewellup.org/2017/6/product/bwu_user_schema#>
PREFIX user: <http://bewellup.org/2017/6/product/bwu_product_user#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

WITH <http://bewellup.org/2017/6/product/bwu_product_user>
DELETE { 
  ?s ?p ?o .
  ?s_del ?p_del ?o_del .
}
WHERE {  
  BIND (<urn:uuid:62eb31ea-e665-49ec-9675-4282ced149da> as ?accountId)
  {
    ?s rdf:type 
        foaf:OnlineAccount ;
        userS:uniqueId ?accountId .
    ?s ?p ?o .
     OPTIONAL{FILTER(isBlank(?o)) ?o (:|!:)* ?s_del . ?s_del ?p_del ?o_del. }
  }
  UNION {
    ?account rdf:type 
        foaf:OnlineAccount ;
        userS:uniqueId ?accountId .
    ?s foaf:holdsAccount ?account .
    ?s ?p ?o .
    OPTIONAL{FILTER(isBlank(?o)) ?o (:|!:)* ?s_del . ?s_del ?p_del ?o_del.}
  }
}

Upvotes: 1

Related Questions