SlideShare a Scribd company logo
1 of 31
SPARQL Query Language for RDF Cluj Semantic WEB meetup http://www.meetup.com/Cluj-Semantic-WEB/ presented by  Dia MIRON 17 May 2011
Introduction - SPARQL ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SPARQL – a first example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SPARQL General Form ORDER BY, DISTINCT  etc (Modifiers) e.g. ORDER BY ?name WHERE  (Query Triple Pattern) e.g. WHERE { ?planttype plant:planttype ?name } FROM  (Data Set) e.g. FROM <http://www.linkeddatatools.com/plantsdata/plants.rdf> SELECT  (Result Set) e.q. SELECT ?name PREFIX  (Namespace Prefixes) e.g. PREFIX plant:<http://www.linkeddatatools.com/plants>
Data set Example: triple data containing a variety of shrubs and plants, and their family names
Select All Data ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
And the results are… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],29.         <binding name=&quot;family&quot;> 30.            <literal>Aralianae</literal> 31.         </binding> 32.      </result> 33.      <result> 34.         <binding name=&quot;name&quot;> 35.            <uri>http://www.linkeddatatools.com/plants#velvetleaf</uri> 36.         </binding> 37.         <binding name=&quot;family&quot;> 38.            <literal>Malvaceae</literal> 39.         </binding> 40.      </result> 41.      <result> 42.         <binding name=&quot;name&quot;> 43.            <uri>http://www.linkeddatatools.com/plants#manglietia</uri> 44.         </binding> 45.         <binding name=&quot;family&quot;> 46.            <literal>Magnoliaceae</literal> 47.         </binding> 48.      </result> 49.   </results> 50.</sparql>
A more specific query ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What About CREATE, INSERT, UPDATE? ,[object Object],[object Object],[object Object]
Basic Graph Pattern  - Multiple Matches Group Graph Pattern  (set of graph patterns) also! Data Query Query Result PREFIX foaf: <http://xmlns.com/foaf/0.1/>  SELECT ?name ?mbox  WHERE  { ?x foaf:name ?name .  ?x foaf:mbox ?mbox }   @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Johnny Lee Outlaw&quot; .  _:a foaf:mbox <mailto:jlow@example.com> .  _:b foaf:name &quot;Peter Goodguy&quot; .  _:b foaf:mbox <mailto:peter@example.org> . <mailto:peter@example.org> &quot;Peter Goodguy&quot; <mailto:jlow@example.com> &quot;Johnny Lee Outlaw&quot; mbox name
Basic Graph Pattern  - Blank Nodes Data Query Query Result PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?x ?name  WHERE { ?x foaf:name ?name }  @prefix foaf: <http://xmlns.com/foaf/0.1/> .  _:a foaf:name &quot;Alice&quot; .  _:b foaf:name &quot;Bob&quot; .  “ Bob” _:d “ Alice“ _:c name x
Value Constraints Data Query Query Result PREFIX dc: <http://purl.org/dc/elements/1.1/>  PREFIX ns: <http://example.org/ns#>  SELECT ?title ?price  WHERE { ?x ns:price ?price .  FILTER ?price < 30 .  ?x dc:title ?title . }  @prefix dc: <http://purl.org/dc/elements/1.1/> . @prefix : <http://example.org/book/> . @prefix ns: <http://example.org/ns#> .  :book1 dc:title &quot;SPARQL Tutorial&quot; .  :book1 ns:price 42 .  :book2 dc:title &quot;The Semantic Web&quot; .  :book2 ns:price 23  .  23 &quot;The Semantic Web&quot;  price title
Optional graph patterns Data Query Query Result PREFIX dc: <http://purl.org/dc/elements/1.1/>  PREFIX ns: <http://example.org/ns#>  SELECT ?title ?price  WHERE { ?x dc:title ?title .  OPTIONAL { ?x ns:price ?price .  FILTER ?price < 30 }} @prefix dc: <http://purl.org/dc/elements/1.1/> .  @prefix : <http://example.org/book/> . @prefix ns: <http://example.org/ns#> .  :book1 dc:title &quot;SPARQL Tutorial&quot; .  :book1 ns:price 42 .  :book2 dc:title &quot;The Semantic Web&quot; . :book2 ns:price 23  .  “ SPARQL Tutorial“ 23 &quot;The Semantic Web&quot;  price title
Multiple Optional Blocks Data Query Query Result PREFIX foaf: <http://xmlns.com/foaf/0.1/>  SELECT ?name ?mbox ?hpage  WHERE { ?x foaf:name ?name .  OPTIONAL { ?x foaf:mbox ?mbox }.  OPTIONAL { ?x foaf:homepage ?hpage } }  @prefix foaf: <http://xmlns.com/foaf/0.1/> .  @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .  _:a foaf:name &quot;Alice&quot; .  _:a foaf:homepage <http://work.example.org/alice/> .  _:b foaf:name &quot;Bob&quot; .  _:b foaf:mbox <mailto:bob@work.example> .  <mailto:bob@example.com>  “ Bob“ <http://work.example.org/alice/>  “ Alice“ hpage Mbox name
Alternative Graph Patterns Data Query Query Result PREFIX dc10: <http://purl.org/dc/elements/1.0/>  PREFIX dc11: <http://purl.org/dc/elements/1.1/> SELECT ?x ?y  WHERE { { ?book dc10:title ?x } UNION { ?book dc11:title ?y } }  @prefix dc10: <http://purl.org/dc/elements/1.0/> . @prefix dc11: <http://purl.org/dc/elements/1.1/> .  _:a dc10:title &quot;SPARQL Query Language Tutorial&quot; .  _:b dc11:title &quot;SPARQL Protocol Tutorial&quot; .  _:c dc10:title &quot;SPARQL&quot; .  _:c dc11:title &quot;SPARQL (updated)&quot; .  y x &quot;SPARQL (updated)&quot;  &quot;SPARQL Query Language Tutorial&quot;  &quot;SPARQL&quot;  &quot;SPARQL Protocol Tutorial&quot;
RDF Dataset ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
RDF Dataset- T he Relationship between Named and Background Graphs (I) #  Background graph   @prefix dc: <http://purl.org/dc/elements/1.1/> .  <http://example.org/bob> dc:publisher &quot;Bob&quot; .  <http://example.org/alice> dc:publisher &quot;Alice&quot; .  #  Graph: http://example.org/bob   @prefix foaf: <http://xmlns.com/foaf/0.1/> .  _:a foaf:name &quot;Bob&quot; .  _:a foaf:mbox <mailto:bob@oldcorp.example.org> . #  Graph: http://example.org/alice   @prefix foaf: <http://xmlns.com/foaf/0.1/> .  _:a foaf:name &quot;Alice&quot; .  _:a foaf:mbox <mailto:alice@work.example.org>  .
RDF Dataset- T he Relationship between Named and Background Graphs (II) #  Background graph   @prefix foaf: <http://xmlns.com/foaf/0.1/>   .  _:x foaf:name &quot;Bob&quot; .  _:x foaf:mbox <mailto:bob@oldcorp.example.org> . _:y foaf:name &quot;Alice&quot; .  _:y foaf:mbox <mailto:alice@work.example.org> .  #  Graph: http://example.org/bob   @prefix foaf: <http://xmlns.com/foaf/0.1/> .  _:a foaf:name &quot;Bob&quot; .  _:a foaf:mbox <mailto:bob@oldcorp.example.org> . #  Graph: http://example.org/alice   @prefix foaf: <http://xmlns.com/foaf/0.1/> .  _:a foaf:name &quot;Alice&quot; .  _:a foaf:mbox <mailto:alice@work.example.org>  .
Querying the Dataset # Graph: http://example.org/foaf/aliceFoaf  @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .  @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .  _:a foaf:name &quot;Alice&quot; .  _:a foaf:mbox <mailto:alice@work.example> .  _:a foaf:knows _:b .  _:b rdfs:seeAlso <http://example.org/foaf/bobFoaf> .  <http://example.org/foaf/bobFoaf> rdf:type foaf:PersonalProfileDocument .  _:b foaf:name &quot;Bob&quot; .  _:b foaf:mbox <mailto:bob@work.example> .  _:b foaf:age 32 .  # Graph: http://example.org/foaf/bobFoaf  @prefix foaf: <http://xmlns.com/foaf/0.1/> .  @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .  @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . _:1 foaf:mbox <mailto:bob@work.example> . _:1 rdfs:seeAlso <http://example.org/foaf/bobFoaf> .  _:1 foaf:age 35 .  <http://example.org/foaf/bobFoaf> rdf:type foaf:PersonalProfileDocument .
Querying the Dataset  - Accessing Graph Labels PREFIX foaf: <http://xmlns.com/foaf/0.1/>  SELECT ?src ?bobAge  WHERE { GRAPH ?src  { ?x foaf:mbox <mailto:bob@work.example> .  ?x foaf:age ?bobAge } } 35  <http://example.org/foaf/bobFoaf>  32  <http://example.org/foaf/aliceFoaf>  bobAge src
Querying the Dataset  -  Restricting by Graph Label  PREFIX foaf: <http://xmlns.com/foaf/0.1/>  PREFIX data: <http://example.org/foaf/>  SELECT ?age  WHERE  { GRAPH data:bobFoaf  {  ?x foaf:mbox <mailto:bob@work.example> .  ?x foaf:age ?age  }  } 35 age
Querying the Dataset  -  Restricting via Query Pattern  PREFIX data: <http://example.org/foaf/>  PREFIX foaf: <http://xmlns.com/foaf/0.1/>  PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>  SELECT ?mbox ?age ?ppd  WHERE  { GRAPH data:aliceFoaf  { ?alice foaf:mbox <mailto:alice@work.example> ; foaf:knows ?whom .  ?whom foaf:mbox ?mbox ;  rdfs:seeAlso ?ppd .  ?ppd a foaf:PersonalProfileDocument . } .  GRAPH ?ppd { ?w foaf:mbox ?mbox ;  foaf:age ?age } }  <http://example.org/foaf/bobFoaf>  35  <mailto:bob@work.example>  ppd age mbox
Query Execution and Ordering  ,[object Object],[object Object],[object Object]
Query forms:   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONSTRUCT Examples(I) PREFIX foaf: <http://xmlns.com/foaf/0.1/>  PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>  CONSTRUCT { <http://example.org/person#Alice> vcard:FN ?name }  WHERE { ?x foaf:name ?name }  @prefix foaf: <http://xmlns.com/foaf/0.1/> .  _:a foaf:name &quot;Alice&quot; . _:a foaf:mbox <mailto:alice@example.org> . @prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>. <http://example.org/person#Alice> vcard:FN &quot;Alice&quot; . #extracting a whole graph from the target RDF dataset CONSTRUCT { ?s ?p ?o }  WHERE { GRAPH <http://example.org/myGraph> { ?s ?p ?o } . }
CONSTRUCT Examples(II) accesing a graph conditional on other information contained in the metadata about named graphs in the dataset PREFIX dc: <http://purl.org/dc/elements/1.1/>  PREFIX app: <http://example.org/ns#>  CONSTRUCT { ?s ?p ?o }  WHERE { GRAPH ?g { ?s ?p ?o } .  { ?g dc:publisher <http://www.w3.org/> } .  { ?g dc:date ?date } .  FILTER app:myDate(?date) > &quot;2005-02-8T00:00:00Z&quot;^^xsd:dateTime.  }
DESCRIBE PREFIX ent: <http://myorg.example/employees#> DESCRIBE ?x WHERE { ?x ent:employeeId &quot;1234&quot; }  @prefix foaf: <http://xmlns.com/foaf/0.1/> .  @prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0> .  @prefix myOrg: <http://myorg.example/employees#> . _:a myOrg:employeeId &quot;1234&quot; ;  foaf:mbox_sha1sum &quot;ABCD1234&quot; ;  vcard:N [ vcard:Family &quot;Smith&quot; ;  vcard:Given &quot;John&quot; ] .  foaf:mbox_sha1sum rdf:type owl:InverseFunctionalProperty .
ASK @prefix foaf: <http://xmlns.com/foaf/0.1/> .  @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .  _:a foaf:name &quot;Alice&quot; .  _:a foaf:homepage <http://work.example.org/alice/> .  _:b foaf:name &quot;Bob&quot; .  _:b foaf:mbox <mailto:bob@work.example> . PREFIX foaf: <http://xmlns.com/foaf/0.1/>  ASK { ?x foaf:name &quot;Alice&quot; } .
Testing Values ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Support for SPARQL ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Contact ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)
andyseaborne
 
WebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPediaWebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPedia
Katrien Verbert
 
Federation and Navigation in SPARQL 1.1
Federation and Navigation in SPARQL 1.1Federation and Navigation in SPARQL 1.1
Federation and Navigation in SPARQL 1.1
net2-project
 
Mon norton tut_queryinglinkeddata02
Mon norton tut_queryinglinkeddata02Mon norton tut_queryinglinkeddata02
Mon norton tut_queryinglinkeddata02
eswcsummerschool
 
SWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mappingSWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mapping
Mariano Rodriguez-Muro
 

What's hot (20)

SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)
 
Linking the world with Python and Semantics
Linking the world with Python and SemanticsLinking the world with Python and Semantics
Linking the world with Python and Semantics
 
SPARQL 1.1 Status
SPARQL 1.1 StatusSPARQL 1.1 Status
SPARQL 1.1 Status
 
Graph Data -- RDF and Property Graphs
Graph Data -- RDF and Property GraphsGraph Data -- RDF and Property Graphs
Graph Data -- RDF and Property Graphs
 
WebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPediaWebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPedia
 
4 sw architectures and sparql
4 sw architectures and sparql4 sw architectures and sparql
4 sw architectures and sparql
 
RDF Tutorial - SPARQL 20091031
RDF Tutorial - SPARQL 20091031RDF Tutorial - SPARQL 20091031
RDF Tutorial - SPARQL 20091031
 
