Meaning of square brackets “[]” when querying RDF

2019-04-08 21:47发布

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 .}

}

2条回答
疯言疯语
2楼-- · 2019-04-08 22:26

[] 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.

查看更多
3楼-- · 2019-04-08 22:27

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" .
查看更多
登录 后发表回答