Reputation: 863
Using AllegroGraph 6.4.6
I am trying to generate a single SPARQL DELETE query w/ respect to quads defined:
// 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
*/
I'm able to generate a SELECT query for determining the existence of all quads:
# 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>
does not get returned.The next query is an attempt at creating the DELETE query, but has a few issues (Note the Option 1 and Option 2 comments):
# 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> )
}
}
}
With ONLY Option 1 uncommented, an error message is returned:
Found DEFAULT. Was expecting one of: NAMED, Q_IRI_REF, QNAME, QNAME_NS.
With ONLY Option 2 uncommented, only the specified Named Graph triples are deleted:
DELETED:
S P O G
--- --- --- ---
<a> <b> <c> <d>
<w> <x> <y> <z>
With BOTH Option 1 and Option 2 commented, every triple gets deleted, even the triple <1> <2> <3> <4>
which we weren't trying to delete.
DELETED:
S P O G
--- --- --- ---
<1> <2> <3>
<a> <b> <c> <d>
<w> <x> <y> <z>
<1> <2> <3> <4>
Upvotes: 1
Views: 618
Reputation: 22042
FROM DEFAULT
to indicate the default graph is not a standard SPARQL feature, so its behavior will be dependent on the triplestore that you use (and many SPARQL engines will simply give a syntax error).
To delete from the two named graphs, you could do this (note that I've removed the NAMED
bit, and removed the graph parameter):
DELETE {?s ?p ?o}
USING <d>
USING <z>
{
?s ?p ?o.
VALUES (?s ?p ?o) {
( <a> <b> <c> )
( <w> <x> <y> )
}
}
Like I said, the DEFAULT
keyword is not a standard SPARQL feature. Perhaps your SPARQL engine will understand it if you do this:
DELETE {?s ?p ?o}
USING DEFAULT
USING <d>
USING <z>
{
?s ?p ?o.
VALUES (?s ?p ?o) {
( <1> <2> <3> )
( <a> <b> <c> )
( <w> <x> <y> )
}
}
Otherwise, your best best is probably to use a sequence of updates, rather than trying to do everything in one big delete.
Upvotes: 1