[SPARQL] Operators

SPARQL `.`, `;`, `,` operators

How did I encounter this?

While using SPARQL queries, I noticed there are several operators continuously used.

Syntax

`.` operator

It separates triple patterns within a block. By using a `.` to end one triple pattern and start another when they are unrelated or when there’s no shared subject.

Example

?item wdt:P31 wd:Q7889.
?item rdfs:label ?label.
?item is an instance of "video game" (P31 → Q7889).
?item has a label (rdfs:label → ?label)
The value in ?item is assigned to ?label

`;` Operator

It changes properties that share the same subject. By using a `;`,  multiple properties are linked to the same subject

Example

?item wdt:P31 wd:Q7889;
      rdfs:label ?label.

# Equivalent to the following case.

?item wdt:P31 wd:Q7889.
?item rdfs:label ?label.

`,` Operator

It chains multiple objects for the same subject and predicate.  By using a `,`, multiple objects for the same subject and predicate are listed.

Example

?item wdt:P136 wd:Q8603, wd:Q7889.

It means ?item is associated with both:

  • wd:Q8603 (genre: action-adventure game).
  • wd:Q7889 (genre: video game).


(=pup)

Comments