使用 AllegroGraph 6.4.6
我正在尝试根据定义的四边形生成单个 SPARQL DELETE 查询:
// Example of dataset used for generation of SPARQL
const quads = [
['<1>','<2>','<3>'], // Graph: DEFAULT
['<a>','<b>','<c>','<d>'], // Graph: <d>
['<w>','<x>','<y>','<z>'], // Graph: <z>
]
/* Example of triples being queried against
S P O G
--- --- --- ---
<1> <2> <3>
<a> <b> <c> <d>
<w> <x> <y> <z> If we delete <1> <2> <3>, we don't
<1> <2> <3> <4> <-- want to accidentally delete this quad
*/
我能够生成一个 SELECT 查询来确定所有四边形的存在:
# Returns all specified quads that exist
SELECT ?s ?p ?o ?g
FROM DEFAULT
FROM NAMED <d>
FROM NAMED <z>
WHERE {
{
?s ?p ?o.
VALUES (?s ?p ?o) {
( <1> <2> <3> )
}
}
UNION
{
GRAPH ?g {?s ?p ?o.}
VALUES (?s ?p ?o ?g) {
( <a> <b> <c> <d> )
( <w> <x> <y> <z> )
}
}
}
- 返回指定的所有四边形
VALUES
<1> <2> <3> <4>
不会被退回。
下一个查询是尝试创建 DELETE 查询,但有一些问题(注意选项 1和选项 2注释):
# Should delete all quads specified in VALUES
DELETE {
GRAPH ?g {?s ?p ?o.}
?sD ?pD ?oD.
}
# USING DEFAULT # Option 1
# USING NAMED <d> # Option 2
# USING NAMED <z> # Option 2
WHERE {
{
?sD ?pD ?oD.
VALUES (?sD ?pD ?oD) {
( <1> <2> <3> )
}
}
UNION
{
GRAPH ?g {?s ?p ?o.}
VALUES (?s ?p ?o ?g) {
( <a> <b> <c> <d> )
( <w> <x> <y> <z> )
}
}
}
仅选项 1未注释时,将返回错误消息:
Found DEFAULT. Was expecting one of: NAMED, Q_IRI_REF, QNAME, QNAME_NS.
仅选项 2未注释时,仅删除指定的命名图三元组:
DELETED: S P O G --- --- --- --- <a> <b> <c> <d> <w> <x> <y> <z>
评论选项 1和选项 2后,每个三元组都会被删除,即使是
<1> <2> <3> <4>
我们没有尝试删除的三元组。DELETED: S P O G --- --- --- --- <1> <2> <3> <a> <b> <c> <d> <w> <x> <y> <z> <1> <2> <3> <4>