SlideShare a Scribd company logo
1 of 13
Download to read offline
SPARQL 1.1
Query Language

SPARQL 1.1 Query
Overview
•
•
•
•
•
•
•
•

SPARQL 1.1 Overview
Aggregates
Subqueries
Negation
Expressions in SELECT
Property Paths
New Built-ins
Short form CONSTRUCT

SPARQL 1.1 Query

#2
What is SPARQL?
• SPARQL was a query language for RDF data
– http://www.w3.org/TR/rdf-sparql-query/

• And a protocol
– http://www.w3.org/TR/rdf-sparql-protocol/

• Designed around graph patterns
– Graph patterns use Turtle syntax

• SPARQL 1.1 introduces:
–
–
–
–

Query extensions (covered here)
Protocol extensions and a (RESTful) graph store protocol
Updates (covered next)
Service descriptions and federation

SPARQL 1.1 Query

#3
SPARQL 1.1 Query Extensions
• SPARQL 1.1 adds the following new features
(http://www.w3.org/TR/sparql11-query)
–
Aggregates

–
–
–
–
–
–
–

Subqueries
Negation
Expressions in the SELECT clause
Property Paths
Assignment
A short form for CONSTRUCT
An expanded set of functions and operators

SPARQL 1.1 Query

#4
Aggregates
• Aggregates allow computation of values using:
– COUNT, SUM, MIN, MAX, AVG, GROUP_CONCAT and SAMPLE

• Built around the GROUP BY operator
• For example computing popularity in a social graph:
SELECT ?person (COUNT(?someone) AS ?popularity)
WHERE {?someone foaf:knows ?person}
GROUP BY ?person

• Prune at group level (cf. FILTER) using HAVING, e.g.:
GROUP BY ?person HAVING (COUNT(?someone) > 300)
SPARQL 1.1 Query

#5
Subqueries
• Subqueries allow bindings from one (inner) query to be
used in another (outer) query
• For example, to compute whom the most popular
person in a social graph knows:
SELECT ?friend
WHERE {?popular foaf:knows ?friend.
{SELECT ?popular (COUNT(?someone) AS ?popularity)
WHERE {?someone foaf:knows ?popular}
GROUP BY ?popular
ORDER BY DESC (?popularity)
LIMIT 1}}
SPARQL 1.1 Query

#6
Negation 1/2
• SPARQL 1.0 negation was limited, applying only to
simple FILTER expressions
• SPARQL 1.1 introduces EXISTS, allowing graph
matching (without binding)
• For example, to compute email addresses of people
who know no Barrys (!):
SELECT ?email
WHERE {?sad foaf:mbox ?email .
FILTER NOT EXISTS {?sad foaf:knows ?barry.
{?barry foaf:givenName "Barry"}
UNION {?barry foaf:firstName "Barry"}}
SPARQL 1.1 Query

#7
Negation 2/2
• SPARQL 1.0 negation was limited, applying only to
simple FILTER expressions
• SPARQL 1.1 also introduces MINUS, allowing explicit
removal of triples (according to another match)
• For example, to compute people who know Barrys
other than Barry Norton:
SELECT DISTINCT ?person WHERE
{?person foaf:knows ?barry.
?barry foaf:givenName "Barry".
MINUS {?person foaf:knows
[foaf:mbox <mailto:barry.norton@ontotext.com>]}}
SPARQL 1.1 Query

#8
Expressions in SELECT (Projection) Clauses
• SPARQL 1.0 allows built-in functions, etc., to be used in
FILTER
• SPARQL 1.1 allows their use in (the projection onto)
variables in the head of the query
• For example, to glue together names:
SELECT (CONCAT(?forename, " ", ?surname) AS ?name)
WHERE {{{?person foaf:givenName ?forename}
UNION {?person foaf:firstName ?forename}}.
{{?person foaf:familyName ?surname}
UNION {?person foaf:lastName ?surname}}}

SPARQL 1.1 Query

#9
Property Paths 1/2
• SPARQL 1.0 builds graph patterns from triple patterns,
where resources are separated in the graph by one arc
• SPARQL 1.1 generalises on triple patterns to model
resources separated by paths of arbitrary length
• Paths are specified using the following grammar that
follows
• Example: any member of an RDF List:
?list rdf:rest*/rdf:first ?element

SPARQL 1.1 Query

#10
Property Paths 2/2

• Example: anyone in social graph of ?p knows a Barry:
?p {foaf:knows | ^foaf:knows}* /
(foaf:givenName | foaf:firstName) "Barry"
SPARQL 1.1 Query

#11
New Built-ins
• SPARQL 1.1 supports a wider set of built-ins than
SPARQL 1.0, introducing:
– Maths: ABS (absolute value), ROUND/CEIL /FLOOR(rounding),
RAND (random), isNUMERIC
– Strings: CONCAT, CONTAINS, SUBSTR, STRLEN, UCASE, LCASE
– Dates: YEAR, MONTH, DAY, HOURS, MINUTES, SECONDS,
TIMEZONE/TZ (timezone as XML or literal), NOW
– Hashes: MD5 , SHA1, SHA224, SHA256, SHA384, SHA512
– Enumeration: IN, NOT IN
– Control: IF, COALESCE
– Identifiers: ENCODE_FOR_URI, IRI/URI, BNODE (create a new
blank node, can be with parameter)

SPARQL 1.1 Query

#12
Short Form CONSTRUCT
• In order to query for a subgraph, without change, it is
no longer necessary to repeat the graph pattern
• Example:
CONSTRUCT WHERE
{?barry foaf:givenName "Barry";
?p ?o}

SPARQL 1.1 Query

#13

More Related Content

Similar to ESWC SS 2012 - Monday Tutorial 2 Barry Norton: SPARQL 1.1 Query Language

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
 
SPARQL and SQL: technical aspects and synergy
SPARQL and SQL: technical aspects and synergySPARQL and SQL: technical aspects and synergy
SPARQL and SQL: technical aspects and synergy
Yannis Kalfoglou
 
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
 
SPARQL in the Semantic Web
SPARQL in the Semantic WebSPARQL in the Semantic Web
SPARQL in the Semantic Web
Jan Beeck
 
Creating web applications with LODSPeaKr
Creating web applications with LODSPeaKrCreating web applications with LODSPeaKr
Creating web applications with LODSPeaKr
Alvaro Graves
 
A hands on overview of the semantic web
A hands on overview of the semantic webA hands on overview of the semantic web
A hands on overview of the semantic web
Marakana Inc.
 
ESWC SS 2012 - Monday Tutorial 2 Barry Norton: Introduction to SPARQL
ESWC SS 2012 - Monday Tutorial 2 Barry Norton: Introduction to SPARQLESWC SS 2012 - Monday Tutorial 2 Barry Norton: Introduction to SPARQL
ESWC SS 2012 - Monday Tutorial 2 Barry Norton: Introduction to SPARQL
eswcsummerschool
 

Similar to ESWC SS 2012 - Monday Tutorial 2 Barry Norton: SPARQL 1.1 Query Language (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)
 
SPARQL 1.1 Status
SPARQL 1.1 StatusSPARQL 1.1 Status
SPARQL 1.1 Status
 
What;s Coming In SPARQL2?
What;s Coming In SPARQL2?What;s Coming In SPARQL2?
What;s Coming In SPARQL2?
 
SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)
 
SPARQL-DL - Theory & Practice
SPARQL-DL - Theory & PracticeSPARQL-DL - Theory & Practice
SPARQL-DL - Theory & Practice
 
The Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLThe Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQL
 
Querying Linked Data
Querying Linked DataQuerying Linked Data
Querying Linked Data
 
SPARQL and SQL: technical aspects and synergy
SPARQL and SQL: technical aspects and synergySPARQL and SQL: technical aspects and synergy
SPARQL and SQL: technical aspects and synergy
 
Search Engine Building with Lucene and Solr (So Code Camp San Diego 2014)
Search Engine Building with Lucene and Solr (So Code Camp San Diego 2014)Search Engine Building with Lucene and Solr (So Code Camp San Diego 2014)
Search Engine Building with Lucene and Solr (So Code Camp San Diego 2014)
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQL
 
Sparql
SparqlSparql
Sparql
 
SPARQL in the Semantic Web
SPARQL in the Semantic WebSPARQL in the Semantic Web
SPARQL in the Semantic Web
 
SWT Lecture Session 3 - SPARQL
SWT Lecture Session 3 - SPARQLSWT Lecture Session 3 - SPARQL
SWT Lecture Session 3 - SPARQL
 
Table functions - Planboard Symposium 2013
Table functions - Planboard Symposium 2013Table functions - Planboard Symposium 2013
Table functions - Planboard Symposium 2013
 
Creating web applications with LODSPeaKr
Creating web applications with LODSPeaKrCreating web applications with LODSPeaKr
Creating web applications with LODSPeaKr
 
Sesam4 project presentation sparql - april 2011
Sesam4   project presentation sparql - april 2011Sesam4   project presentation sparql - april 2011
Sesam4 project presentation sparql - april 2011
 
Sesam4 project presentation sparql - april 2011
Sesam4   project presentation sparql - april 2011Sesam4   project presentation sparql - april 2011
Sesam4 project presentation sparql - april 2011
 
A hands on overview of the semantic web
A hands on overview of the semantic webA hands on overview of the semantic web
A hands on overview of the semantic web
 
ESWC SS 2012 - Monday Tutorial 2 Barry Norton: Introduction to SPARQL
ESWC SS 2012 - Monday Tutorial 2 Barry Norton: Introduction to SPARQLESWC SS 2012 - Monday Tutorial 2 Barry Norton: Introduction to SPARQL
ESWC SS 2012 - Monday Tutorial 2 Barry Norton: Introduction to SPARQL
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 

More from eswcsummerschool

Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014
Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014 Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014
Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014
eswcsummerschool
 
Mon norton tut_publishing01
Mon norton tut_publishing01Mon norton tut_publishing01
Mon norton tut_publishing01
eswcsummerschool
 
Mon domingue introduction to the school
Mon domingue introduction to the schoolMon domingue introduction to the school
Mon domingue introduction to the school
eswcsummerschool
 
Mon norton tut_querying cultural heritage data
Mon norton tut_querying cultural heritage dataMon norton tut_querying cultural heritage data
Mon norton tut_querying cultural heritage data
eswcsummerschool
 
Tue acosta hands_on_providinglinkeddata
Tue acosta hands_on_providinglinkeddataTue acosta hands_on_providinglinkeddata
Tue acosta hands_on_providinglinkeddata
eswcsummerschool
 
Thu bernstein key_warp_speed
Thu bernstein key_warp_speedThu bernstein key_warp_speed
Thu bernstein key_warp_speed
eswcsummerschool
 
Fri schreiber key_knowledge engineering
Fri schreiber key_knowledge engineeringFri schreiber key_knowledge engineering
Fri schreiber key_knowledge engineering
eswcsummerschool
 
Mon norton tut_queryinglinkeddata02
Mon norton tut_queryinglinkeddata02Mon norton tut_queryinglinkeddata02
Mon norton tut_queryinglinkeddata02
eswcsummerschool
 
Mon fundulaki tut_querying linked data
Mon fundulaki tut_querying linked dataMon fundulaki tut_querying linked data
Mon fundulaki tut_querying linked data
eswcsummerschool
 

More from eswcsummerschool (20)

Semantic Aquarium - ESWC SSchool 14 - Student project
Semantic Aquarium - ESWC SSchool 14 - Student projectSemantic Aquarium - ESWC SSchool 14 - Student project
Semantic Aquarium - ESWC SSchool 14 - Student project
 
Syrtaki - ESWC SSchool 14 - Student project
Syrtaki  - ESWC SSchool 14 - Student projectSyrtaki  - ESWC SSchool 14 - Student project
Syrtaki - ESWC SSchool 14 - Student project
 
Keep fit (a bit) - ESWC SSchool 14 - Student project
Keep fit (a bit)  - ESWC SSchool 14 - Student projectKeep fit (a bit)  - ESWC SSchool 14 - Student project
Keep fit (a bit) - ESWC SSchool 14 - Student project
 
Arabic Sentiment Lexicon - ESWC SSchool 14 - Student project
Arabic Sentiment Lexicon - ESWC SSchool 14 - Student projectArabic Sentiment Lexicon - ESWC SSchool 14 - Student project
Arabic Sentiment Lexicon - ESWC SSchool 14 - Student project
 
FIT-8BIT An activity music assistant - ESWC SSchool 14 - Student project
FIT-8BIT An activity music assistant - ESWC SSchool 14 - Student projectFIT-8BIT An activity music assistant - ESWC SSchool 14 - Student project
FIT-8BIT An activity music assistant - ESWC SSchool 14 - Student project
 
Personal Tours at the British Museum - ESWC SSchool 14 - Student project
Personal Tours at the British Museum  - ESWC SSchool 14 - Student projectPersonal Tours at the British Museum  - ESWC SSchool 14 - Student project
Personal Tours at the British Museum - ESWC SSchool 14 - Student project
 
Exhibition recommendation using British Museum data and Event Registry - ESWC...
Exhibition recommendation using British Museum data and Event Registry - ESWC...Exhibition recommendation using British Museum data and Event Registry - ESWC...
Exhibition recommendation using British Museum data and Event Registry - ESWC...
 
Empowering fishing business using Linked Data - ESWC SSchool 14 - Student pro...
Empowering fishing business using Linked Data - ESWC SSchool 14 - Student pro...Empowering fishing business using Linked Data - ESWC SSchool 14 - Student pro...
Empowering fishing business using Linked Data - ESWC SSchool 14 - Student pro...
 
Tutorial: Social Semantic Web and Crowdsourcing - E. Simperl - ESWC SS 2014
Tutorial: Social Semantic Web and Crowdsourcing - E. Simperl - ESWC SS 2014 Tutorial: Social Semantic Web and Crowdsourcing - E. Simperl - ESWC SS 2014
Tutorial: Social Semantic Web and Crowdsourcing - E. Simperl - ESWC SS 2014
 
Keynote: Global Media Monitoring - M. Grobelnik - ESWC SS 2014
Keynote: Global Media Monitoring - M. Grobelnik - ESWC SS 2014Keynote: Global Media Monitoring - M. Grobelnik - ESWC SS 2014
Keynote: Global Media Monitoring - M. Grobelnik - ESWC SS 2014
 
Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014
Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014 Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014
Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014
 
Tutorial: Querying a Marine Data Warehouse Using SPARQL - I. Fundulaki - ESWC...
Tutorial: Querying a Marine Data Warehouse Using SPARQL - I. Fundulaki - ESWC...Tutorial: Querying a Marine Data Warehouse Using SPARQL - I. Fundulaki - ESWC...
Tutorial: Querying a Marine Data Warehouse Using SPARQL - I. Fundulaki - ESWC...
 
Mon norton tut_publishing01
Mon norton tut_publishing01Mon norton tut_publishing01
Mon norton tut_publishing01
 
Mon domingue introduction to the school
Mon domingue introduction to the schoolMon domingue introduction to the school
Mon domingue introduction to the school
 
Mon norton tut_querying cultural heritage data
Mon norton tut_querying cultural heritage dataMon norton tut_querying cultural heritage data
Mon norton tut_querying cultural heritage data
 
Tue acosta hands_on_providinglinkeddata
Tue acosta hands_on_providinglinkeddataTue acosta hands_on_providinglinkeddata
Tue acosta hands_on_providinglinkeddata
 
Thu bernstein key_warp_speed
Thu bernstein key_warp_speedThu bernstein key_warp_speed
Thu bernstein key_warp_speed
 
Fri schreiber key_knowledge engineering
Fri schreiber key_knowledge engineeringFri schreiber key_knowledge engineering
Fri schreiber key_knowledge engineering
 
Mon norton tut_queryinglinkeddata02
Mon norton tut_queryinglinkeddata02Mon norton tut_queryinglinkeddata02
Mon norton tut_queryinglinkeddata02
 
Mon fundulaki tut_querying linked data
Mon fundulaki tut_querying linked dataMon fundulaki tut_querying linked data
Mon fundulaki tut_querying linked data
 

Recently uploaded

Recently uploaded (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

ESWC SS 2012 - Monday Tutorial 2 Barry Norton: SPARQL 1.1 Query Language

  • 2. Overview • • • • • • • • SPARQL 1.1 Overview Aggregates Subqueries Negation Expressions in SELECT Property Paths New Built-ins Short form CONSTRUCT SPARQL 1.1 Query #2
  • 3. What is SPARQL? • SPARQL was a query language for RDF data – http://www.w3.org/TR/rdf-sparql-query/ • And a protocol – http://www.w3.org/TR/rdf-sparql-protocol/ • Designed around graph patterns – Graph patterns use Turtle syntax • SPARQL 1.1 introduces: – – – – Query extensions (covered here) Protocol extensions and a (RESTful) graph store protocol Updates (covered next) Service descriptions and federation SPARQL 1.1 Query #3
  • 4. SPARQL 1.1 Query Extensions • SPARQL 1.1 adds the following new features (http://www.w3.org/TR/sparql11-query) – Aggregates – – – – – – – Subqueries Negation Expressions in the SELECT clause Property Paths Assignment A short form for CONSTRUCT An expanded set of functions and operators SPARQL 1.1 Query #4
  • 5. Aggregates • Aggregates allow computation of values using: – COUNT, SUM, MIN, MAX, AVG, GROUP_CONCAT and SAMPLE • Built around the GROUP BY operator • For example computing popularity in a social graph: SELECT ?person (COUNT(?someone) AS ?popularity) WHERE {?someone foaf:knows ?person} GROUP BY ?person • Prune at group level (cf. FILTER) using HAVING, e.g.: GROUP BY ?person HAVING (COUNT(?someone) > 300) SPARQL 1.1 Query #5
  • 6. Subqueries • Subqueries allow bindings from one (inner) query to be used in another (outer) query • For example, to compute whom the most popular person in a social graph knows: SELECT ?friend WHERE {?popular foaf:knows ?friend. {SELECT ?popular (COUNT(?someone) AS ?popularity) WHERE {?someone foaf:knows ?popular} GROUP BY ?popular ORDER BY DESC (?popularity) LIMIT 1}} SPARQL 1.1 Query #6
  • 7. Negation 1/2 • SPARQL 1.0 negation was limited, applying only to simple FILTER expressions • SPARQL 1.1 introduces EXISTS, allowing graph matching (without binding) • For example, to compute email addresses of people who know no Barrys (!): SELECT ?email WHERE {?sad foaf:mbox ?email . FILTER NOT EXISTS {?sad foaf:knows ?barry. {?barry foaf:givenName "Barry"} UNION {?barry foaf:firstName "Barry"}} SPARQL 1.1 Query #7
  • 8. Negation 2/2 • SPARQL 1.0 negation was limited, applying only to simple FILTER expressions • SPARQL 1.1 also introduces MINUS, allowing explicit removal of triples (according to another match) • For example, to compute people who know Barrys other than Barry Norton: SELECT DISTINCT ?person WHERE {?person foaf:knows ?barry. ?barry foaf:givenName "Barry". MINUS {?person foaf:knows [foaf:mbox <mailto:barry.norton@ontotext.com>]}} SPARQL 1.1 Query #8
  • 9. Expressions in SELECT (Projection) Clauses • SPARQL 1.0 allows built-in functions, etc., to be used in FILTER • SPARQL 1.1 allows their use in (the projection onto) variables in the head of the query • For example, to glue together names: SELECT (CONCAT(?forename, " ", ?surname) AS ?name) WHERE {{{?person foaf:givenName ?forename} UNION {?person foaf:firstName ?forename}}. {{?person foaf:familyName ?surname} UNION {?person foaf:lastName ?surname}}} SPARQL 1.1 Query #9
  • 10. Property Paths 1/2 • SPARQL 1.0 builds graph patterns from triple patterns, where resources are separated in the graph by one arc • SPARQL 1.1 generalises on triple patterns to model resources separated by paths of arbitrary length • Paths are specified using the following grammar that follows • Example: any member of an RDF List: ?list rdf:rest*/rdf:first ?element SPARQL 1.1 Query #10
  • 11. Property Paths 2/2 • Example: anyone in social graph of ?p knows a Barry: ?p {foaf:knows | ^foaf:knows}* / (foaf:givenName | foaf:firstName) "Barry" SPARQL 1.1 Query #11
  • 12. New Built-ins • SPARQL 1.1 supports a wider set of built-ins than SPARQL 1.0, introducing: – Maths: ABS (absolute value), ROUND/CEIL /FLOOR(rounding), RAND (random), isNUMERIC – Strings: CONCAT, CONTAINS, SUBSTR, STRLEN, UCASE, LCASE – Dates: YEAR, MONTH, DAY, HOURS, MINUTES, SECONDS, TIMEZONE/TZ (timezone as XML or literal), NOW – Hashes: MD5 , SHA1, SHA224, SHA256, SHA384, SHA512 – Enumeration: IN, NOT IN – Control: IF, COALESCE – Identifiers: ENCODE_FOR_URI, IRI/URI, BNODE (create a new blank node, can be with parameter) SPARQL 1.1 Query #12
  • 13. Short Form CONSTRUCT • In order to query for a subgraph, without change, it is no longer necessary to repeat the graph pattern • Example: CONSTRUCT WHERE {?barry foaf:givenName "Barry"; ?p ?o} SPARQL 1.1 Query #13