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?

asked 05 Nov '12, 17:18

bazbishop's gravatar image

bazbishop
3413
accept rate: 25%


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:

ex:s ex:p ex:o .
ex:s ex:p ex:o .

But because this is just a serialization of a set of triples, it's the same exact graph as this:

ex:s ex:p ex:o .

...and for that matter the same graph as this:

ex:s ex:p ex:o .
ex:s ex:p ex:o .
ex:s ex:p ex:o .
ex:s ex:p ex:o .

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

link

answered 05 Nov '12, 17:26

lee's gravatar image

lee
3.2k39
accept rate: 37%

@bazbishop, could you change the second part of your comment into a new question?

(06 Nov '12, 03:47) Jerven Jerven's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×1,266
×32

Asked: 05 Nov '12, 17:18

Seen: 964 times

Last updated: 06 Nov '12, 10:35