Two graph data models : RDF and Property Graphs
Two graph data models : RDF and Property GraphsTwo graph data models : RDF and Property Graphs
Two graph data models : RDF and Property Graphs
 
NoSQL and Triple Stores
NoSQL and Triple StoresNoSQL and Triple Stores
NoSQL and Triple Stores
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 
Aidan's PhD Viva
Aidan's PhD VivaAidan's PhD Viva
Aidan's PhD Viva
 
Challenges and applications of RDF shapes
Challenges and applications of RDF shapesChallenges and applications of RDF shapes
Challenges and applications of RDF shapes
 
RDF Data Model
RDF Data ModelRDF Data Model
RDF Data Model
 
Federation and Navigation in SPARQL 1.1
Federation and Navigation in SPARQL 1.1Federation and Navigation in SPARQL 1.1
Federation and Navigation in SPARQL 1.1
 
SWT Lecture Session 10 R2RML Part 1
SWT Lecture Session 10 R2RML Part 1SWT Lecture Session 10 R2RML Part 1
SWT Lecture Session 10 R2RML Part 1
 
SWT Lecture Session 3 - SPARQL
SWT Lecture Session 3 - SPARQLSWT Lecture Session 3 - SPARQL
SWT Lecture Session 3 - SPARQL
 
Mon norton tut_queryinglinkeddata02
Mon norton tut_queryinglinkeddata02Mon norton tut_queryinglinkeddata02
Mon norton tut_queryinglinkeddata02
 
SWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mappingSWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mapping
 
Getty Vocabulary Program LOD: Ontologies and Semantic Representation
Getty Vocabulary Program LOD: Ontologies and Semantic RepresentationGetty Vocabulary Program LOD: Ontologies and Semantic Representation
Getty Vocabulary Program LOD: Ontologies and Semantic Representation
 
SWT Lecture Session 11 - R2RML part 2
SWT Lecture Session 11 - R2RML part 2SWT Lecture Session 11 - R2RML part 2
SWT Lecture Session 11 - R2RML part 2
 

Viewers also liked

malagigi
malagigimalagigi
malagigi
uokko
 
Salute e scuola
Salute e scuolaSalute e scuola
Salute e scuola
sepulvi
 
08 newton's law of motion
08 newton's law of motion08 newton's law of motion
08 newton's law of motion
IZZUDIN IBRAHIM
 
Mangan i hrom
Mangan i hrom Mangan i hrom
Mangan i hrom
vukpro97
 
Guia de_derecho_romano
Guia  de_derecho_romanoGuia  de_derecho_romano
Guia de_derecho_romano
Mariana Muñoz
 
Parní lokomotivy čsd
Parní lokomotivy čsdParní lokomotivy čsd
Parní lokomotivy čsd
corvik
 

Viewers also liked (20)

