SPARQL Tutorial

Leigh Dodds
Leigh DoddsAssociate
Data Extraction & Exploration with SPARQL & the Talis Platform
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Tutorial Schema ,[object Object],[object Object],[object Object]
 
Triple and Graph Patterns ,[object Object]
#An RDF triple in Turtle syntax <http://purl.org/net/schemas/space/spacecraft/1957-001B>   foaf:name “Sputnik 1”.
#An SPARQL triple pattern, with a single variable <http://purl.org/net/schemas/space/spacecraft/1957-001B>   foaf:name ?name.
#All parts of a triple pattern can be variables ?spacecraft   foaf:name ?name.
 
#Matching labels of resources ?subject rdfs:label ?label.
 
#Combine triples patterns to create a graph pattern ?subject rdfs:label ?label. ?subject rdf:type space:Discipline.
#SPARQL is based on Turtle, which allows abbreviations #e.g. predicate-object lists: ?subject rdfs:label ?label; rdf:type space:Discipline.
 
#Graph patterns allow us to traverse a graph ?spacecraft foaf:name “Sputnik 1”. ?launch space:spacecraft ?launch. ?launch space:launched ?launchdate.
#Graph patterns allow us to traverse a graph ?spacecraft foaf:name “Sputnik 1” . ?launch space:spacecraft ?launch . ?launch space:launched ?launchdate .
 
Structure of a Query ,[object Object]
#Ex. 1 #Associate URIs with prefixes PREFIX space: <http://purl.org/net/schemas/space/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> #Example of a SELECT query, retrieving 2 variables #Variables selected MUST be bound in graph pattern SELECT ?subject ?label WHERE { #This is our graph pattern ?subject rdfs:label ?label; rdf:type space:Discipline. }
#Ex. 2 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> #Example of a SELECT query, retrieving all variables SELECT * WHERE { ?subject rdfs:label ?label; rdf:type space:Discipline. }
OPTIONAL bindings ,[object Object]
#Ex. 3 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?image WHERE { #This pattern must be bound ?spacecraft foaf:name ?name. #Anything in this block doesn't have to be bound OPTIONAL {   ?spacecraft foaf:depiction ?image. } }
UNION queries ,[object Object]
#Ex. 4 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: < http://xmlns.com/foaf/0.1/ > PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?subject ?displayLabel WHERE { { ?subject foaf:name ?displayLabel. } UNION { ?subject rdfs:label ?displayLabel. } }
Sorting & Restrictions ,[object Object],[object Object]
#Ex.5  #Select the uri and the mass of all the spacecraft PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: < http://xmlns.com/foaf/0.1/ > PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?spacecraft ?mass WHERE { ?spacecraft space:mass ?mass. }
#Ex. 6 #Select the uri and the mass of all the spacecraft #with highest first PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: < http://xmlns.com/foaf/0.1/ > PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?spacecraft ?mass WHERE { ?spacecraft space:mass ?mass. } #Use an ORDER BY clause to apply a sort. Can be ASC or DESC ORDER BY DESC(?mass)‏
#Ex. 7 #Select the uri and the mass of the 10 heaviest spacecraft PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: < http://xmlns.com/foaf/0.1/ > PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?spacecraft ?mass WHERE { ?spacecraft space:mass ?mass. } #Order by weight descending ORDER BY DESC(?mass)‏ #Limit to first ten results LIMIT 10
#Ex. 8 #Select the uri and the mass of the 11-20 th  most  #heaviest spacecraft PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: < http://xmlns.com/foaf/0.1/ > PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?spacecraft ?mass WHERE { ?spacecraft space:mass ?mass. } ORDER BY DESC(?mass)‏ #Limit to ten results LIMIT 10 #Apply an offset to get next “page” OFFSET 10
Filtering ,[object Object]
#Sample data for Sputnik launch <http://purl.org/net/schemas/space/launch/1957-001> rdf:type space:Launch; #Assign a datatype to the literal, to indicate it is #a date space:launched &quot;1957-10-04&quot;^^xsd:date; space:spacecraft <http://purl.org/net/schemas/space/spacecraft/1957-001B> .
#Ex. 9 #Select name of spacecraft launched between  #1 st  Jan 1969 and 1 st  Jan 1970 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?name WHERE { ?launch space:launched ?date; space:spacecraft ?spacecraft. ?spacecraft foaf:name ?name. FILTER (?date > &quot;1969-01-01&quot;^^xsd:date &&  ?date < &quot;1970-01-01&quot;^^xsd:date)‏ }
#Ex. 10 #Select spacecraft with a mass of less than 90kg PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?spacecraft ?name WHERE { ?spacecraft foaf:name ?name; space:mass ?mass. #Note that we have to cast the data to the right type #As it is not declared in the data FILTER( xsd:double(?mass) < 90.0 )‏ }
#Ex. 11 #Select spacecraft with a name like “ollo” PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?name WHERE { ?spacecraft foaf:name ?name. FILTER( regex(?name, “ollo”, “i” ) )‏ }
Built-In Filters ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
DISTINCT ,[object Object]
#Ex. 12 #Select list of agencies associated with spacecraft PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT DISTINCT ?agency WHERE { ?spacecraft space:agency ?agency. }
SPARQL Query Forms ,[object Object]
ASK ,[object Object]
#Ex. 13 #Was there a launch on 16 th  July 1969? PREFIX space: <http://purl.org/net/schemas/space/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> ASK WHERE { ?launch space:launched &quot;1969-07-16&quot;^^xsd:date. }
DESCRIBE Generate an RDF description of a resource(s)‏
#Ex. 14 #Describe launch(es) that occurred on 16 th  July 1969 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> DESCRIBE ?launch WHERE { ?launch space:launched &quot;1969-07-16&quot;^^xsd:date. }
#Ex. 15 #Describe spacecraft launched on 16 th  July 1969 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> DESCRIBE ?spacecraft WHERE { ?launch space:launched &quot;1969-07-16&quot;^^xsd:date. ?spacecraft space:launch ?launch. }
CONSTRUCT Create a custom RDF graph based on query criteria Can be used to transform RDF data
#Ex. 16 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> CONSTRUCT { ?spacecraft foaf:name ?name; space:agency ?agency; space:mass ?mass.  } WHERE { ?launch space:launched &quot;1969-07-16&quot;^^xsd:date. ?spacecraft space:launch ?launch; foaf:name ?name; space:agency ?agency; space:mass ?mass.  }
SELECT SQL style result set retrieval
#Ex. 17 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?agency ?mass WHERE { ?launch space:launched &quot;1969-07-16&quot;^^xsd:date. ?spacecraft space:launch ?launch; foaf:name ?name; space:agency ?agency; space:mass ?mass.  }
Useful Links ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
shared innovation
1 of 49

