![](/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.