Search code examples
sparqlsemantic-webvirtuosolinked-data

SPARQL CONSTRUCT: does implicit subject/object influence the result?


I have a SPARQL CONSTRUCT like:

CONSTRUCT
{
  ?address
    schema:addressLocality ?city;
    schema:addressCountry ?country;
    schema:streetAddress ?addressLine;
    schema:postalCode ?zip;
    schema:addressRegion ?region.
}
WHERE
{
  ?address
    schema:addressLocality ?city;
    schema:addressCountry ?country. 

  OPTIONAL { ?address schema:streetAddress ?addressLine }
  OPTIONAL { ?address schema:postalCode ?zip }
  OPTIONAL { ?address schema:addressRegion ?region }
}

I'm getting fewer triples this way, than when the CONSTRUCT lists all the triple patterns explicitly, without omitting the subject for variables that are optional (ie, possibly unbounded):

CONSTRUCT
{
  ?address
    schema:addressLocality ?city;
    schema:addressCountry ?country.

  ?address schema:streetAddress ?addressLine.
  ?address schema:postalCode ?zip.
  ?address schema:addressRegion ?region.
}
...

I was assuming that the two forms can't influence the result, but now I'm gathering that instead the implicit subject syntax actually means something like "I want all the graph rooted on this subject or nothing at all for it". Is it like that? Is this behaviour specified by SPARQL, or is it the way it's implemented in certain engines (I'm on top of Virtuoso)?


Solution

  • Not an ultimate answer, but at least what I've learned so far. As comments above say, SPARQL should return the same from either form.

    I suspect that the problem arises from the fact that Virtuoso doesn't trigger an error when the query execution times out, it instead silently returns the results it achieved up to the time deadline. But I'm not sure of that either, since I don't see any special HTTP header in the response, as they suggest in the link I've mentioned.