Recommended

SPARQL in a nutshell by
SPARQL in a nutshellSPARQL in a nutshell
SPARQL in a nutshellFabien Gandon
9.9K views39 slides
SPARQL-DL - Theory & Practice by
SPARQL-DL - Theory & PracticeSPARQL-DL - Theory & Practice
SPARQL-DL - Theory & PracticeAdriel Café
4K views27 slides
SHACL by example by
SHACL by exampleSHACL by example
SHACL by exampleJose Emilio Labra Gayo
13.6K views44 slides
SPARQL introduction and training (130+ slides with exercices) by
SPARQL introduction and training (130+ slides with exercices)SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)Thomas Francart
2.1K views134 slides
SHACL Overview by
SHACL OverviewSHACL Overview
SHACL OverviewIrene Polikoff
1.4K views42 slides
Semantic web meetup – sparql tutorial by
Semantic web meetup – sparql tutorialSemantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialAdonisDamian
6.2K views25 slides

More Related Content

What's hot

Rdf In A Nutshell V1 by
Rdf In A Nutshell V1Rdf In A Nutshell V1
Rdf In A Nutshell V1Fabien Gandon
5.9K views66 slides
RDFS In A Nutshell V1 by
RDFS In A Nutshell V1RDFS In A Nutshell V1
RDFS In A Nutshell V1Fabien Gandon
7.3K views33 slides
Introduction To RDF and RDFS by
Introduction To RDF and RDFSIntroduction To RDF and RDFS
Introduction To RDF and RDFSNilesh Wagmare
1.2K views19 slides
Jena – A Semantic Web Framework for Java by
Jena – A Semantic Web Framework for JavaJena – A Semantic Web Framework for Java
Jena – A Semantic Web Framework for JavaAleksander Pohl
5.2K views25 slides
OWL Full Semantics by
OWL Full SemanticsOWL Full Semantics
OWL Full SemanticsJie Bao
1.7K views41 slides
RDF 개념 및 구문 소개 by
RDF 개념 및 구문 소개RDF 개념 및 구문 소개
RDF 개념 및 구문 소개Dongbum Kim
21.2K views44 slides

