![](/img/trans.png)
[英]how to extract subject (Name) in comparison with predicate from a RDF Triple using sparql
[英]SPARQL: DELETE if subject contains 1 triple and has predicate
我想知道是否有人知道基于 2 个条件DELETE
三元组的方法:
我遇到这两个条件的障碍是,为了计算某个主题的COUNT
数,您必须执行GROUP BY?s
。 那么您就没有能力过滤任何?p
值。
最可能的解决方案是子查询,但我不确定它的结构。
我会这样写:
DELETE { ?s ?p ?o }
WHERE {
{
SELECT ?s (COUNT(*) AS ?c) {
?s ?p ?o
}
GROUP BY ?s
}
FILTER (?c = 1)
?s ?p ?o
}
这样的事情有用吗?
我假设“主题的三重计数为 1”是指该主题只有一个三重。 对于 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.