SQL2SPARQL
SQL2SPARQLSQL2SPARQL
SQL2SPARQL
 
[DSBW Spring 2010] Unit 10: XML and Web And beyond
[DSBW Spring 2010] Unit 10: XML and Web And beyond[DSBW Spring 2010] Unit 10: XML and Web And beyond
[DSBW Spring 2010] Unit 10: XML and Web And beyond
 
New Yarns and Funny Jokes
New Yarns and Funny JokesNew Yarns and Funny Jokes
New Yarns and Funny Jokes
 
Trafiklab Meetup 20161206
Trafiklab Meetup 20161206Trafiklab Meetup 20161206
Trafiklab Meetup 20161206
 
malagigi
malagigimalagigi
malagigi
 
Salute e scuola
Salute e scuolaSalute e scuola
Salute e scuola
 
Brachyura
BrachyuraBrachyura
Brachyura
 
Meducate® GI Patient Education Brochures
Meducate® GI Patient Education BrochuresMeducate® GI Patient Education Brochures
Meducate® GI Patient Education Brochures
 
08 newton's law of motion
08 newton's law of motion08 newton's law of motion
08 newton's law of motion
 
Mandible # brief
Mandible # brief Mandible # brief
Mandible # brief
 
Mangan i hrom
Mangan i hrom Mangan i hrom
Mangan i hrom
 
Guia de_derecho_romano
Guia  de_derecho_romanoGuia  de_derecho_romano
Guia de_derecho_romano
 
Malingering and how to spot it
Malingering and how to spot itMalingering and how to spot it
Malingering and how to spot it
 
carnivora dan proboscidea
carnivora dan proboscidea carnivora dan proboscidea
carnivora dan proboscidea
 
Parní lokomotivy čsd
Parní lokomotivy čsdParní lokomotivy čsd
Parní lokomotivy čsd
 
Te Reo o Ngatihine
Te Reo o NgatihineTe Reo o Ngatihine
Te Reo o Ngatihine
 
MAGHRENOV deliverable 2.1: Roadmap of an EU-MPC entrepreneurial education pro...
MAGHRENOV deliverable 2.1: Roadmap of an EU-MPC entrepreneurial education pro...MAGHRENOV deliverable 2.1: Roadmap of an EU-MPC entrepreneurial education pro...
MAGHRENOV deliverable 2.1: Roadmap of an EU-MPC entrepreneurial education pro...
 
Subphylum mandibulata (By: J.Q)
Subphylum mandibulata (By: J.Q)Subphylum mandibulata (By: J.Q)
Subphylum mandibulata (By: J.Q)
 
Martensitic stainless steel
Martensitic stainless steel Martensitic stainless steel
Martensitic stainless steel
 
E-nano Newsletter 32
E-nano Newsletter 32E-nano Newsletter 32
E-nano Newsletter 32
 

Similar to From SQL to SPARQL

Creating APIs over RDF
Creating APIs over RDFCreating APIs over RDF
Creating APIs over RDF
Leigh Dodds
 
Creating APIs over RDF
Creating APIs over RDFCreating APIs over RDF
Creating APIs over RDF
Leigh Dodds
 
Creating Linked Data 2/5 Semtech2011
Creating Linked Data 2/5 Semtech2011Creating Linked Data 2/5 Semtech2011
Creating Linked Data 2/5 Semtech2011
Juan Sequeda
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQL
Emanuele Della Valle
 
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
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ák
 
Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP
yucefmerhi
 
