Wouter Beek (wouter@triply.cc)
Thomas de Groot (thomas.de.groot@triply.cc)
ask
construct
describe
select
select
select
query
select
query creates a tabular view by matching a pattern against the graph data.select
query conceptsTable | SPARQL |
---|---|
column | variable |
cell | binding |
row | result |
select
query componentsselect
select
query
select ?s ?p ?o
{ ?s ?p ?o. }
limit 10
<https://triplydb.com/academy/pokemon/vocab/colour>
?pokemon
and ?color
"yellow"
bind(VALUE as VARIABLE)
"LEXICAL-FORM"^^<DATATYPE-IRI>
bind(?x * ?y as ?z)
?x
and ?y
to ?z
.
vocab:colour
pokémon:flareon
?color
?pokemon
?color
?pokemon
select *
{{VARIABLE}}
?VARIABLE
in a template string.
limit 250
offset 250
Write a SPARQL select
query over your own data.
Construct | Purpose | Examples |
---|---|---|
Prefix | Abbreviate syntax | prefix ex: <https://example.com/> |
Projection | Select columns | select ?x ?y select * |
Pattern | Match cell values | { ?s ?p ?o. } { ?s ex:p ?o. } |
Binding | Introduce new variables | bind('Hi!' as ?widget) |
Template |
Return HTML widgets | bind('<img src="{{image}}">' as ?widget) |
Limit | Set a maximum number of rows. | limit 10 |
Offset | Skip a number of rows. | offset 10 |
select
?pokemon
.
(dot)
;
(semi-colon),
(comma)
filter( … )
X != Y
, X < Y
, …X
and Y
must not be the same, X
must be smaller than Y
, etc.
lang(…)
filter( A && B )
A
ánd filter B
.
Notation | Example |
---|---|
Absolute IRI | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> |
Relative IRI | <type> (requires base ) |
Prefixed IRI | rdf:type (requires prefix ) |
Type IRI | a (only in predicate position) |
Symbol | Notation type |
---|---|
. | Single triple |
; | Predicate list |
, | Object list |
Example | Datatype IRI |
---|---|
false | xsd:boolean |
11 | xsd:integer |
1.1 | xsd:decimal |
1.1e0 | xsd:double |
"abc" | xsd:string |
P/Q
P
, then follow Q
.P|Q
P
ór follow Q
.P+
P
one or more times.P*
P
zero or more times.
order by ?x
order by ?x ?y ?z
order by desc(?x)
desc
ending).
'''…'''^^rdf:HTML
?widget
What is the heaviest dragon, and how does it sound?
geo:hasGeometry
and geo:asWKT
?shapeLabel
?shape
.
a
rdf:type
.[ P O ]
[…]
) can be used to abbreviate unused subject terms.Find your house or street in the Netherlands.
By using the API elements in this query.
?shapeColor
?shape
.?shapeHeight
?shape
.?shapeLabel
?shape
.values (?var … ?var) { (?term … ?term) … (?term … ?term) }
Find your house or street in the Netherlands.
By editing the query string directly in this query.
Show the 25 oldest buildings in Apeldoorn.
service <URL> { Q }
select
query Q
on the SPARQL endpoint located at URL
.https://dbpedia.org/sparql
Write a federative query
Start at your own endpoint, and federate to an endpoint of one of your colleagues, or federate to DBpedia (https://dbpedia.org/sparql
).
Endpoints must share at least one term (IRI or literal), maybe add a link with owl:sameAs
.
One or more functions that are applied to groups of values.
The groups are generated for each unique combination of values for a specified set of variables.
The set of variables is {?pokemon}
.
The groups are the sets of names per Pokémon.
?pokemon | ?name |
---|---|
id:abomasnow | "ABOMASNOW"@it-it |
id:abomasnow | "ABOMASNOW"@es-es |
id:abomasnow | "ABOMASNOW"@en-us |
id:abomasnow | "BLIZZAROI"@fr-fr |
id:abomasnow | "REXBLISAR"@de-de |
id:abomasnow | "ユキノオー"@ja-ja |
id:abra | "ABRA"@it-it |
id:abra | "ABRA"@fr-fr |
id:abra | "ABRA"@es-es |
id:abra | "ABRA"@de-de |
id:abra | "ABRA"@en-us |
id:abra | "ケーシィ"@ja-ja |
… | … |
count(…)
count
function to each group of names.group by ?pokemon
count
) and there is no group by
clause.
concat(…)
group_concat(…;separator=…)
observation:0007ddade4 a qb:Observation;
qb:dataSet dataset:countries;
dimension:location country:Netherlands;
dimension:year "2002"^^xsd:gYear;
measure:lifeExpectancy 7.9696e1.
dataset:countries a qb:DataSet;
qb:structure dsd:countries;
sdmx-attribute:unitMeasure dbr:Year.
dsd:countries a qb:DataStructureDefinition;
qb:component
[ qb:dimension dimension:location ],
[ qb:dimension dimension:year ],
[ qb:measure measure:lifeExpectancy ],
[ qb:attribute sdmx-attribute:unitMeasure;
qb:componentAttachment qb:Dataset ].
dimension:location a qb:DimensionProperty;
qb:concept sdmx-concept:refArea;
rdfs:range vocab:Country;
rdfs:subPropertyOf sdmx-dimension:refArea.
dimension:year a qb:DimensionProperty;
qb:concept sdmx-concept:refPeriod;
rdfs:range xsd:gYear;
rdfs:subPropertyOf sdmx-dimension:refPeriod.
measure:lifeExpectancy a qb:MeasureProperty;
rdfs:range xsd:double;
rdfs:subProperty sdmx-measure:obsValue.
dimension:year "2007"^^xsd:gYear
dimension:location/rdfs:label ?country
measure:lifeExpectancy ?value
Wouter Beek (wouter@triply.cc)
Thomas de Groot (thomas.de.groot@triply.cc)