11

I am pretty new to SPARQL and RDF and I was wondering what exactly does the below mean in SPARQL?

[] vc:n ?vcard .

The complete query is

PREFIX vc: <http://www.w3.org/2006/vcard/ns#>

SELECT ?given ?family

WHERE{

    [] vc:n ?vcard .

    OPTIONAL {?vcard vc:given-name ?given .}

    OPTIONAL {?vcard vc:family-name ?family .}

}
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Nitish Mathur
  • 113
  • 1
  • 6
  • 2
    The answer here may be useful: http://stackoverflow.com/questions/22311732/what-are-brackets-in-sparql-and-why-is-the-linked-movie-database-limited-to-2500 – Marc Baumbach Aug 13 '14 at 04:32
  • 2
    @MarcBaumbach It's more than useful, it's a duplicate. [What are brackets in SPARQL and why is the linked movie database limited to 2500 records?](http://stackoverflow.com/q/22311732/1281433). "Brackets" in the title of that question refers to square brackets, i.e., `[` and `]`. – Joshua Taylor Aug 13 '14 at 12:25
  • I've also added the [tag:turtle] tag, since this syntax is shared (for the most part, if not exactly) with the Turtle serialization of RDF. – Joshua Taylor Aug 13 '14 at 14:18
  • Thank You all. This was pretty helpful. I would be even more grateful if any of you could give me a brief idea as to what exactly does that line do that is "[] vc:n ?vcard ." As far as I understand it is of the triple format. What does vc:n do? – Nitish Mathur Aug 13 '14 at 18:58

2 Answers2

8

This is cannibalized from my answer to What are brackets in SPARQL and why is the linked movie database limited to 2500 records?, of which this question may be a duplicate, although it's a bit more broad. (It asks two questions, whereas this asks just one.) The answer is mostly links and citations of the SPARQL specification.

[ … ] is a blank node

The square brackets are described in the SPARQL 1.1 Query Language. In particular, see 4.1.4 Syntax for Blank Nodes

4.1.4 Syntax for Blank Nodes

Blank nodes in graph patterns act as variables, not as references to specific blank nodes in the data being queried.

Blank nodes are indicated by either the label form, such as "\_:abc", or the abbreviated form "[]". A blank node that is used in only one place in the query syntax can be indicated with []. A unique blank node will be used to form the triple pattern. Blank node labels are written as "_:abc" for a blank node with label "abc". The same blank node label cannot be used in two different basic graph patterns in the same query.

The [:p :v] construct can be used in triple patterns. It creates a blank node label which is used as the subject of all contained predicate-object pairs. The created blank node can also be used in further triple patterns in the subject and object positions.

The following two forms

[ :p "v" ] .
[] :p "v" .

allocate a unique blank node label (here "b57") and are equivalent to writing:

_:b57 :p "v" .

This allocated blank node label can be used as the subject or object of further triple patterns. For example, as a subject:

[ :p "v" ] :q "w" .

which is equivalent to the two triples:

_:b57 :p "v" .
_:b57 :q "w" .

and as an object:

:x :q [ :p "v" ] .

which is equivalent to the two triples:

:x  :q _:b57 .
_:b57 :p "v" .
Community
  • 1
  • 1
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
6

[] is a blank node in a query. It acts like a named variable except you can't use it in a SELECT project or FILTER or anywhere where you need to name the variable. You can replace [] with a named variable using a name not used anywhere in the query. SELECT * would add it but otherwise it is much the same query.

AndyS
  • 16,345
  • 17
  • 21