Architecting Web Services
Architecting Web ServicesArchitecting Web Services
Architecting Web Services
Lorna Mitchell
 

Similar to From SQL to SPARQL (20)

The Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLThe Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQL
 
Creating APIs over RDF
Creating APIs over RDFCreating APIs over RDF
Creating APIs over RDF
 
Creating APIs over RDF
Creating APIs over RDFCreating APIs over RDF
Creating APIs over RDF
 
Sparql a simple knowledge query
Sparql  a simple knowledge querySparql  a simple knowledge query
Sparql a simple knowledge query
 
SPARQLing Services
SPARQLing ServicesSPARQLing Services
SPARQLing Services
 
Gist od2-feb-2011
Gist od2-feb-2011Gist od2-feb-2011
Gist od2-feb-2011
 
Exploiter le Web Semantic, le comprendre et y contribuer
Exploiter le Web Semantic, le comprendre et y contribuerExploiter le Web Semantic, le comprendre et y contribuer
Exploiter le Web Semantic, le comprendre et y contribuer
 
Building linked data apps
Building linked data appsBuilding linked data apps
Building linked data apps
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 
Creating Linked Data 2/5 Semtech2011
Creating Linked Data 2/5 Semtech2011Creating Linked Data 2/5 Semtech2011
Creating Linked Data 2/5 Semtech2011
 
W3 C Specification For Interoperability And Accessibility For Ajax, Dhtml, Xm...
W3 C Specification For Interoperability And Accessibility For Ajax, Dhtml, Xm...W3 C Specification For Interoperability And Accessibility For Ajax, Dhtml, Xm...
W3 C Specification For Interoperability And Accessibility For Ajax, Dhtml, Xm...
 
Semantic Web
Semantic WebSemantic Web
Semantic Web
 
Web 3 0
Web 3 0Web 3 0
Web 3 0
 
Visualize open data with Plone - eea.daviz PLOG 2013
Visualize open data with Plone - eea.daviz PLOG 2013Visualize open data with Plone - eea.daviz PLOG 2013
Visualize open data with Plone - eea.daviz PLOG 2013
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQL
 
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
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
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 
Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP
 
The Web, one huge database ...
The Web, one huge database ...The Web, one huge database ...
The Web, one huge database ...
 
Architecting Web Services
Architecting Web ServicesArchitecting Web Services
Architecting Web Services
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

