Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of square brackets "[]" when querying RDF with SPARQL?

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

}
like image 641
Nitish Mathur Avatar asked Aug 13 '14 04:08

Nitish Mathur


People also ask

How can you query RDF data?

RDF is a directed, labeled graph data format for representing information in the Web. This specification defines the syntax and semantics of the SPARQL query language for RDF. SPARQL can be used to express queries across diverse data sources, whether the data is stored natively as RDF or viewed as RDF via middleware.

How does SPARQL query work?

SPARQL sees your data as a directed, labeled graph, that is internally expressed as triples consisting of subject, predicate and object. Correspondingly, a SPARQL query consists of a set of triple patterns in which each element (the subject, predicate and object) can be a variable (wildcard).

What is a prefix in SPARQL query?

"PREFIX", however (without the "@"), is the SPARQL instruction for a declaration of a namespace prefix. It allows you to write prefixed names in queries instead of having to use full URIs everywhere. So it's a syntax convenience mechanism for shorter, easier to read (and write) queries.

What does SPARQL stand for?

SPARQL is a recursive acronym, which stands for SPARQL Protocol and RDF Query Language. SPARQL consists of two parts: query language and protocol. The query part of that is pretty straightforward. SQL is used to query relational data. XQuery is used to query XML data.


2 Answers

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" .
like image 64
Joshua Taylor Avatar answered Oct 06 '22 02:10

Joshua Taylor


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

like image 28
AndyS Avatar answered Oct 06 '22 02:10

AndyS