1

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> )
    }
  }
}
  • Returns all quads specified in 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>
    
Neil Graham
  • 593
  • 1
  • 5
  • 17
  • 1
    What's your quad store (name and version)? It matters... Not least, because `DEFAULT` doesn't exist in every store, if indeed in any (though it is in [discussion for possible inclusion in SPARQL 1.2](https://github.com/w3c/sparql-12/issues/43)). – TallTed Oct 30 '19 at 21:23
  • I'm using AllegroGraph 6.4.6 – Neil Graham Oct 30 '19 at 21:44
  • 1
    The AllegroGraph documentation only [discusses `SELECT` (not `DELETE`) with `FROM DEFAULT`](https://franz.com/agraph/support/documentation/6.3.0/python/tutorial/example010.html). It does say that the "unnamed" `DEFAULT` Named Graph cannot be addressed simultaneously with other Named Graphs, so I think that your quest for a single query for this deletion cannot be satisfied -- and also that you may not be able to delete `{ <1> <2> <3> }` from `DEFAULT` without also deleting `{ <1> <2> <3> <4> }`. – TallTed Oct 31 '19 at 13:50
  • 1
    Add `PREFIX franzOption_defaultDatasetBehavior: ` or `PREFIX franzOption_defaultDatasetBehavior: ` to your query and repeat experiments. – Stanislav Kralin Oct 31 '19 at 19:12

1 Answers1

1

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.

Neil Graham
  • 593
  • 1
  • 5
  • 17
Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73