What's hot(20)

RDFS In A Nutshell V1 by Fabien Gandon
RDFS In A Nutshell V1RDFS In A Nutshell V1
RDFS In A Nutshell V1
Fabien Gandon7.3K views
Introduction To RDF and RDFS by Nilesh Wagmare
Introduction To RDF and RDFSIntroduction To RDF and RDFS
Introduction To RDF and RDFS
Nilesh Wagmare1.2K views
Jena – A Semantic Web Framework for Java by Aleksander Pohl
Jena – A Semantic Web Framework for JavaJena – A Semantic Web Framework for Java
Jena – A Semantic Web Framework for Java
Aleksander Pohl5.2K views
OWL Full Semantics by Jie Bao
OWL Full SemanticsOWL Full Semantics
OWL Full Semantics
Jie Bao1.7K views
RDF 개념 및 구문 소개 by Dongbum Kim
RDF 개념 및 구문 소개RDF 개념 및 구문 소개
RDF 개념 및 구문 소개
Dongbum Kim21.2K views
SHACL in Apache jena - ApacheCon2020 by andyseaborne
SHACL in Apache jena - ApacheCon2020SHACL in Apache jena - ApacheCon2020
SHACL in Apache jena - ApacheCon2020
andyseaborne383 views
Hive 3 - a new horizon by Thejas Nair
Hive 3 - a new horizonHive 3 - a new horizon
Hive 3 - a new horizon
Thejas Nair2.6K views
SPARQL Cheat Sheet by LeeFeigenbaum
SPARQL Cheat SheetSPARQL Cheat Sheet
SPARQL Cheat Sheet
LeeFeigenbaum92.4K views
온톨로지 & 규칙 추론 시스템 by Sang-Kyun Kim
온톨로지 & 규칙 추론 시스템온톨로지 & 규칙 추론 시스템
온톨로지 & 규칙 추론 시스템
Sang-Kyun Kim5.6K views
WebTech Tutorial Querying DBPedia by Katrien Verbert
WebTech Tutorial Querying DBPediaWebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPedia
Katrien Verbert8.2K views
Understanding RDF: the Resource Description Framework in Context (1999) by Dan Brickley
Understanding RDF: the Resource Description Framework in Context  (1999)Understanding RDF: the Resource Description Framework in Context  (1999)
Understanding RDF: the Resource Description Framework in Context (1999)
Dan Brickley7.3K views
LODAC 2017 Linked Open Data Workshop by Myungjin Lee
LODAC 2017 Linked Open Data WorkshopLODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data Workshop
Myungjin Lee3.5K views
SPARQL queries on CIDOC-CRM data of BritishMuseum by Thomas Francart
SPARQL queries on CIDOC-CRM data of BritishMuseumSPARQL queries on CIDOC-CRM data of BritishMuseum
SPARQL queries on CIDOC-CRM data of BritishMuseum
Thomas Francart741 views

Similar to SPARQL Tutorial

