Laatst gewijzigd op: 18 juni 2018
Instructies: Gebruik de pijltjestoetsen (←, →, ↑, ↓) om door de presentatie te navigeren. Druk op de ESC toets voor een overzicht.
select ?s ?p ?o {
?s ?p ?o
}
limit 5
Onderdelen:
projectie: select ?s ?p ?o
patroon: ?s ?p ?o .
limiet: limit 5
select ?o ?p ?s {
?s ?p ?o
}
limit 5
select ?s ?p ?o {
?s ?p ?o
}
limit 10
select ?s ?p ?o {
?s ?p ?o
}
limit 5
offset 5
select ?s {
?s ?p "De Brug"^^<http://www.w3.org/2001/XMLSchema#string> .
}
limit 100
"De
Brug"^^<http://www.w3.org/2001/XMLSchema#string>
is een literal.
<http://www.w3.org/2001/XMLSchema#string>
is het datatype.
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
select ?s {
?s ?p "De Brug"^^xsd:string .
}
limit 100
URI kunnen worden afgekort met prefix
declaraties.
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
select ?s {
{
?s ?p "De Brug"^^xsd:string .
} union {
?s ?p "De Brug"@nl .
}
}
limit 100
"De Brug"@nl
is een language-tagged
string. Dit betekent dat "De Brug"
geïnterpreteerd moet worden in het Nederlands
(nl
).
{ A } union { B }
geeft aan dat de de
resultaten van query A
én de resultaten
van query B
willen.
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
select distinct ?klasse {
{
?s ?p "De Brug"^^xsd:string ; a ?klasse .
} union {
?s ?p "De Brug"@nl ; a ?klasse .
}
}
limit 100
‘a
’ duidt de relatie aan tussen een
instantie en een klasse. ‘a
’ is een
afkorting voor rdf:type
, wat een
afkorting is
voor <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
.
distinct
laat alleen unieke resultaten zien.
‘;
’ is een afkorting die de subject term herhaalt.
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?s {
?s rdfs:label "Apeldoorn"@nl .
}
limit 100
rdfs:label
geeft een menselijk
interpreteerbare naam van een ding.
prefix rdfs:
select ?s ?label {
?s rdfs:label "Apeldoorn"@nl ; a ?klasse .
?klasse rdfs:label ?label .
}limit 100
Merk op dat we ?klasse
niet gebruiken in
de projectie (zie volgende query).
prefix rdfs:
select ?s ?label {
?s rdfs:label "Apeldoorn"@nl ; a/rdfs:label ?label .
}
limit 100
We slaan ?klasse
uit de vorige query over.
X/Y
is een property path.
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?wkt ?wktLabel {
?s rdfs:label "Apeldoorn"@nl ;
geo:hasGeometry/geo:asWKT ?wkt ;
a/rdfs:label ?wktLabel .
}
limit 100
geo:hasGeometry/geo:asWKT
geeft de
Well-Known Text (WKT) representatie van een geometrie.
Merk op dat we verschillende vocabulaires door elkaar
heen gebruiken: rdfs
van W3C
en geo
van OGC.
“Ik bedoel het registratief gebied”
prefix brt: <http://brt.basisregistraties.overheid.nl/def/top10nl#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?wkt ?wktLabel {
?instantie rdfs:label "Apeldoorn"@nl ;
geo:hasGeometry/geo:asWKT ?wkt ;
a brt:RegistratiefGebied .
}
limit 100
prefix <http://bag.basisregistraties.overheid.nl/def/bag#>
select ?openbareRuimte {
?openbareRuimte bag:naamOpenbareRuimte "Hofstraat"
}
limit 100
Openbare ruimtes die ‘Hofstraat’ heten.
prefix bag: <http://bag.basisregistraties.overheid.nl/def/bag#>
select ?openbareRuimte ?woonplaats {
?openbareRuimte bag:naamOpenbareRuimte "Hofstraat" ;
bag:bijbehorendeWoonplaats ?woonplaats .
}
limit 100
Openbare ruimtes die ‘Hofstraat’ heten én hun bijbehorende woonplaats.
prefix bag: <http://bag.basisregistraties.overheid.nl/def/bag#>
select ?openbareRuimte ?woonplaats ?label {
?openbareRuimte bag:naamOpenbareRuimte "Hofstraat" ;
bag:bijbehorendeWoonplaats ?woonplaats .
?woonplaats bag:naamWoonplaats ?label .
}
limit 100
Weer ambiguïteit: er zijn heel veel openbare ruimtes die ‘Hofstraat’ heten.
prefix bag: <http://bag.basisregistraties.overheid.nl/def/bag#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?openbareRuimte ?woonplaats {
?openbareRuimte bag:naamOpenbareRuimte "Hofstraat" ;
bag:bijbehorendeWoonplaats ?woonplaats .
?woonplaats rdfs:label "Apeldoorn"@nl .
}
limit 100
De Hofstraat in Apeldoorn.
(Merk op: er zijn 2 openbare ruimtes; hierover later meer.)prefix bag: <http://bag.basisregistraties.overheid.nl/def/bag#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?nummeraanduiding ?openbareRuimte {
?openbareRuimte bag:naamOpenbareRuimte "Hofstraat" ;
bag:bijbehorendeWoonplaats/rdfs:label "Apeldoorn"@nl .
?nummeraanduiding bag:bijbehorendeOpenbareRuimte ?openbareRuimte ;
bag:huisnummer 110 .
}
limit 100
Met property path notatie (/
) slaan we de
niet gebruikte ?woonplaats
over.
prefix bag: <http://bag.basisregistraties.overheid.nl/def/bag#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?wkt {
?openbareRuimte bag:naamOpenbareRuimte "Hofstraat" ;
bag:bijbehorendeWoonplaats/rdfs:label "Apeldoorn"@nl .
?nummeraanduiding bag:bijbehorendeOpenbareRuimte ?openbareRuimte ;
bag:huisnummer 110 .
?verblijfsobject bag:hoofdadres ?nummeraanduiding ;
bag:pandrelatering ?pand .
?pand bag:geometriePand/geo:asWKT ?wkt .
}
limit 100
prefix bag: <http://bag.basisregistraties.overheid.nl/def/bag#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?wkt ?wktLabel {
?openbareRuimte bag:naamOpenbareRuimte "Hofstraat" ;
bag:bijbehorendeWoonplaats/rdfs:label "Apeldoorn"@nl .
?nummeraanduiding bag:bijbehorendeOpenbareRuimte ?openbareRuimte ;
bag:huisnummer ?wktLabel .
?verblijfsobject bag:hoofdadres ?nummeraanduiding ;
bag:pandrelatering/bag:geometriePand/geo:asWKT ?wkt .
}
limit 100
Waarom zien we sommige panden dubbel?
prefix bag: <http://bag.basisregistraties.overheid.nl/def/bag#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?wktVerblijfsobject ?wktVerblijfsobjectColor ?wktVerblijfsobjectLabel ?wktPand ?wktPandLabel {
?openbareRuimte bag:naamOpenbareRuimte "Hofstraat" ;
bag:bijbehorendeWoonplaats/rdfs:label "Apeldoorn"@nl .
?nummeraanduiding bag:bijbehorendeOpenbareRuimte ?openbareRuimte ;
bag:postcode ?postcode ;
bag:huisnummer ?huisnummer .
?verblijfsobject bag:hoofdadres ?nummeraanduiding ;
geo:hasGeometry/geo:asWKT ?wktVerblijfsobject ;
bag:pandrelatering ?pand ;
a/rdfs:label ?label .
?pand bag:geometriePand/geo:asWKT ?wktPand .
bind (concat('Hofstraat ',str(?huisnummer)) as ?wktPandLabel)
bind (concat(?wktPandLabel,' ',str(?postcode),'
',str(?label)) as ?wktVerblijfsobjectLabel)
bind ("red" as ?wktVerblijfsobjectColor)
}
limit 1000
Facebook, Google, Bing, BBC, NYT, Renault, Accenture, Deloitte, Wallmart, Getty, NXP, Europeana, Springer, Elsevier, ..only 140chars... https://t.co/oeMRQyDLLt
— Frank van Harmelen (@FrankVanHarmele) October 31, 2017
Schema.org:
Er zijn heel veel andere Linked Datasets op het web.
We kunnen al deze Datasets bevragen met SPARQL.
prefix brt: <http://brt.basisregistraties.overheid.nl/def/top10nl#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?shape ?shapeLabel {
bind("Amsterdam"@nl as ?naam)
?plaats1 rdfs:label ?naam ; brt:isBAGwoonplaats true ; geo:hasGeometry/geo:asWKT ?shape
service <https://dbpedia.org/sparql> {
?plaats2 rdfs:label ?naam ; foaf:depiction ?vlag
}
bind(concat(
'<h2>',str(?naam),'</h2>',
if(bound(?vlag),concat('<img src="',replace(str(?vlag),'http://','https://'),'" style="max-width: 150px;">'),''),
'<p>Externe representatie: <a href="',str(?plaats2),'">[DBpedia]</a></p>'
) as ?shapeLabel)
}
limit 1
service <URL> { A }
betekent: voer
query A
uit op SPARQL
endpoint URL
, en voeg de resultaten
samen.
prefix brt: <http://brt.basisregistraties.overheid.nl/def/top10nl#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?shape ?shapeLabel {
bind("Apeldoorn"@nl as ?naam)
?plaats1 rdfs:label ?naam ; brt:isBAGwoonplaats true ; geo:hasGeometry/geo:asWKT ?shape
service <https://dbpedia.org/sparql> {
?plaats2 rdfs:label ?naam
optional { ?plaats2 foaf:depiction ?vlag }
}
bind(concat(
'<h2>',str(?naam),'</h2>',
if(bound(?vlag),concat('<img src="',str(?vlag),'" style="max-width: 150px;">'),''),
'<p>Externe representatie: <a href="',str(?plaats2),'">[DBpedia]</a></p>'
) as ?shapeLabel)
}
limit 1
optional { A }
betekent:
voer A
uit, indien mogelijk.
Met name nuttig voor ontbrekende waardes (data op het web is vaak onvolledig).
prefix bag:
prefix geo:
select ?wkt ?wktLabel {
?verblijfsobject bag:hoofdadres/bag:bijbehorendeOpenbareRuimte/bag:bijbehorendeWoonplaats/bag:naamWoonplaats "Apeldoorn" ;
bag:pandrelatering ?pand .
?pand bag:oorspronkelijkBouwjaar ?wktLabel ;
bag:geometriePand/geo:asWKT ?wkt .
}
order by asc(?wktLabel)
limit 50
prefix bag: <http://bag.basisregistraties.overheid.nl/def/bag#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?openbareRuimte ?woonplaats {
?openbareRuimte bag:naamOpenbareRuimte "Hofstraat" ;
bag:bijbehorendeWoonplaats ?woonplaats .
?woonplaats rdfs:label "Apeldoorn"@nl .
}
limit 100
openbareRuimte | woonplaats |
---|---|
openbare-ruimte:0200300022471548 | woonplaats:2247 |
openbare-ruimte:0200300022471548 | woonplaats:3560 |
prefix bag: <http://bag.basisregistraties.overheid.nl/def/bag#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?woonplaats ?status {
?openbareRuimte bag:naamOpenbareRuimte "Hofstraat" ;
bag:bijbehorendeWoonplaats ?woonplaats .
?woonplaats rdfs:label "Apeldoorn"@nl ;
bag:status ?status .
}
limit 100
woonplaats | status |
---|---|
woonplaats:2247 | begrip:WoonplaatsAangewezen |
woonplaats:2247 | begrip:WoonplaatsIngetrokken |
woonplaats:3560 | begrip:WoonplaatsAangewezen |
prefix bag: <http://bag.basisregistraties.overheid.nl/def/bag#>
prefix begrip: <http://bag.basisregistraties.overheid.nl/id/begrip/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?openbareRuimte ?woonplaats {
?openbareRuimte bag:naamOpenbareRuimte "Hofstraat" ;
bag:bijbehorendeWoonplaats ?woonplaats .
?woonplaats rdfs:label "Apeldoorn"@nl .
filter not exists {
?woonplaats bag:status begrip:WoonplaatsIngetrokken .
}
}
limit 100
Nu hebben we de juiste Apeldoorn.
prefix bag: <http://bag.basisregistraties.overheid.nl/def/bag#>
prefix begrip: <http://bag.basisregistraties.overheid.nl/id/begrip/>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?wkt ?begin ?eind {
?openbareRuimte bag:naamOpenbareRuimte "Hofstraat" ;
bag:bijbehorendeWoonplaats ?woonplaats .
?woonplaats rdfs:label "Apeldoorn"@nl .
filter not exists {
?woonplaats bag:status begrip:WoonplaatsIngetrokken .
}
?nummeraanduiding bag:bijbehorendeOpenbareRuimte ?openbareRuimte ;
bag:huisnummer 110 .
graph ?voorkomen {
?verblijfsobject bag:hoofdadres ?nummeraanduiding .
}
?verblijfsobject bag:pandrelatering/bag:geometriePand/geo:asWKT ?wkt .
?voorkomen bag:beginGeldigheid ?begin .
optional {
?voorkomen bag:eindGeldigheid ?eind .
}
}
limit 100
graph
betekent: voer
query A
uit binnen
deelgraaf URI
.
prefix bag: <http://bag.basisregistraties.overheid.nl/def/bag#>
prefix begrip: <http://bag.basisregistraties.overheid.nl/id/begrip/>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?wkt ?begin {
?openbareRuimte bag:naamOpenbareRuimte "Hofstraat" ;
bag:bijbehorendeWoonplaats ?woonplaats .
?woonplaats rdfs:label "Apeldoorn"@nl .
filter not exists {
?woonplaats bag:status begrip:WoonplaatsIngetrokken .
}
?nummeraanduiding bag:bijbehorendeOpenbareRuimte ?openbareRuimte ;
bag:huisnummer 110 .
graph ?voorkomen {
?verblijfsobject bag:hoofdadres ?nummeraanduiding .
}
?verblijfsobject bag:pandrelatering/bag:geometriePand/geo:asWKT ?wkt .
?voorkomen bag:beginGeldigheid ?begin .
filter not exists {
?voorkomen bag:eindGeldigheid ?eind .
}
}
limit 100