【发布时间】:2018-01-29 06:15:56
【问题描述】:
@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 链接的三元组?
【问题讨论】:
-
如果这只是直接连接的空白节点,则可能在
DELETE部分和UNION部分中使用?o ?p1 ?o1之类的东西:OPTIONAL{FILTER(isBlank(?o)) ?o ?p1 ?o1}但对于嵌套或传递连接的三元组,它更多困难的。很贵。 -
我这里没有什么要测试的,但这行得通吗?
OPTIONAL{FILTER(isBlank(?o)) ?o (:|!:)* ?s_del . ?s_del ?p_del ?o_del.在UNION部分和?s_del p_del ?o_del到DELETE部分。请注意,即使这有效,它也不会考虑路径上的传入三元组 -
只是为了理解,您要删除 1) 关于帐户的三元组以及 2) 关于用户的三元组?然后,它是完美的,因为你必须匹配两个不同的结构。现在我正在考虑一般数据(实际上我不知道数据),但是拥有多个帐户的用户呢?我想这是不可能的,对吧?
-
好的,那么我的方法现在应该可以了。至少我在我的本地三元组商店中测试了它,
CONSTRUCT查询返回所有相关的三元组——也是我为了测试目的而引入的一次传递连接。 HTH -
(:|!:)是一种通配符,参见 e。 G。 this answer。可能(a|!a)*更清楚:-)。如果@AKSW 发布他的答案,我将删除此评论。
标签: sparql blank-nodes