CC6202-1 L A W EB DE D ATOS P RIMAVERA 2015 Lecture 7: SPARQL (1.0) Aidan Hogan

Slides:



Advertisements
Similar presentations
Requirements. UC&R: Phase Compliance model –RIF must define a compliance model that will identify required/optional features Default.
Advertisements

XML Data Management 8. XQuery Werner Nutt. Requirements for an XML Query Language David Maier, W3C XML Query Requirements: Closedness: output must be.
Lecture 24 MAS 714 Hartmut Klauck
ESDSWG2011 – Semantic Web session Semantic Web Sub-group Session ESDSWG 2011 Meeting – Semantic Web sub-group session Wednesday, November 2, 2011 Norfolk,
A Visual Approach to Semantic Query Design Using a Web-Based Graphical Query Designer Paul R. Smart, Alistair Russell, Dave Braines, Yannis Kalfoglou,,
 Copyright 2004 Digital Enterprise Research Institute. All rights reserved. SPARQL Query Language for RDF presented by Cristina Feier.
SPARQL RDF Query.
Types and Arithmetic Operators
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A Modified by Donghui Zhang.
INFS614, Fall 08 1 Relational Algebra Lecture 4. INFS614, Fall 08 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of.
SPARQL for Querying PML Data Jitin Arora. Overview SPARQL: Query Language for RDF Graphs W3C Recommendation since 15 January 2008 Outline: Basic Concepts.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 2: Single-Table Selections.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
SQL SQL is a very-high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation details that would be necessary in.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
Chapter 3A Semantic Web Primer 1 Chapter 3 Querying the Semantic Web Grigoris Antoniou Paul Groth Frank van Harmelen Rinke Hoekstra.
IFS Intro. to Data Management Chapter 6 Filtering your data.
Logics for Data and Knowledge Representation SPARQL Protocol and RDF Query Language (SPARQL) Feroz Farazi.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
SPARQL All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link:
Master Informatique 1 Semantic Technologies Part 5SPARQL Werner Nutt.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
Introduction to SPARQL. Acknowledgements This presentation is based on the W3C Candidate Recommendation “SPARQL Query Language for RDF” from
Chapter 3 Querying RDF stores with SPARQL. Why an RDF Query Language? Why not use an XML query language? XML at a lower level of abstraction than RDF.
1 CS 430 Database Theory Winter 2005 Lecture 12: SQL DML - SELECT.
SPARQL W3C Simple Protocol And RDF Query Language
Lesley Charles November 23, 2009.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
SPARQL AN RDF Query Language. SPARQL SPARQL is a recursive acronym for SPARQL Protocol And Rdf Query Language SPARQL is the SQL for RDF Example: PREFIX.
SPARQL All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link:
CC L A W EB DE D ATOS P RIMAVERA 2015 Lecture 2: RDF Model & Syntax Aidan Hogan
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Instructor: Jinze Liu Fall Basic Components (2) Relational Database Web-Interface Done before mid-term Must-Have Components (2) Security: access.
Master Informatique 1 Semantic Technologies Part 7SPARQL 1.1 Werner Nutt.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra.
1 Relational Algebra and Calculas Chapter 4, Part A.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 4 Relational Algebra.
Copyright Curt Hill The C/C++ switch Statement A multi-path decision statement.
05/01/2016 SPARQL SPARQL Protocol and RDF Query Language S. Garlatti.
CC L A W EB DE D ATOS P RIMAVERA 2015 Lecture 8: SPARQL (1.1) Aidan Hogan
CC L A W EB DE D ATOS P RIMAVERA 2015 Lecture 10: Conclusion Aidan Hogan
An Effective SPARQL Support over Relational Database Jing Lu, Feng Cao, Li Ma, Yong Yu, Yue Pan SWDB-ODBIS 2007 SNU IDB Lab. Hyewon Lim July 30 th, 2009.
CSE 6331 © Leonidas Fegaras XQuery 1 XQuery Leonidas Fegaras.
IST 210 More SQL Todd Bacastow IST 210: Organization of Data.
1 SQL: The Query Language. 2 Example Instances R1 S1 S2 v We will use these instances of the Sailors and Reserves relations in our examples. v If the.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
1 Section 3 - Select Statement u The Select statement allows you to... –Display Data –Specify Selection Criteria –Sort Data –Group Data for reporting –Use.
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
1 ORACLE I 3 – SQL 1 Salim Phone: YM: talim_bansal.
CC La Web de Datos Primavera 2017 Lecture 7: SPARQL [i]
Relational Database Design
Writing Basic SQL SELECT Statements
CC La Web de Datos Primavera 2016 Lecture 8: SPARQL (1.1)
CC La Web de Datos Primavera 2017 Lecture 8: SPARQL [ii]
Introduction to SPARQL
SPARQL SPARQL Protocol and RDF Query Language
SPARQL + RDF Based on: Prof. Benny Kimelfled’s lecture notes
SQL: Structured Query Language DML- Queries Lecturer: Dr Pavle Mogin
Basic SQL Lecture 6 Fall
Logics for Data and Knowledge Representation
CC La Web de Datos Primavera 2016 Lecture 7: SPARQL (1.0)
CC La Web de Datos Primavera 2016 Lecture 2: RDF Model & Syntax
G-CORE: A Core for Future Graph Query Languages
CC La Web de Datos Primavera 2018 Lecture 8: SPARQL [1.1]
XQuery Leonidas Fegaras.
Logics for Data and Knowledge Representation
On Provenance of Queries on Linked Web Data
Presentation transcript:

