LD4SC Summer School7th - 12th June, Cercedilla, Spain
LD4SC Summer School7th - 12th June, Cercedilla, Spain
1st Summer School on Smart Cities and Linked Open Data (LD4SC-15)
RDF(S) and SPARQL
Pieter Pauwels, Ghent University
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The cool and awesome intro movies
https://vimeo.com/36752317https://www.youtube.com/watch?v=4x_xzT5eF5Q
2
LD4SC Summer School7th - 12th June, Cercedilla, Spain
3
Index
• RDF graphs: the simple basis• Syntax: talking the talk
– URIs– RDF Statements– Literals– Collections and containers
• Linked (Open) Data Cloud• Adding basic structure : RDFS• Querying: SPARQL
– The basis– The SPARQL endpoint– Some more complex examples
• Concluding Overview
LD4SC Summer School7th - 12th June, Cercedilla, Spain
RDF graphs, what are they
RDF graphs are DIRECTED, LABELLED GRAPHS
4
P. Pauwels, D. Van Deursen, R. Verstraeten, J. De Roo, R. De Meyer, R. Van de Walle, J. Van Campenhout. A semantic rule checking environment for building performance checking. Automation in Construction 20(5) 2011, 506-518.
LABELLED
DIRECTED
Triple
LD4SC Summer School7th - 12th June, Cercedilla, Spain
RDF graphs, what are they NOT
Hierarchies (cfr. XML)
Relational databases (cfr. MySQL, SQLServer)
5
RDF graphs are DIRECTED, LABELLED GRAPHS
LD4SC Summer School7th - 12th June, Cercedilla, Spain
A triple
6
Triple
SUBJECT OBJECTPREDICATE
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Connecting Triples
7
SUBJECT OBJECTPREDICATE
OBJECT
PREDICATE
OBJECT
PREDICATE
OBJECTPREDICATE
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The result: an RDF graph
8
LABELLED
DIRECTED
Triple
That is it: simple directed labelled graphs, always remember
LD4SC Summer School7th - 12th June, Cercedilla, Spain
9
Index
• RDF graphs: the simple basis• Syntax: talking the talk
– URIs– RDF Statements– Literals– Collections and containers
• Linked (Open) Data Cloud• Adding basic structure : RDFS• Querying: SPARQL
– The basis– The SPARQL endpoint– Some more complex examples
• Concluding Overview
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Talking the RDF language
• RDF stands for Resource Description Framework• RDF is a standard data model for describing web resources
– Note: ‘web resources’ can make statements about anything in the real world: DBPedia, geography, building information, sensors, … anything goes
• RDF is designed to be read and understood by computers• RDF is not designed for being displayed to people• RDF is written in XML• RDF is a W3C Recommendation
10
http://www.w3schools.com/webservices/ws_rdf_intro.asp
easily used
usually
-> standardisation
not a file format, not a syntax, not a schema, … => a data model
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The Semantic Web stack
11
Tim Berners-Lee. WWW past & future, 2003. http://www.w3.org/2003/Talks/0922-rsoc-tbl/.
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Syntaxes for serialisation
12
Triple
RDF/XML
Turtle (TTL)
Notation-3 (N3)
…
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Expressiveness of syntaxes
13
http://www.w3.org/DesignIssues/diagrams/n3/venn
We stick to Turtle today
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Example TTL file
@prefix b: <http://www.R4SC.net/building#> . @prefix c: <http://www.R4SC.net/city#> .
<http://www.R4SC.net/today#building_1> b:hasRoom <http://www.R4SC.net/today#room_1> ; b:hasName “Our summer school building"; c:partOfCity <http://cities.com/#cercedilla> .
<http://cities.com/#cercedilla> c:closeToCity <http://cities.com/#madrid> ;c:hasName “Cercedilla” .
14
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Example TTL graph
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The same thing in RDF/XML
<?xml version="1.0" encoding="UTF-8"?><rdf:RDF xmlns:b="http://www.R4SC.net/building#" xmlns:c="http://www.R4SC.net/city#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description rdf:about="http://www.R4SC.net/today#building_1"> <c:partOfCity rdf:resource="http://cities.com/#cercedilla"/> <b:hasName>Our summer school building</b:hasName> <b:hasRoom rdf:resource="http://www.R4SC.net/today#room_1"/> </rdf:Description> <rdf:Description rdf:about="http://cities.com/#cercedilla"> <c:hasName>Cercedilla</c:hasName> <c:closeToCity rdf:resource="http://cities.com/#madrid"/> </rdf:Description></rdf:RDF>
16
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Convert to different syntaxes
Convert to/from syntaxes:
http://rdf-translator.appspot.com/
Or simply build and use your own software tool
17
LD4SC Summer School7th - 12th June, Cercedilla, Spain
18
Index
• RDF graphs: the simple basis• Syntax: talking the talk
– URIs– RDF Statements– Literals– Collections and containers
• Linked (Open) Data Cloud• Adding basic structure : RDFS• Querying: SPARQL
– The basis– The SPARQL endpoint– Some more complex examples
• Concluding Overview
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Uniform Resource Identifiers
URI
URI
URI
URI
URI
URIURI
URI
URI
URI
URI
LD4SC Summer School7th - 12th June, Cercedilla, Spain
What is a URI?
• URI stands for Uniform Resource Identifier• Purpose: Obtain globally unique identifiers, so that information
can be exchanged globally.• Structure:
<http://www.R4SC.net/today#building_1>
• Namespace needed to avoid name conflicts with tags of the same name: other tags with the name “building_1” can be defined with other namespace URIs, and an RDF reader would still be able to tell that they were different properties even though they had the same tag name.
20
Namespace Name
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Full version of the URIs
<http://www.R4SC.net/today#building_1><http://www.R4SC.net/today#room_1>
<http://www.R4SC.net/building#hasRoom ><http://www.R4SC.net/building#hasName >
<http://www.R4SC.net/city#partOfCity><http://www.R4SC.net/city#closeToCity><http://www.R4SC.net/city#hasName>
<http://cities.com/#cercedilla><http://cities.com/#madrid>
21
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Example TTL file
@prefix b: <http://www.R4SC.net/building#> . @prefix c: <http://www.R4SC.net/city#> .
<http://www.R4SC.net/today#building_1> b:hasRoom <http://www.R4SC.net/today#room_1> ; b:hasName “Our summer school building"; c:partOfCity <http://cities.com/#cercedilla> .
<http://cities.com/#cercedilla> c:closeToCity <http://cities.com/#madrid> ;c:hasName “Cercedilla” .
22
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Prefixed URIs
@prefix b: <http://www.R4SC.net/building#> . @prefix c: <http://www.R4SC.net/city#> . @prefix bi: <http://www.R4SC.net/today#> . @prefix ci: < http://cities.com/# > .
bi:building_1bi:room_1
b:hasRoomb:hasName
c:partOfCityc:closeToCityc:hasName
ci:madridci:cercedilla
23
LD4SC Summer School7th - 12th June, Cercedilla, Spain
TTL file with fully qualified names
<http://www.R4SC.net/today#building_1> <http://www.R4SC.net/building#hasRoom >
<http://www.R4SC.net/today#room_1> ; <http://www.R4SC.net/building#hasName > “Our summer school building"; <http://www.R4SC.net/city#partOfCity > <http://cities.com/#cercedilla> .
<http://cities.com/#cercedilla> <http://www.R4SC.net/city#closeToCity > <http://cities.com/#madrid> ;<http://www.R4SC.net/city#hasName > “Cercedilla” .
24
-> prefixes increase readibility
LD4SC Summer School7th - 12th June, Cercedilla, Spain
25
Index
• RDF graphs: the simple basis• Syntax: talking the talk
– URIs– RDF Statements– Literals– Collections and containers
• Linked (Open) Data Cloud• Adding basic structure : RDFS• Querying: SPARQL
– The basis– The SPARQL endpoint– Some more complex examples
• Concluding Overview
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Statements
Statement
Statement
Statement
Statement
Statement
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Statement follows triple structure
<http://www.R4SC.net/today#building_1><http://www.R4SC.net/city#partOfCity > <http://cities.com/#cercedilla> .
27
Triple
<http://www.R4SC.net/
today#building_1>
<http://cities.com/#cercedilla>
<http://www.R4SC.net/city#partOfCity>
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Combining statements
<http://www.R4SC.net/today#building_1> <http://www.R4SC.net/building#hasRoom >
<http://www.R4SC.net/today#room_1> ; <http://www.R4SC.net/building#hasName > “Our summer school building"; <http://www.R4SC.net/city#partOfCity > <http://cities.com/#cercedilla> .
<http://cities.com/#cercedilla> <http://www.R4SC.net/city#closeToCity > <http://cities.com/#madrid> ;<http://www.R4SC.net/city#hasName > “Cercedilla” .
28
Same subject
AND [next statement]
Same subject
Same subjectAND [next statement]
, Same subject, same predicate
LD4SC Summer School7th - 12th June, Cercedilla, Spain
List of all statements
<http://www.R4SC.net/today#building_1> <http://www.R4SC.net/building#hasRoom >
<http://www.R4SC.net/today#room_1> .
<http://www.R4SC.net/today#building_1> <http://www.R4SC.net/building#hasName > “Our summer school building” .
<http://www.R4SC.net/today#building_1> <http://www.R4SC.net/city#partOfCity > <http://cities.com/#cercedilla> .
<http://cities.com/#cercedilla> <http://www.R4SC.net/city#closeToCity > <http://cities.com/#madrid> .
<http://cities.com/#cercedilla> <http://www.R4SC.net/city#hasName > “Cercedilla” .
29
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Statements
Statement
Statement
Statement
Statement
Statement
LD4SC Summer School7th - 12th June, Cercedilla, Spain
31
Index
• RDF graphs: the simple basis• Syntax: talking the talk
– URIs– RDF Statements– Literals– Collections and containers
• Linked (Open) Data Cloud• Adding basic structure : RDFS• Querying: SPARQL
– The basis– The SPARQL endpoint– Some more complex examples
• Concluding Overview
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Recap on the URIs
URI
URI
URI
URI
URI
URIURI
URI
URI
URI
URI
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Literals in the statements
<http://www.R4SC.net/today#building_1> <http://www.R4SC.net/building#hasRoom >
<http://www.R4SC.net/today#room_1> .
<http://www.R4SC.net/today#building_1> <http://www.R4SC.net/building#hasName > “Our summer school building” .
<http://www.R4SC.net/today#building_1> <http://www.R4SC.net/city#partOfCity > <http://cities.com/#cercedilla> .
<http://cities.com/#cercedilla> <http://www.R4SC.net/city#closeToCity > <http://cities.com/#madrid> .
<http://cities.com/#cercedilla> <http://www.R4SC.net/city#hasName > “Cercedilla” .
33
Literal
Literal
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Conventional representation / distinction from regular resources
Resource
Resource
Resource
Resource
Literal
Literal
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Similar yet distinct
@prefix b: <http://www.R4SC.net/building#> . @prefix c: <http://www.R4SC.net/city#> . @prefix xsd: <http://www.w3.org/2001/XMLSchema>.
<http://www.R4SC.net/today#building_1> b:hasName “Our summer school building” ,
“Our summer school building”@en , “Our summer school building”^^xsd:string
35
Untyped
Typed
Literal with language setting Referring to type
within specific namespace
LD4SC Summer School7th - 12th June, Cercedilla, Spain
What is available in xsd
36
http://www.w3.org/TR/xmlschema-2/
LD4SC Summer School7th - 12th June, Cercedilla, Spain
What is available in xsd
37
http://www.xml.dvint.com/docs/SchemaDataTypesQR-2.pdf
LD4SC Summer School7th - 12th June, Cercedilla, Spain
If you do not like xsd...
Simply define your own datatypes…
@prefix b: <http://www.R4SC.net/building#> . @prefix c: <http://www.R4SC.net/city#> . @prefix dt: < http://www.R4SC.net/todaysdts#> .
<http://www.R4SC.net/today#building_1> b:hasName “Our summer school building”^^dt:myTypeOfString
LD4SC Summer School7th - 12th June, Cercedilla, Spain
39
Index
• RDF graphs: the simple basis• Syntax: talking the talk
– URIs– RDF Statements– Literals– Collections and containers
• Linked (Open) Data Cloud• Adding basic structure : RDFS• Querying: SPARQL
– The basis– The SPARQL endpoint– Some more complex examples
• Concluding Overview
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Repeating properties
• I have a property that can have multiple values, now what?– Solution 1: Simply repeat the property of the
resource multiple times. – Solution 2: Use a structured value for a literal– Solution 3: Use an RDF Container (Sequence, Bag,
or Alt) or Collection (RDF List)
http://patterns.dataincubator.org/book/repeated-property.html
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Example for solution 1: simply repeating property
@prefix b: <http://www.R4SC.net/building#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://www.R4SC.net/today#room_1> b:hasPersonInside <http://www.R4SC.net/today#PieterPauwels> ,
<http://www.R4SC.net/today#RaulGarciaCastro> ,<http://www.R4SC.net/today#AsuncionGomezPerez> ,<http://www.R4SC.net/today#MariaPovedaVillalon> ,<http://www.R4SC.net/today#FilipRadulovic> .
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Example for solution 2: Use a structured value for a literal
@prefix b: <http://www.R4SC.net/building#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://www.R4SC.net/today#room_1> b:hasPeopleInside “IRECOGNIZETHIS:PieterPauwels; IRECOGNIZETHIS:
RaulGarciaCastro; IRECOGNIZETHIS:AsuncionGomezPerez; IRECOGNIZETHIS: MariaPovedaVillalon; IRECOGNIZETHIS: FilipRadulovic”
=> NOT recommended!!
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Example for solution 3
@prefix b: <http://www.R4SC.net/building#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://www.R4SC.net/today#room_1> b:hasPeopleInside ( <http://www.R4SC.net/today#PieterPauwels>
<http://www.R4SC.net/today#RaulGarciaCastro> <http://www.R4SC.net/today#AsuncionGomezPerez> <http://www.R4SC.net/today#MariaPovedaVillalon> <http://www.R4SC.net/today#FilipRadulovic> )
LD4SC Summer School7th - 12th June, Cercedilla, Spain
So, what are our options for solution 3?
• Apart from resources and literals, it is also possible to describe ‘containers’ and ‘collections’
• Containers– Bags– Sequences– Alt
• Collections– Lists
used to describe groups that can ONLY contain the specified members
used to describe an open groups of things (unknown length)
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Bags – Seqs – Alts ??
• Bag– Unordered– Resources or literals– Duplicate values are permitted
• Sequence (Seq)– Ordered– Resources or literals– Duplicate values are permitted
• Alternative (Alt)– Unordered– Resources or literals– Alternatives for a single property value (cfr. language alternatives)These are the conventions / they are ‘just’ conventions
LD4SC Summer School7th - 12th June, Cercedilla, Spain
List
• List– Ordered– Resources or literals– Duplicate values are permitted– Closed collection – length of list is known
• So, identical to a sequence, except that the collection is closed: only the listed items are in the List, nothing else
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Back to our example
@prefix b: <http://www.R4SC.net/building#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://www.R4SC.net/today#room_1> b:hasPeopleInside ( <http://www.R4SC.net/today#PieterPauwels>
<http://www.R4SC.net/today#RaulGarciaCastro> <http://www.R4SC.net/today#AsuncionGomezPerez> <http://www.R4SC.net/today#MariaPovedaVillalon> <http://www.R4SC.net/today#FilipRadulovic> )
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The downside of solution 3<?xml version="1.0" encoding="UTF-8"?><rdf:RDF xmlns:b="http://www.R4SC.net/building#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description rdf:about="http://www.R4SC.net/today#room_1"> <b:hasPeopleInside rdf:nodeID="fabfea5436e794e259b04593dadf0c9f8b1"/> </rdf:Description> <rdf:Description rdf:nodeID="fabfea5436e794e259b04593dadf0c9f8b4"> <rdf:first rdf:resource="http://www.R4SC.net/today#MariaPovedaVillalon"/> <rdf:rest rdf:nodeID="fabfea5436e794e259b04593dadf0c9f8b5"/> </rdf:Description> <rdf:Description rdf:nodeID="fabfea5436e794e259b04593dadf0c9f8b5"> <rdf:first rdf:resource="http://www.R4SC.net/today#FilipRadulovic"/> <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/> </rdf:Description> <rdf:Description rdf:nodeID="fabfea5436e794e259b04593dadf0c9f8b2"> <rdf:first rdf:resource="http://www.R4SC.net/today#RaulGarciaCastro"/> <rdf:rest rdf:nodeID="fabfea5436e794e259b04593dadf0c9f8b3"/> </rdf:Description> <rdf:Description rdf:nodeID="fabfea5436e794e259b04593dadf0c9f8b1"> <rdf:first rdf:resource="http://www.R4SC.net/today#PieterPauwels"/> <rdf:rest rdf:nodeID="fabfea5436e794e259b04593dadf0c9f8b2"/> </rdf:Description> <rdf:Description rdf:nodeID="fabfea5436e794e259b04593dadf0c9f8b3"> <rdf:rest rdf:nodeID="fabfea5436e794e259b04593dadf0c9f8b4"/> <rdf:first rdf:resource="http://www.R4SC.net/today#AsuncionGomezPerez"/> </rdf:Description></rdf:RDF>
Blank nodesElaborate and complex description
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Repeating properties
• I have a property that can have multiple values, now what?– Solution 1: Simply repeat the property of the
resource multiple times. Repeating properties is the simplest approach to handling multi-valued relations. The alternatives all have their downsides.
– Solution 2: Use a structured value for a literal– Solution 3: Use an RDF Container (Sequence, Bag,
or Alt) or Collection (RDF List)
http://patterns.dataincubator.org/book/repeated-property.html
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Wait a second…
Did you say ‘blank nodes’?
LD4SC Summer School7th - 12th June, Cercedilla, Spain
51
What are blank nodes?
• Blank nodes are nodes that do not have URIs– No URI -> no semantics really -> unstable and unreliable
• They are usually represented as: _:1, _:city, _:thiscanbeanythingyouwishfor, _:8936fazGUID, …
• This representation is typically generated on-the-fly so that it is unique within the scope in which an RDF graph is opened– When opening this RDF graph the following day, even in the
same scope, entirely different names might be generated– Unstable and unreliable
LD4SC Summer School7th - 12th June, Cercedilla, Spain
52
So, why do we use these blank nodes?
• Simply because it is hard to give everything an explicit name, this is not always wanted / desirable
• For example:
@prefix b: <http://www.R4SC.net/building#> . @prefix c: <http://www.R4SC.net/city#> . @prefix region: <http://www.R4SC.net/region#> .
<http://www.R4SC.net/today#building_1> b:hasRoom <http://www.R4SC.net/today#room_1> ; b:hasName “Our summer school building"; c:partOfCity <http://cities.com/#cercedilla> ;c:partOfRegion [ region:location “NorthOfMadrid”; region:regiontype “Forest”]
• Likewise, people do not intend to define names for all kinds of groups of things -> hence a lot of blank nodes in descriptions of collections and containers
Blank node
LD4SC Summer School7th - 12th June, Cercedilla, Spain
53
Index
• RDF graphs: the simple basis• Syntax: talking the talk
– URIs– RDF Statements– Literals– Collections and containers
• Linked (Open) Data Cloud• Adding basic structure : RDFS• Querying: SPARQL
– The basis– The SPARQL endpoint– Some more complex examples
• Concluding Overview
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Data integration now possible
MyBuilding Cities
LD4SC Summer School7th - 12th June, Cercedilla, Spain
We already integrated datasets!
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Linked Open Data Cloud
• http://lod-cloud.net/
• datasets that have been published in Linked Data format, by contributors to the Linking Open Data community project and other individuals and organisations
• based on metadata collected and curated by contributors to the Data Hub as well as on metadata extracted from a crawl of the Linked Data web conducted in April 2014
• Attribution: Linking Open Data cloud diagram 2014, by Max Schmachtenberg, Christian Bizer, Anja Jentzsch and Richard Cyganiak. http://lod-cloud.net/
LD4SC Summer School7th - 12th June, Cercedilla, Spain
lod-cloud.net
http://lod-cloud.net (Last version: 2014-08-30)
LD4SC Summer School7th - 12th June, Cercedilla, Spain
History of the LOD
http://lod-cloud.net
LD4SC Summer School7th - 12th June, Cercedilla, Spain
LOD as of May 2007
LD4SC Summer School7th - 12th June, Cercedilla, Spain
LOD as of March 2009
LD4SC Summer School7th - 12th June, Cercedilla, Spain
!!!!Advertisement break!!!!
RDF(S) and SPARQLPieter Pauwels
More to come after the break
LD4SC Summer School7th - 12th June, Cercedilla, Spain
!!!!Advertisement break!!!!
http://ldac-2015.bwk.tue.nl/
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Before the break
LD4SC Summer School7th - 12th June, Cercedilla, Spain
LOD as of August 2014
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Circle sizes and arrow fonts
• Depending on the size of the dataset and the number of triples between datasets, the layout in the LOD cloud schema is different.
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Data integration now possible
MyBuilding Cities
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Status and statistics
• Cumulative stats:http://stats.lod2.eu/ • State of the LOD cloud 2014: http://linkeddatacatalog.dws.informatik.uni-mannheim.de/state/• State of the LOD cloud 2011: http://lod-cloud.net/state/
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Triple counts
http://stats.lod2.eu/
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Stats - Datasets by topical domain
http://linkeddatacatalog.dws.informatik.uni-mannheim.de/state/
Topic Datasets %Government 183 18.05%
Publications 96 9.47%
Life sciences 83 8.19%
User-generated content 48 4.73%
Cross-domain 41 4.04%
Media 22 2.17%
Geographic 21 2.07%
Social web 520 51.28%
Total 1014
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Stats - Categorization by number of linked datasets
Number of linked datasets Number of datasetsmore than 10 79 (7.79%)
6 to 10 81 (7.99%)
5 31 (3.06%)
4 42 (4.14%)
3 54 (5.33%)
2 106 (10.45%)
1 176 (17.36%)
0 445 (43.89%)
http://linkeddatacatalog.dws.informatik.uni-mannheim.de/state/
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Can my dataset be included?
First, make sure that you publish data according to the Linked Data principles. We interpret this as:• There must be resolvable http:// (or https://) URIs.• They must resolve, with or without content negotiation, to RDF
data in one of the popular RDF formats (RDFa, RDF/XML, Turtle, N-Triples).
• The dataset must contain at least 1000 triples.• The dataset must be connected via RDF links to a dataset that is
already in the diagram. This means, either your dataset must use URIs from the other dataset, or vice versam. We arbitrarily require at least 50 links.
• Access of the entire dataset must be possible via RDF crawling, via an RDF dump, or via a SPARQL endpoint.
Then, add it to the Data Hub and request to be included
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The resolvable URIs
Hold on, what do you mean, ‘resolvable’?
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Reminder: What is a URI?
• URI stands for Unique Resource Identifier• Purpose: Obtain globally unique identifiers, so that information
can be exchanged globally.• Structure:
<http://www.R4SC.net/today#building_1>
• Namespace needed to avoid name conflicts with tags of the same name: other tags with the name “building_1" can be defined with other namespace URIs, and an RDF reader would still be able to tell that they were different properties even though they had the same tag name.
73
Namespace Name
LD4SC Summer School7th - 12th June, Cercedilla, Spain
74
What do you mean… resolvable?
• A resolvable URI is: “A URI whose resource has one or more representations available via invoking HTTP GET on the URI”(source: http://www.w3.org/TR/2010/WD-sparql11-http-rdf-update-20100126/)
http://www.w3.org/TR/cooluris/#oldweb
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Dereferencing URIs
http://wifo5-03.informatik.uni-mannheim.de/bizer/pub/LinkedDataTutorial/
LD4SC Summer School7th - 12th June, Cercedilla, Spain
So, you are now ready to publish here
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Note: the O in LOD
• This does NOT mean that RDF is “OPEN” by default
• Most datasets in the LOD cloud have licence information attached
• This does NOT mean that RDF is “OPEN” by default
LD4SC Summer School7th - 12th June, Cercedilla, Spain
78
Index
• RDF graphs: the simple basis• Syntax: talking the talk
– URIs– RDF Statements– Literals– Collections and containers
• Linked (Open) Data Cloud• Adding basic structure : RDFS• Querying: SPARQL
– The basis– The SPARQL endpoint– Some more complex examples
• Concluding Overview
LD4SC Summer School7th - 12th June, Cercedilla, Spain
What did we do so far?
@prefix b: <http://www.R4SC.net/building#> . @prefix c: <http://www.R4SC.net/city#> .
<http://www.R4SC.net/today#building_1> b:hasRoom <http://www.R4SC.net/today#room_1> ; b:hasName “Our summer school building"; c:partOfCity <http://cities.com/#cercedilla> .
<http://cities.com/#cercedilla> c:closeToCity <http://cities.com/#madrid> ;c:hasName “Cercedilla” .
79
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The Semantic Web stack
80
Tim Berners-Lee. WWW past & future, 2003. http://www.w3.org/2003/Talks/0922-rsoc-tbl/.
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The RDF namespace
@prefix rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The first few lines
LD4SC Summer School7th - 12th June, Cercedilla, Spain
We have actually already used it
<?xml version="1.0" encoding="UTF-8"?><rdf:RDF xmlns:b="http://www.R4SC.net/building#" xmlns:c="http://www.R4SC.net/city#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description rdf:about="http://www.R4SC.net/today#building_1"> <c:partOfCity rdf:resource="http://cities.com/#cercedilla"/> <b:hasName>Our summer school building</b:hasName> <b:hasRoom rdf:resource="http://www.R4SC.net/today#room_1"/> </rdf:Description> <rdf:Description rdf:about="http://cities.com/#cercedilla"> <c:hasName>Cercedilla</c:hasName> <c:closeToCity rdf:resource="http://cities.com/#madrid"/> </rdf:Description></rdf:RDF>
83
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Need for structured vocabularies
• RDF graphs -> could be anything• Need for semantics / structured vocabularies
Þ RDFSchema (RDFS) Þ Web Ontology Language (OWL)
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The Semantic Web stack
85
Tim Berners-Lee. WWW past & future, 2003. http://www.w3.org/2003/Talks/0922-rsoc-tbl/.
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The RDFS namespace
@prefix rdfs: http://www.w3.org/2000/01/rdf-schema#
LD4SC Summer School7th - 12th June, Cercedilla, Spain
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Example TTL graph
-> ambiguous / close to meaningless
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Example vocabulary in TTL
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix b: <http://www.R4SC.net/building#> . @prefix c: <http://www.R4SC.net/city#> .
b:InfrastructuralElementrdf:type rdfs:Class .
b:Buildingrdf:type rdfs:Class ;rdfs:subClassOf b:InfrastructuralElement .
b:hasRoomrdf:type rdf:Property ;rdfs:range b:Room ;rdfs:domain b:Building .
89
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The same thing in RDF/XML
<?xml version="1.0" encoding="utf-8"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> <rdf:Property rdf:about="http://www.R4SC.net/building#hasRoom"> <rdfs:domain rdf:resource="http://www.R4SC.net/building#Building"/> <rdfs:range rdf:resource="http://www.R4SC.net/building#Room"/> </rdf:Property> <rdfs:Class rdf:about="http://www.R4SC.net/building#InfrastructuralElement"/> <rdfs:Class rdf:about="http://www.R4SC.net/building#Building"> <rdfs:subClassOf rdf:resource="http://www.R4SC.net/building#InfrastructuralElement"/> </rdfs:Class></rdf:RDF>
90
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Combining instances and vocabulary
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix b: <http://www.R4SC.net/building#> . @prefix c: <http://www.R4SC.net/city#> .
b:InfrastructuralElementrdf:type rdfs:Class .
b:Buildingrdf:type rdfs:Class ;rdfs:subClassOf b:InfrastructuralElement .
b:hasRoomrdf:type rdf:Property ;rdfs:range b:Room ;rdfs:domain b:Building .
91
<http://www.R4SC.net/today#building_1> b:hasRoom <http://www.R4SC.net/today#room_1>; b:hasName “Our summer school building"; c:partOfCity <http://cities.com/#cercedilla> .
<http://cities.com/#cercedilla> c:closeToCity <http://cities.com/#madrid> ;c:hasName “Cercedilla” .
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Example TTL graph
-> unambiguous / meaningful semantics
LD4SC Summer School7th - 12th June, Cercedilla, Spain
93
Index
• RDF graphs: the simple basis• Syntax: talking the talk
– URIs– RDF Statements– Literals– Collections and containers
• Linked (Open) Data Cloud• Adding basic structure : RDFS• Querying: SPARQL
– The basis– The SPARQL endpoint– Some more complex examples
• Concluding Overview
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The Semantic Web stack
94
Tim Berners-Lee. WWW past & future, 2003. http://www.w3.org/2003/Talks/0922-rsoc-tbl/.
LD4SC Summer School7th - 12th June, Cercedilla, Spain
So, it’s also just an RDF graph…
95
http://www.w3.org/DesignIssues/diagrams/n3/venn
We stick to Turtle today
Let’s just quietly extend towards SPARQL as well
LD4SC Summer School7th - 12th June, Cercedilla, Spain
96
Index
• RDF graphs: the simple basis• Syntax: talking the talk
– URIs– RDF Statements– Literals– Collections and containers
• Linked (Open) Data Cloud• Adding basic structure : RDFS• Querying: SPARQL
– The basis– The SPARQL endpoint– Some more complex examples
• Concluding Overview
LD4SC Summer School7th - 12th June, Cercedilla, Spain
What is SPARQL
• SPARQL stands for SPARQL Protocol and RDF Query Language• SPARQL is a Query Language• Find the W3C Recommendation page:
http://www.w3.org/TR/rdf-sparql-query/– Used to express queries across diverse data sources, whether the data is
stored natively as RDF or viewed as RDF via middleware. – SPARQL contains capabilities for querying required and optional graph
patterns along with their conjunctions and disjunctions. – SPARQL supports extensible value testing and constraining queries by
source RDF graph. – The results of SPARQL queries can be results sets or RDF graphs.
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The inspiration: SQL
select A1, A2, ..., Anfrom r1, r2, ..., rmwhere P
LD4SC Summer School7th - 12th June, Cercedilla, Spain
SPARQL template
prefix a:…select conceptsfrom datasourceswhere { statements }order by …
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Structure of a SPARQL query
• Prefix declarationsUsed to abbreviate URIs
• Dataset definitionUsed to state what RDF graph(s) are being queried
• A result clauseUsed to identify what information to return from the
query• The query pattern
Used to specify what to query for in the underlying dataset• Query modifiers, slicing, ordering, and otherwise
Used to rearrange query results (post-processing)
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Let’s query our example graph
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Example SPARQL Query
PREFIX b: <http://www.R4SC.net/building#> .PREFIX c: <http://www.R4SC.net/city#> .
SELECT ?city2 WHERE {
?b b:hasRoom <http://www.R4SC.net/today#room_1> . ?b c:partOfCity ?city .?city c:closeToCity ?city2
}
variable
Regular RDF statements
Regular RDF prefix declarations
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Processing the WHERE statement section
• A pattern is matched against the RDF data• “find a set of bindings such that the substitution of variables for values creates a triple that is in the set of triples making up the graph”
• Source: http://www.w3.org/2004/Talks/17Dec-sparql/QueryLang1/all.html
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Graph matching
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The Query Result
city2
<http://cities.com/#madrid>
LD4SC Summer School7th - 12th June, Cercedilla, Spain
106
Index
• RDF graphs: the simple basis• Syntax: talking the talk
– URIs– RDF Statements– Literals– Collections and containers
• Linked (Open) Data Cloud• Adding basic structure : RDFS• Querying: SPARQL
– The basis– The SPARQL endpoint– Some more complex examples
• Concluding Overview
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Example SPARQL endpoint on DBPedia
The HTTP Address of the endpoint
The software used in the server to store the triples (cfr. DBMS)
Diverse options to set
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Try it
Try it out on the DBPedia dataset:
http://dbpedia.org/sparql
Or even better: host one yourself and make it available
108
LD4SC Summer School7th - 12th June, Cercedilla, Spain
109
Index
• RDF graphs: the simple basis• Syntax: talking the talk
– URIs– RDF Statements– Literals– Collections and containers
• Linked (Open) Data Cloud• Adding basic structure : RDFS• Querying: SPARQL
– The basis– The SPARQL endpoint– More details
• Concluding Overview
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Matching literals (1)
RDF data:@prefix b: <http://www.R4SC.net/building#> . @prefix people: <http://www.R4SC.net/people#> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . <http://www.R4SC.net/today#room_1>
b:hasPersonInside "Pieter"@en . <http://www.R4SC.net/today#restaurant>
b:hasPersonInside "Raul"^^xsd:string . <http://www.R4SC.net/today#airport>
b:hasPersonInside "Leandro"^^people:keynotespeaker .
QuerySELECT ?v WHERE { ?v ?p "Pieter" }
Result{ }
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Matching literals (2)
RDF data:@prefix b: <http://www.R4SC.net/building#> . @prefix people: <http://www.R4SC.net/people#> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . <http://www.R4SC.net/today#room_1>
b:hasPersonInside "Pieter"@en . <http://www.R4SC.net/today#restaurant>
b:hasPersonInside "Raul"^^xsd:string . <http://www.R4SC.net/today#airport>
b:hasPersonInside "Leandro"^^people:keynotespeaker .
QuerySELECT ?v WHERE { ?v ?p "Pieter"@en}
Result{ <http://www.R4SC.net/today#room_1> }
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Matching literals (3)
RDF data:@prefix b: <http://www.R4SC.net/building#> . @prefix people: <http://www.R4SC.net/people#> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . <http://www.R4SC.net/today#room_1>
b:hasPersonInside "Pieter"@en . <http://www.R4SC.net/today#restaurant>
b:hasPersonInside "Raul"^^xsd:string . <http://www.R4SC.net/today#airport>
b:hasPersonInside "Leandro"^^people:keynotespeaker .
QuerySELECT ?v WHERE { ?v ?p "Leandro"^^< http://www.R4SC.net/people#keynotespeaker > }
Result{ <http://www.R4SC.net/today#airport > }
LD4SC Summer School7th - 12th June, Cercedilla, Spain
Querying blank nodes
RDF data:@prefix b: <http://www.R4SC.net/building#> .
_:room1 b:hasPersonInside “Pieter" . _:room2 b:hasPersonInside “Raul" .
QueryPREFIX b: <http://www.R4SC.net/building#> SELECT ?x ?nameWHERE { ?x b:hasPersonInside ?name }
Resultx name
_:c "Pieter"
_:d "Leandro"
x name
_:r "Pieter"
_:s "Leandro"…
LD4SC Summer School7th - 12th June, Cercedilla, Spain
CONSTRUCT queriesRDF data:@prefix b: <http://www.R4SC.net/building#> .@prefix : <http://www.R4SC.net/today#> ._:a b:presenterName “Pieter" ._:b b:presenterName “Raul" .:room1 b:hasPersonInside _:a . :room1 b:hasPersonInside “Raul" .:room1 rdf:type b:R4SCPresentationRoom
QueryPREFIX b: <http://www.R4SC.net/building#> WHERE { ?x rdf:type b:R4SCPresentationRoom . ?x: b:hasPersonInside ?z . ?z b:presenterName ?name }CONSTRUCT { ?x b:hasR4SCPresenter ?name }
Result@prefix b: <http://www.R4SC.net/building#> .@prefix : <http://www.R4SC.net/today#> .:room1 b:hasR4SCPresenter “Pieter” .:room1 b:hasR4SCPresenter “Raul”
LD4SC Summer School7th - 12th June, Cercedilla, Spain
SPARQL FiltersRDF data:@prefix b: <http://www.R4SC.net/building#> .@prefix : <http://www.R4SC.net/today#> .:room_1 b:hasPresentationTitle “RDF(S) and SPARQL" .:room_1 b:hasPeopleInside 28 .:room_2 b:hasPresentationTitle “Handson session RDF(S) and SPARQL" .:room_2 b:hasPeopleInside 23 .
Query@prefix b: <http://www.R4SC.net/building#> .SELECT ?titleWHERE { ?x b:hasPresentationTitle ?title
FILTER regex(?title, "^Hands") }
Result
title
"Handson session RDF(S) and SPARQL"
Many possibilities: string matching, value restrictions (greaterThan, etc.), DateTime restrictions, …
LD4SC Summer School7th - 12th June, Cercedilla, Spain
OPTIONAL keywordRDF data:@prefix b: <http://www.R4SC.net/building#> .@prefix : <http://www.R4SC.net/today#> .:room_1 b:hasPresentationTitle “RDF(S) and SPARQL" .:room_1 b:hasPeopleInside 28 .:room_2 b:hasPresentationTitle “Handson session RDF(S) and SPARQL" .:room_2 b:hasPeopleInside 23 .
Query@prefix b: <http://www.R4SC.net/building#> .SELECT ?title ?attendeesWHERE { ?x b:hasPresentationTitle ?title . OPTIONAL { ?x b:hasPeopleInside ?attendees. FILTER (?attendees > 25) } }
Result
title attendees
"RDF(S) and SPARQL" 28
"Handson session RDF(S) and SPARQL"
If there is a match, give the optional data, otherwise give the required data
LD4SC Summer School7th - 12th June, Cercedilla, Spain
LIMIT Keyword
RDF data:@prefix b: <http://www.R4SC.net/building#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .<http://www.R4SC.net/today#room_1>
b:hasPersonInside “PieterPauwels" , “RaulGarciaCastro" , “AsuncionGomezPerez" , “MariaPovedaVillalon", “FilipRadulovic" .
QueryPREFIX b: <http://www.R4SC.net/building#>SELECT ?nameWHERE { ?x b:hasPersonInside ?name }LIMIT 2
Result
name
“PieterPauwels"
“RaulGarciaCastro"
LD4SC Summer School7th - 12th June, Cercedilla, Spain
ORDER BY
RDF data:@prefix b: <http://www.R4SC.net/building#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .<http://www.R4SC.net/today#room_1>
b:hasPersonInside “PieterPauwels" , “RaulGarciaCastro" , “AsuncionGomezPerez" , “MariaPovedaVillalon", “FilipRadulovic" .
QueryPREFIX b: <http://www.R4SC.net/building#>SELECT ?nameWHERE { ?x b:hasPersonInside ?name }LIMIT 2 ORDER BY DESC(?name)
Result
name
“RaulGarciaCastro"
“PieterPauwels"
LD4SC Summer School7th - 12th June, Cercedilla, Spain
DISTINCT KeywordRDF data:@prefix b: <http://www.R4SC.net/building#> .@prefix : <http://www.R4SC.net/today#> .:room_1 b:hasPresentation [ b:hasPresentationTitle “RDF(S) and SPARQL" ] .:room_1 b:hasPresentation [ b:hasPresentationTitle “Handson session Generate your RDF”; b:startsAt “14:30:00”^^xsd:time ] .:room_1 b:hasPresentation [ b:hasPresentationTitle “Handson session Generate your RDF”; b:startsAt “17:00:00”^^xsd:time ] .
QueryPREFIX b: < http://www.R4SC.net/building# >SELECT DISTINCT ?titleWHERE { ?x b:hasPresentationTitle ?title}
Result
title
“RDF(S) and SPARQL"
“Handson session Generate your RDF"
LD4SC Summer School7th - 12th June, Cercedilla, Spain
UNION KeywordRDF data:@prefix b: <http://www.R4SC.net/building#> .@prefix : <http://www.R4SC.net/today#> .:room_1 b:hasPresentation [ b:hasPresentationTitle “RDF(S) and SPARQL" ] .:room_1 b:hasPresentation [ b:hasPresentationTitle “Handson session Generate your RDF”; b:startsAt “14:30:00”^^xsd:time ] .:room_1 b:hasPresentation [ b:hasPresentationTitle “Handson session Generate your RDF”; b:startsAt “17:00:00”^^xsd:time ] ._:x1 b:presentation “Linking Data” .
Query@prefix b: <http://www.R4SC.net/building#> .@prefix : <http://www.R4SC.net/today#> .
SELECT DISTINCT ?title_1 ?title_2WHERE { { ?p b:hasPresentationTitle ?title_1 } UNION { ?p1 b:presentation ?title_2 } }
title
“RDF(S) and SPARQL"
“Handson session Generate your RDF"
“Linking Data”
Result
LD4SC Summer School7th - 12th June, Cercedilla, Spain
But well, the only way to learn it…
Try it out, for example, on the DBPedia dataset:
http://dbpedia.org/sparql
Or even better: host one yourself and make it available
121
LD4SC Summer School7th - 12th June, Cercedilla, Spain
122
Index
• RDF graphs: the simple basis• Syntax: talking the talk
– URIs– RDF Statements– Literals– Collections and containers
• Linked (Open) Data Cloud• Adding basic structure : RDFS• Querying: SPARQL
– The basis– The SPARQL endpoint– Some more complex examples
• Concluding Overview
LD4SC Summer School7th - 12th June, Cercedilla, Spain
The Semantic Web stack
123
Tim Berners-Lee. WWW past & future, 2003. http://www.w3.org/2003/Talks/0922-rsoc-tbl/.
LD4SC Summer School7th - 12th June, Cercedilla, Spain
LD4SC Summer School7th - 12th June, Cercedilla, Spain
1st Summer School on Smart Cities and Linked Open Data (LD4SC-15)
Thank you for your attention!