Ontologias - RDF by
Ontologias - RDFOntologias - RDF
Ontologias - RDFelliando dias
708 views77 slides
From SQL to SPARQL by
From SQL to SPARQLFrom SQL to SPARQL
From SQL to SPARQLGeorge Roth
5.6K views31 slides
Ks2007 Semanticweb In Action by
Ks2007 Semanticweb In ActionKs2007 Semanticweb In Action
Ks2007 Semanticweb In ActionRinke Hoekstra
1.9K views29 slides
NoSQL and Triple Stores by
NoSQL and Triple StoresNoSQL and Triple Stores
NoSQL and Triple Storesandyseaborne
4.9K views16 slides
Tutorial ESWC2011 Building Semantic Sensor Web - 04 - Querying_semantic_strea... by
Tutorial ESWC2011 Building Semantic Sensor Web - 04 - Querying_semantic_strea...Tutorial ESWC2011 Building Semantic Sensor Web - 04 - Querying_semantic_strea...
Tutorial ESWC2011 Building Semantic Sensor Web - 04 - Querying_semantic_strea...Jean-Paul Calbimonte
895 views35 slides
Intro to Linked, Dutch Ships and Sailors and SPARQL handson by
Intro to Linked, Dutch Ships and Sailors and SPARQL handson Intro to Linked, Dutch Ships and Sailors and SPARQL handson
Intro to Linked, Dutch Ships and Sailors and SPARQL handson Victor de Boer
1.4K views48 slides

Similar to SPARQL Tutorial(20)

From SQL to SPARQL by George Roth
From SQL to SPARQLFrom SQL to SPARQL
From SQL to SPARQL
George Roth5.6K views
Ks2007 Semanticweb In Action by Rinke Hoekstra
Ks2007 Semanticweb In ActionKs2007 Semanticweb In Action
Ks2007 Semanticweb In Action
Rinke Hoekstra1.9K views
NoSQL and Triple Stores by andyseaborne
NoSQL and Triple StoresNoSQL and Triple Stores
NoSQL and Triple Stores
andyseaborne4.9K views
Tutorial ESWC2011 Building Semantic Sensor Web - 04 - Querying_semantic_strea... by Jean-Paul Calbimonte
Tutorial ESWC2011 Building Semantic Sensor Web - 04 - Querying_semantic_strea...Tutorial ESWC2011 Building Semantic Sensor Web - 04 - Querying_semantic_strea...
Tutorial ESWC2011 Building Semantic Sensor Web - 04 - Querying_semantic_strea...
Intro to Linked, Dutch Ships and Sailors and SPARQL handson by Victor de Boer
Intro to Linked, Dutch Ships and Sailors and SPARQL handson Intro to Linked, Dutch Ships and Sailors and SPARQL handson
Intro to Linked, Dutch Ships and Sailors and SPARQL handson
Victor de Boer1.4K views
Getting Started With The Talis Platform by Leigh Dodds
Getting Started With The Talis PlatformGetting Started With The Talis Platform
Getting Started With The Talis Platform
Leigh Dodds811 views
SPARQLing Services by Leigh Dodds
SPARQLing ServicesSPARQLing Services
SPARQLing Services
Leigh Dodds822 views
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs by Josef Petrák
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
Josef Petrák617 views
Mashup OpenStreetMap and Wikidata to Create Useful Vector Data by Nicholas Peihl
Mashup OpenStreetMap and Wikidata to Create Useful Vector DataMashup OpenStreetMap and Wikidata to Create Useful Vector Data
Mashup OpenStreetMap and Wikidata to Create Useful Vector Data
Nicholas Peihl45 views
(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011) by Olaf Hartig
(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
Olaf Hartig2.3K views
SPARQL 1.1 Update (2013-03-05) by andyseaborne
SPARQL 1.1 Update (2013-03-05)SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)
andyseaborne4.5K views
Geography in Linked Ancient World Data by paregorios
Geography in Linked Ancient World DataGeography in Linked Ancient World Data
Geography in Linked Ancient World Data
paregorios541 views
The Semantics of SPARQL by Olaf Hartig
The Semantics of SPARQLThe Semantics of SPARQL
The Semantics of SPARQL
Olaf Hartig2.2K views
Ks2008 Semanticweb In Action by Rinke Hoekstra
Ks2008 Semanticweb In ActionKs2008 Semanticweb In Action
Ks2008 Semanticweb In Action
Rinke Hoekstra1.8K views
OpenSearch 2010-09 by Oscar Fonts
OpenSearch 2010-09OpenSearch 2010-09
OpenSearch 2010-09
Oscar Fonts1.2K views

More from Leigh Dodds