From SQL to SPARQL

  • 1. SPARQL Query Language for RDF Cluj Semantic WEB meetup http://www.meetup.com/Cluj-Semantic-WEB/ presented by Dia MIRON 17 May 2011
  • 2.
  • 3.
  • 4. SPARQL General Form ORDER BY, DISTINCT etc (Modifiers) e.g. ORDER BY ?name WHERE (Query Triple Pattern) e.g. WHERE { ?planttype plant:planttype ?name } FROM (Data Set) e.g. FROM <http://www.linkeddatatools.com/plantsdata/plants.rdf> SELECT (Result Set) e.q. SELECT ?name PREFIX (Namespace Prefixes) e.g. PREFIX plant:<http://www.linkeddatatools.com/plants>
  • 5. Data set Example: triple data containing a variety of shrubs and plants, and their family names
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. Basic Graph Pattern - Multiple Matches Group Graph Pattern (set of graph patterns) also! Data Query Query Result PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?mbox WHERE { ?x foaf:name ?name . ?x foaf:mbox ?mbox } @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Johnny Lee Outlaw&quot; . _:a foaf:mbox <mailto:jlow@example.com> . _:b foaf:name &quot;Peter Goodguy&quot; . _:b foaf:mbox <mailto:peter@example.org> . <mailto:peter@example.org> &quot;Peter Goodguy&quot; <mailto:jlow@example.com> &quot;Johnny Lee Outlaw&quot; mbox name
  • 11. Basic Graph Pattern - Blank Nodes Data Query Query Result PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?x ?name WHERE { ?x foaf:name ?name } @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Alice&quot; . _:b foaf:name &quot;Bob&quot; . “ Bob” _:d “ Alice“ _:c name x
  • 12. Value Constraints Data Query Query Result PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX ns: <http://example.org/ns#> SELECT ?title ?price WHERE { ?x ns:price ?price . FILTER ?price < 30 . ?x dc:title ?title . } @prefix dc: <http://purl.org/dc/elements/1.1/> . @prefix : <http://example.org/book/> . @prefix ns: <http://example.org/ns#> . :book1 dc:title &quot;SPARQL Tutorial&quot; . :book1 ns:price 42 . :book2 dc:title &quot;The Semantic Web&quot; . :book2 ns:price 23 . 23 &quot;The Semantic Web&quot; price title
  • 13. Optional graph patterns Data Query Query Result PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX ns: <http://example.org/ns#> SELECT ?title ?price WHERE { ?x dc:title ?title . OPTIONAL { ?x ns:price ?price . FILTER ?price < 30 }} @prefix dc: <http://purl.org/dc/elements/1.1/> . @prefix : <http://example.org/book/> . @prefix ns: <http://example.org/ns#> . :book1 dc:title &quot;SPARQL Tutorial&quot; . :book1 ns:price 42 . :book2 dc:title &quot;The Semantic Web&quot; . :book2 ns:price 23 . “ SPARQL Tutorial“ 23 &quot;The Semantic Web&quot; price title
  • 14. Multiple Optional Blocks Data Query Query Result PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?mbox ?hpage WHERE { ?x foaf:name ?name . OPTIONAL { ?x foaf:mbox ?mbox }. OPTIONAL { ?x foaf:homepage ?hpage } } @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . _:a foaf:name &quot;Alice&quot; . _:a foaf:homepage <http://work.example.org/alice/> . _:b foaf:name &quot;Bob&quot; . _:b foaf:mbox <mailto:bob@work.example> . <mailto:bob@example.com> “ Bob“ <http://work.example.org/alice/> “ Alice“ hpage Mbox name
  • 15. Alternative Graph Patterns Data Query Query Result PREFIX dc10: <http://purl.org/dc/elements/1.0/> PREFIX dc11: <http://purl.org/dc/elements/1.1/> SELECT ?x ?y WHERE { { ?book dc10:title ?x } UNION { ?book dc11:title ?y } } @prefix dc10: <http://purl.org/dc/elements/1.0/> . @prefix dc11: <http://purl.org/dc/elements/1.1/> . _:a dc10:title &quot;SPARQL Query Language Tutorial&quot; . _:b dc11:title &quot;SPARQL Protocol Tutorial&quot; . _:c dc10:title &quot;SPARQL&quot; . _:c dc11:title &quot;SPARQL (updated)&quot; . y x &quot;SPARQL (updated)&quot; &quot;SPARQL Query Language Tutorial&quot; &quot;SPARQL&quot; &quot;SPARQL Protocol Tutorial&quot;
  • 16.
  • 17. RDF Dataset- T he Relationship between Named and Background Graphs (I) # Background graph @prefix dc: <http://purl.org/dc/elements/1.1/> . <http://example.org/bob> dc:publisher &quot;Bob&quot; . <http://example.org/alice> dc:publisher &quot;Alice&quot; . # Graph: http://example.org/bob @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Bob&quot; . _:a foaf:mbox <mailto:bob@oldcorp.example.org> . # Graph: http://example.org/alice @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Alice&quot; . _:a foaf:mbox <mailto:alice@work.example.org> .
  • 18. RDF Dataset- T he Relationship between Named and Background Graphs (II) # Background graph @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:x foaf:name &quot;Bob&quot; . _:x foaf:mbox <mailto:bob@oldcorp.example.org> . _:y foaf:name &quot;Alice&quot; . _:y foaf:mbox <mailto:alice@work.example.org> . # Graph: http://example.org/bob @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Bob&quot; . _:a foaf:mbox <mailto:bob@oldcorp.example.org> . # Graph: http://example.org/alice @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Alice&quot; . _:a foaf:mbox <mailto:alice@work.example.org> .
  • 19. Querying the Dataset # Graph: http://example.org/foaf/aliceFoaf @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . _:a foaf:name &quot;Alice&quot; . _:a foaf:mbox <mailto:alice@work.example> . _:a foaf:knows _:b . _:b rdfs:seeAlso <http://example.org/foaf/bobFoaf> . <http://example.org/foaf/bobFoaf> rdf:type foaf:PersonalProfileDocument . _:b foaf:name &quot;Bob&quot; . _:b foaf:mbox <mailto:bob@work.example> . _:b foaf:age 32 . # Graph: http://example.org/foaf/bobFoaf @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . _:1 foaf:mbox <mailto:bob@work.example> . _:1 rdfs:seeAlso <http://example.org/foaf/bobFoaf> . _:1 foaf:age 35 . <http://example.org/foaf/bobFoaf> rdf:type foaf:PersonalProfileDocument .
  • 20. Querying the Dataset - Accessing Graph Labels PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?src ?bobAge WHERE { GRAPH ?src { ?x foaf:mbox <mailto:bob@work.example> . ?x foaf:age ?bobAge } } 35 <http://example.org/foaf/bobFoaf> 32 <http://example.org/foaf/aliceFoaf> bobAge src
  • 21. Querying the Dataset - Restricting by Graph Label PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX data: <http://example.org/foaf/> SELECT ?age WHERE { GRAPH data:bobFoaf { ?x foaf:mbox <mailto:bob@work.example> . ?x foaf:age ?age } } 35 age
  • 22. Querying the Dataset - Restricting via Query Pattern PREFIX data: <http://example.org/foaf/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?mbox ?age ?ppd WHERE { GRAPH data:aliceFoaf { ?alice foaf:mbox <mailto:alice@work.example> ; foaf:knows ?whom . ?whom foaf:mbox ?mbox ; rdfs:seeAlso ?ppd . ?ppd a foaf:PersonalProfileDocument . } . GRAPH ?ppd { ?w foaf:mbox ?mbox ; foaf:age ?age } } <http://example.org/foaf/bobFoaf> 35 <mailto:bob@work.example> ppd age mbox
  • 23.
  • 24.
  • 25. CONSTRUCT Examples(I) PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> CONSTRUCT { <http://example.org/person#Alice> vcard:FN ?name } WHERE { ?x foaf:name ?name } @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Alice&quot; . _:a foaf:mbox <mailto:alice@example.org> . @prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>. <http://example.org/person#Alice> vcard:FN &quot;Alice&quot; . #extracting a whole graph from the target RDF dataset CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/myGraph> { ?s ?p ?o } . }
  • 26. CONSTRUCT Examples(II) accesing a graph conditional on other information contained in the metadata about named graphs in the dataset PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX app: <http://example.org/ns#> CONSTRUCT { ?s ?p ?o } WHERE { GRAPH ?g { ?s ?p ?o } . { ?g dc:publisher <http://www.w3.org/> } . { ?g dc:date ?date } . FILTER app:myDate(?date) > &quot;2005-02-8T00:00:00Z&quot;^^xsd:dateTime. }
  • 27. DESCRIBE PREFIX ent: <http://myorg.example/employees#> DESCRIBE ?x WHERE { ?x ent:employeeId &quot;1234&quot; } @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0> . @prefix myOrg: <http://myorg.example/employees#> . _:a myOrg:employeeId &quot;1234&quot; ; foaf:mbox_sha1sum &quot;ABCD1234&quot; ; vcard:N [ vcard:Family &quot;Smith&quot; ; vcard:Given &quot;John&quot; ] . foaf:mbox_sha1sum rdf:type owl:InverseFunctionalProperty .
  • 28. ASK @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . _:a foaf:name &quot;Alice&quot; . _:a foaf:homepage <http://work.example.org/alice/> . _:b foaf:name &quot;Bob&quot; . _:b foaf:mbox <mailto:bob@work.example> . PREFIX foaf: <http://xmlns.com/foaf/0.1/> ASK { ?x foaf:name &quot;Alice&quot; } .
  • 29.
  • 30.
  • 31.