|
Apologies for dredging up this question. It has been asked in many places before, but I can't seem to find a definitive answer: Can SPARQL CONSTRUCT queries return duplicate triples in the resulting graph, or must a SPARQL processor discard duplicates? I came to the conclusion that duplicates are allowed, but then noticed that the SPARQL 1.1 Working Draft says: "The result is an RDF graph formed by taking each query solution in the solution sequence, substituting for the variables in the graph template, and combining the triples into a single RDF graph by set union." The 'set union' part I take to mean (courtesy of wikipedia): "...the union of a collection of sets is the set of all distinct elements in the collection". Does this mean that CONSTRUCT queries must not return duplicates? |
|
Hi @bazbishop, The results of a CONSTRUCT query is an RDF graph. An RDF graph is a set of triples. A set is a mathematical object which only contains a single copy of each of its elements. When we communicate the results of a CONSTRUCT query, we do so by writing down the serialization of an RDF graph, such as in RDF/XML or in Turtle. These serializations do nothing to prohibit us from writing the same triple down twice. That is, the following is a valid response to a CONSTRUCT query:
But because this is just a serialization of a set of triples, it's the same exact graph as this:
...and for that matter the same graph as this:
So... a CONSTRUCT query is welcome to return its results in a serialization that contains duplicate triples, but whether it does so or not is irrelevant, since it's serializing the same RDF graph either way. Does that help? Lee @bazbishop, could you change the second part of your comment into a new question? |

