删除连接的三元组

时间:2017-08-21 08:34:11

标签: sparql blank-nodes

@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:foo@example.com> ;
    # some meaningless BNODE example just for demonstration purposes
    # that should also be deleted
    user:xxx [ user:a user:b ] 
.

我试图完成的事情

  • user:uniqueId查找帐户
    • 删除所有它的三元组
  • 找到foaf:holdsAccount <urn:uuid:62eb31ea-e665-49ec-9675-4282ced149da>引用该帐户的资源
    • 删除所有三元组
  • 还会删除所有与BNODE相关的三元组(如果有的话)

我想出了什么

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 .
  }
}

是否有更简洁或有效的方法来删除所有创建的三元组?

如何删除BNODE链接的三元组?

1 个答案:

答案 0 :(得分:1)

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.}
  }
}