Being a data magpie by
Being a data magpieBeing a data magpie
Being a data magpieLeigh Dodds
6 views26 slides
How you (yes, you!) can contribute to open data by
How you (yes, you!) can contribute to open dataHow you (yes, you!) can contribute to open data
How you (yes, you!) can contribute to open dataLeigh Dodds
3.3K views18 slides
Accessible Bath Training by
Accessible Bath TrainingAccessible Bath Training
Accessible Bath TrainingLeigh Dodds
221 views19 slides
Accessible Bath by
Accessible BathAccessible Bath
Accessible BathLeigh Dodds
461 views14 slides
Cheap bots done quick lightning talk by
Cheap bots done quick lightning talkCheap bots done quick lightning talk
Cheap bots done quick lightning talkLeigh Dodds
880 views13 slides
Open data in bath by
Open data in bathOpen data in bath
Open data in bathLeigh Dodds
409 views26 slides

More from Leigh Dodds(20)

How you (yes, you!) can contribute to open data by Leigh Dodds
How you (yes, you!) can contribute to open dataHow you (yes, you!) can contribute to open data
How you (yes, you!) can contribute to open data
Leigh Dodds3.3K views
Accessible Bath Training by Leigh Dodds
Accessible Bath TrainingAccessible Bath Training
Accessible Bath Training
Leigh Dodds221 views
Cheap bots done quick lightning talk by Leigh Dodds
Cheap bots done quick lightning talkCheap bots done quick lightning talk
Cheap bots done quick lightning talk
Leigh Dodds880 views
Open data in bath by Leigh Dodds
Open data in bathOpen data in bath
Open data in bath
Leigh Dodds409 views
Bath: Hacked Learning Night: Introduction to CartoDB by Leigh Dodds
Bath: Hacked Learning Night: Introduction to CartoDBBath: Hacked Learning Night: Introduction to CartoDB
Bath: Hacked Learning Night: Introduction to CartoDB
Leigh Dodds339 views
Dungeons and Dragons and Data by Leigh Dodds
Dungeons and Dragons and DataDungeons and Dragons and Data
Dungeons and Dragons and Data
Leigh Dodds915 views
Love the Environment Pre-Meetup by Leigh Dodds
Love the Environment Pre-MeetupLove the Environment Pre-Meetup
Love the Environment Pre-Meetup
Leigh Dodds750 views
Why I love open data and you should too by Leigh Dodds
Why I love open data and you should tooWhy I love open data and you should too
Why I love open data and you should too
Leigh Dodds795 views
Introduction to Open Data & Bath: Hacked by Leigh Dodds
Introduction to Open Data & Bath: HackedIntroduction to Open Data & Bath: Hacked
Introduction to Open Data & Bath: Hacked
Leigh Dodds590 views
Bath: Hacked: open data, the arts and cultural heritage by Leigh Dodds
Bath: Hacked: open data, the arts and cultural heritageBath: Hacked: open data, the arts and cultural heritage
Bath: Hacked: open data, the arts and cultural heritage
Leigh Dodds560 views
Introduction to Open Data & Linked Data by Leigh Dodds
Introduction to Open Data & Linked DataIntroduction to Open Data & Linked Data
Introduction to Open Data & Linked Data
Leigh Dodds661 views
Time Travelling with Open Data by Leigh Dodds
Time Travelling with Open DataTime Travelling with Open Data
Time Travelling with Open Data
Leigh Dodds540 views
Ignite for Good: Why I Love Open Data and You Should Too by Leigh Dodds
Ignite for Good: Why I Love Open Data and You Should TooIgnite for Good: Why I Love Open Data and You Should Too
Ignite for Good: Why I Love Open Data and You Should Too
Leigh Dodds1.3K views
Oil and Water: When Data Licences Don't Mix by Leigh Dodds
Oil and Water: When Data Licences Don't MixOil and Water: When Data Licences Don't Mix
Oil and Water: When Data Licences Don't Mix
Leigh Dodds1.9K views
Linked Data Patterns by Leigh Dodds
Linked Data PatternsLinked Data Patterns
Linked Data Patterns
Leigh Dodds1.3K views
Digital Grafitti for Digital Cities by Leigh Dodds
Digital Grafitti for Digital CitiesDigital Grafitti for Digital Cities
Digital Grafitti for Digital Cities
Leigh Dodds1.9K views
Layered Data: An Example by Leigh Dodds
Layered Data: An ExampleLayered Data: An Example
Layered Data: An Example
Leigh Dodds1.6K views
Data Foundations for Digital Cities by Leigh Dodds
Data Foundations for Digital CitiesData Foundations for Digital Cities
Data Foundations for Digital Cities
Leigh Dodds1.6K views