CC L A W EB DE D ATOS P RIMAVERA 2015 Lecture 7: SPARQL (1.0) Aidan Hogan

(1) Data, (2) Rules/Ontologies, (3) Query

First SPARQL (1.0) Then SPARQL 1.1

SPARQL: Query Language for RDF How to ask: “Who stars in ‘Sharknado’?”

SPARQL: Query Language for RDF Query: Solutions:

SPARQL: PREFIX DECLARATIONS

SPARQL: prefix declarations Shortcuts for IRIs (exactly like in Turtle)

SPARQL: WHERE CLAUSE

SPARQL: WHERE clause Where the magic happens Specifies what to match in the data “Triple pattern” (a triple with variables)

SPARQL: WHERE clause Query: Solutions:

SPARQL: WHERE clause How to ask: “What movies did the stars of ‘Sharknado’ also star in?”

SPARQL: Basic Graph Patterns Query:Solutions:

SPARQL: Basic Graph Patterns Query: “Basic Graph Pattern” (a set of triple patterns)

SPARQL: Join Variables Query: “Join Variable” (a variable appearing multiple times)

SPARQL: Disjunction How to ask: “What are the titles of the (first two) movies in the Sharknado series?”

SPARQL: Disjunction ( UNION ) Query: Solutions:

SPARQL: Left-join How to ask: “Give me the titles of all movies and, if available, their first-aired date?”

SPARQL: Left-join ( OPTIONAL ) Query: Solutions: “UNBOUND Variable” (a variable without a binding in a solution)

SPARQL: Filtering results How to ask: “What movies were first aired in 2014?”

SPARQL: FILTER Query: Solutions: “Empty Results” Any problem here?… be careful comparing dates without time-zones! … also missing the xsd: prefix ;)

SPARQL: FILTER Query: What happens in this case where ?date bound in data to a string? FILTERS (and other functions we see later) expect certain types. If not given, a type error is given.

SPARQL: Boolean FILTER operators FILTER s evaluate as true, false or error Only results evaluating as true are returned Can apply AND ( && ) or OR ( || ) Can also apply NOT ( ! ) –!E → E–!E → E

SPARQL: RDF term FILTER operators ISIRI(A), ISURI(A), ISBLANK(A), ISLITERAL(A) – checks the type of RDF term –ISIRI and ISURI are synonymous BOUND(A) – checks if the variable is bound

SPARQL: (In)equality FILTER operators =, !=, SAMETERM(A,B) –= and != test value (in)equality –SAMETERM tests term equality e.g., “2.0”^^decimal = “2”^^xsd:int gives true SAMETERM(“2.0”^^decimal,“2”^^xsd:int ) gives false >, =, <= – can only compare “compatible” types e.g., “2.0”^^decimal > “2”^^xsd:int okay, “2.0”^^decimal > “2” an error

SPARQL: Numeric FILTER operators +A, –A, A+B, A–B, A*B, A/B (numeric) – input numeric, output numeric

SPARQL: Literal/string FILTER operators STR(A), LANG(A), DATATYPE(A) –STR returns string of RDF term (literal or IRI) –LANG returns language tag of literal –DATATYPE returns datatype of literal – All return xsd:string LANGMATCHES(A,B) tests (sub-)language – e.g.: LANGMATCHES( “ en “, “ en “ ) gives true LANGMATCHES( “ en-US “, “ en “ ) gives true LANGMATCHES( “ en “, “ en-US “ ) gives false REGEX(A,B,C) tests a regular expression – C sets some optional tags like case insensitivity – e.g.: REGEX( “ blah “, ” ^B ” ) gives false REGEX( “ blah “, “ ^B “, “ i “ ) gives true

