[英]SPARQL: DELETE if subject contains 1 triple and has predicate
I was wondering if anyone knew of a way to DELETE
a triple based on 2 conditions:我想知道是否有人知道基于 2 个条件
DELETE
三元组的方法:
The obstacle I'm coming across with these 2 conditions is that in order to COUNT
the number of statements on a subject, you must do GROUP BY?s
.我遇到这两个条件的障碍是,为了计算某个主题的
COUNT
数,您必须执行GROUP BY?s
。 Then you do not have the ability to filter any ?p
value.那么您就没有能力过滤任何
?p
值。
The most likely solution would be a subquery, but I am not sure how this would be structured.最可能的解决方案是子查询,但我不确定它的结构。
I would write it like this:我会这样写:
DELETE { ?s ?p ?o }
WHERE {
{
SELECT ?s (COUNT(*) AS ?c) {
?s ?p ?o
}
GROUP BY ?s
}
FILTER (?c = 1)
?s ?p ?o
}
Does something like this work?这样的事情有用吗?
I assume that by "Subject has a triple count of 1" you mean that there is only one triple with this subject.我假设“主题的三重计数为 1”是指该主题只有一个三重。 For the case of 1, this is a bit easier since we can just check that "there does not exist another triple for the same subject."
对于 1 的情况,这更容易一些,因为我们可以只检查“同一主题不存在另一个三元组”。
DELETE { ?s ?p ?o }
WHERE {
?s ?p ?o
#-- the value of ?p is the predicate of interest.
#-- Alternatively, this could be a FILTER involving
#-- the variable ?p .
values ?p { <the-predicate> }
#-- There is no other triple with ?s as the subject
#-- that has a different subject or object. (I.e.,
#-- the only triple with ?s as a subject is with ?p
#-- and ?o .
filter not exists {
?s ?pp ?oo
filter (?pp != ?p || ?oo != ?o)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.