SPARQL advanced topics - ge-semtk/semtk Wiki

This page is a collection of SPARQL "gotcha" situations we have encountered.

Negation: MINUS, FILTER NOT EXIST, etc.

There is subtle behavior that might not be apparent from a nodegroup shape. See

Summary:

  • MINUS { } only subtracts the right-hand side from the left-hand side. The left-hand side reaches back to the beginning of the current block, marked by {. This renders a UNION { MINUS {}} as a no-op Instead, the branch of a UNION must also contain the left-hand side clauses for the MINUS
  • FILTER clauses' variables are also only bound within the closest enclosing block

FROM, FROM USING, GRAPH

Multiple FROM clauses create a virtual temporary graph which is the union of all of the clauses' graphs. In my mind this is the "as expected" behavior. Jena does not appear capable of optimizing these. Blazegraph (so probably Neptune?) does optimize these.

Multiple GRAPH clauses are not allowed. Instead a construct like this can be used:

FROM NAMED <http://graph1> FROM NAMED <http://graph2>
GRAPH ?g {
   <clauses>
}

This essentially loops over the named graphs and executes the clauses. So this requires all clauses to match within the same graph

See this Stardog blog post explains common pitfalls.

The W3C section is here: Specifying an RDF dataset

⚠️ **GitHub.com Fallback** ⚠️