SPARQL: Casting between types Y: always allowed N: never allowed M: depends on value – e.g., “2”^^xsd:string can be mapped to xsd:int but “P”^^xsd:string cannot

SPARQL: Extensible/User-defined Functions A SPARQL implementation can choose to implement custom functions – e.g., ex:isOddNumber(A) A common example in practice is for free-text search The SPARQL syntax allows it but the engine must interpret the function (or throw an error if not supported)

SPARQL: WHERE clause example (i) Query: What solutions would this query return? Solutions:

SPARQL: WHERE clause example (ii) Query: What solutions would this query return? Solutions: Can do a closed-world style of negation!

SPARQL: QUERY TYPES

SPARQL: SELECT with * Query: Solutions:

SPARQL: SELECT with projection Query: DEFAULT “Bag Semantics” (number of results returned must correspond to number of matches in data) Solutions:

SPARQL: SELECT with DISTINCT Query: DISTINCT: “Set Semantics” (each result row must be unique) Solutions:

SPARQL: SELECT with REDUCED Query: Solutions: OR May (but do not need to) return duplicates. (This allows the engine do whatever is most efficient.)

SPARQL: ASK Query: Solutions: Returns true if there is a match, false otherwise.

SPARQL: CONSTRUCT Query: Solutions: Returns an RDF graph based on the matching CONSTRUCT clause.

SPARQL: DESCRIBE (optional feature) Query: Solutions: Returns an RDF graph “describing” the returned results. This is an optional feature. What should be returned is left open.

SPARQL: SOLUTION MODIFIERS

Solution modifiers ORDER BY (DESC) – Can be used to order results – By default ascending ( ASC ), can specify descending ( DESC ) – Can order lexicographically on multiple items LIMIT n – Return only n results OFFSET n – Skip the first n results How might we ask for the second and third most recently released movies? Strictly speaking, by default, no ordering is applied. Hence OFFSET means nothing without ORDER BY. However, some engines support a default ordering (e.g., the order of computation of results).

SPARQL: NAMED GRAPHS

SPARQL defined over a Dataset Core idea: SPARQL can support multiple RDF graphs, not just one. When using SPARQL, you can partition your data into multiple graphs. The default graph is chosen if you don’t specify a graph. Otherwise you can explicitly select a named graph using it’s IRI name.

An example dataset

Creating a dataset for a query FROM – Used to define a default graph for the query using graph names – If multiple graphs are specified, they are RDF-merged FROM NAMED – Used to select the active named graphs to be used for the query Using either feature clears the index dataset

Querying the named graphs in a dataset We can query parts of the dataset using … GRAPH : specifies the URI of a named graph from which results or a variable that ranges over all named graphs – Does not access the default graph! – If not specified, default graph is accessed

An example query Query: What solutions would this query return? Solutions: No GRAPH clause so answers come from default graph only

Using FROM Query: What solutions would this query return? Solutions: No GRAPH clause so answers come from default graph defined by FROM (existing default graph cleared)

Using FROM NAMED Query: What solutions would this query return? Solutions: No GRAPH clause so answers come from default graph, which is empty (since existing default graph cleared)!

Using GRAPH with variable Query: What solutions would this query return? Solutions: GRAPH clause only ranges over the named graphs.

Using GRAPH with a name Query: What solutions would this query return? Solutions:

Using GRAPH with FROM Query: What solutions would this query return? Solutions: No named graphs specified!

Using GRAPH with FROM NAMED Query: What solutions would this query return? Solutions: GRAPH accesses the one and only named graph

Using GRAPH with FROM and FROM NAMED Query: What solutions would this query return? Solutions:

RECAP

Parts of a SPARQL query (i) Prefix declarations WHERE clause – Joins / Basic Graph Patterns –UNION –OPTIONAL –FILTER Solution modifiers –ORDER BY –LIMIT –OFFSET

Parts of a SPARQL query (ii) Types of queries: –SELECT ( DISTINCT / REDUCED ) –ASK –CONSTRUCT –DESCRIBE Dataset selection / querying –FROM –FROM NAMED –GRAPH

Questions?