1
@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 链接的三元组?

4

1 回答 1

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.}
  }
}
于 2017-08-21T11:20:15.183 回答