Recently uploaded

SUPPLIER SOURCING.pptx by
SUPPLIER SOURCING.pptxSUPPLIER SOURCING.pptx
SUPPLIER SOURCING.pptxangelicacueva6
16 views1 slide
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...Jasper Oosterveld
19 views49 slides
Melek BEN MAHMOUD.pdf by
Melek BEN MAHMOUD.pdfMelek BEN MAHMOUD.pdf
Melek BEN MAHMOUD.pdfMelekBenMahmoud
14 views1 slide
Unit 1_Lecture 2_Physical Design of IoT.pdf by
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdfStephenTec
12 views36 slides
Network Source of Truth and Infrastructure as Code revisited by
Network Source of Truth and Infrastructure as Code revisitedNetwork Source of Truth and Infrastructure as Code revisited
Network Source of Truth and Infrastructure as Code revisitedNetwork Automation Forum
27 views45 slides
Case Study Copenhagen Energy and Business Central.pdf by
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdfAitana
16 views3 slides

Recently uploaded(20)

ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 views
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana16 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb14 views
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn22 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc11 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2218 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10300 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman36 views
Future of AR - Facebook Presentation by ssuserb54b561
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
ssuserb54b56115 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi132 views

SPARQL Tutorial

  • 1. Data Extraction & Exploration with SPARQL & the Talis Platform
  • 2.
  • 3.
  • 4.  
  • 5.
  • 6. #An RDF triple in Turtle syntax <http://purl.org/net/schemas/space/spacecraft/1957-001B> foaf:name “Sputnik 1”.
  • 7. #An SPARQL triple pattern, with a single variable <http://purl.org/net/schemas/space/spacecraft/1957-001B> foaf:name ?name.
  • 8. #All parts of a triple pattern can be variables ?spacecraft foaf:name ?name.
  • 9.  
  • 10. #Matching labels of resources ?subject rdfs:label ?label.
  • 11.  
  • 12. #Combine triples patterns to create a graph pattern ?subject rdfs:label ?label. ?subject rdf:type space:Discipline.
  • 13. #SPARQL is based on Turtle, which allows abbreviations #e.g. predicate-object lists: ?subject rdfs:label ?label; rdf:type space:Discipline.
  • 14.  
  • 15. #Graph patterns allow us to traverse a graph ?spacecraft foaf:name “Sputnik 1”. ?launch space:spacecraft ?launch. ?launch space:launched ?launchdate.
  • 16. #Graph patterns allow us to traverse a graph ?spacecraft foaf:name “Sputnik 1” . ?launch space:spacecraft ?launch . ?launch space:launched ?launchdate .
  • 17.  
  • 18.
  • 19. #Ex. 1 #Associate URIs with prefixes PREFIX space: <http://purl.org/net/schemas/space/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> #Example of a SELECT query, retrieving 2 variables #Variables selected MUST be bound in graph pattern SELECT ?subject ?label WHERE { #This is our graph pattern ?subject rdfs:label ?label; rdf:type space:Discipline. }
  • 20. #Ex. 2 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> #Example of a SELECT query, retrieving all variables SELECT * WHERE { ?subject rdfs:label ?label; rdf:type space:Discipline. }
  • 21.
  • 22. #Ex. 3 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?image WHERE { #This pattern must be bound ?spacecraft foaf:name ?name. #Anything in this block doesn't have to be bound OPTIONAL { ?spacecraft foaf:depiction ?image. } }
  • 23.
  • 24. #Ex. 4 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: < http://xmlns.com/foaf/0.1/ > PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?subject ?displayLabel WHERE { { ?subject foaf:name ?displayLabel. } UNION { ?subject rdfs:label ?displayLabel. } }
  • 25.
  • 26. #Ex.5 #Select the uri and the mass of all the spacecraft PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: < http://xmlns.com/foaf/0.1/ > PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?spacecraft ?mass WHERE { ?spacecraft space:mass ?mass. }
  • 27. #Ex. 6 #Select the uri and the mass of all the spacecraft #with highest first PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: < http://xmlns.com/foaf/0.1/ > PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?spacecraft ?mass WHERE { ?spacecraft space:mass ?mass. } #Use an ORDER BY clause to apply a sort. Can be ASC or DESC ORDER BY DESC(?mass)‏
  • 28. #Ex. 7 #Select the uri and the mass of the 10 heaviest spacecraft PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: < http://xmlns.com/foaf/0.1/ > PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?spacecraft ?mass WHERE { ?spacecraft space:mass ?mass. } #Order by weight descending ORDER BY DESC(?mass)‏ #Limit to first ten results LIMIT 10
  • 29. #Ex. 8 #Select the uri and the mass of the 11-20 th most #heaviest spacecraft PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: < http://xmlns.com/foaf/0.1/ > PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?spacecraft ?mass WHERE { ?spacecraft space:mass ?mass. } ORDER BY DESC(?mass)‏ #Limit to ten results LIMIT 10 #Apply an offset to get next “page” OFFSET 10
  • 30.
  • 31. #Sample data for Sputnik launch <http://purl.org/net/schemas/space/launch/1957-001> rdf:type space:Launch; #Assign a datatype to the literal, to indicate it is #a date space:launched &quot;1957-10-04&quot;^^xsd:date; space:spacecraft <http://purl.org/net/schemas/space/spacecraft/1957-001B> .
  • 32. #Ex. 9 #Select name of spacecraft launched between #1 st Jan 1969 and 1 st Jan 1970 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?name WHERE { ?launch space:launched ?date; space:spacecraft ?spacecraft. ?spacecraft foaf:name ?name. FILTER (?date > &quot;1969-01-01&quot;^^xsd:date && ?date < &quot;1970-01-01&quot;^^xsd:date)‏ }
  • 33. #Ex. 10 #Select spacecraft with a mass of less than 90kg PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?spacecraft ?name WHERE { ?spacecraft foaf:name ?name; space:mass ?mass. #Note that we have to cast the data to the right type #As it is not declared in the data FILTER( xsd:double(?mass) < 90.0 )‏ }
  • 34. #Ex. 11 #Select spacecraft with a name like “ollo” PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?name WHERE { ?spacecraft foaf:name ?name. FILTER( regex(?name, “ollo”, “i” ) )‏ }
  • 35.
  • 36.
  • 37. #Ex. 12 #Select list of agencies associated with spacecraft PREFIX space: <http://purl.org/net/schemas/space/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT DISTINCT ?agency WHERE { ?spacecraft space:agency ?agency. }
  • 38.
  • 39.
  • 40. #Ex. 13 #Was there a launch on 16 th July 1969? PREFIX space: <http://purl.org/net/schemas/space/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> ASK WHERE { ?launch space:launched &quot;1969-07-16&quot;^^xsd:date. }
  • 41. DESCRIBE Generate an RDF description of a resource(s)‏
  • 42. #Ex. 14 #Describe launch(es) that occurred on 16 th July 1969 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> DESCRIBE ?launch WHERE { ?launch space:launched &quot;1969-07-16&quot;^^xsd:date. }
  • 43. #Ex. 15 #Describe spacecraft launched on 16 th July 1969 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> DESCRIBE ?spacecraft WHERE { ?launch space:launched &quot;1969-07-16&quot;^^xsd:date. ?spacecraft space:launch ?launch. }
  • 44. CONSTRUCT Create a custom RDF graph based on query criteria Can be used to transform RDF data
  • 45. #Ex. 16 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> CONSTRUCT { ?spacecraft foaf:name ?name; space:agency ?agency; space:mass ?mass. } WHERE { ?launch space:launched &quot;1969-07-16&quot;^^xsd:date. ?spacecraft space:launch ?launch; foaf:name ?name; space:agency ?agency; space:mass ?mass. }
  • 46. SELECT SQL style result set retrieval
  • 47. #Ex. 17 PREFIX space: <http://purl.org/net/schemas/space/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?agency ?mass WHERE { ?launch space:launched &quot;1969-07-16&quot;^^xsd:date. ?spacecraft space:launch ?launch; foaf:name ?name; space:agency ?agency; space:mass ?mass. }
  • 48.