Logics for Data and Knowledge Representation

Slides:



Advertisements
Similar presentations
ESDSWG2011 – Semantic Web session Semantic Web Sub-group Session ESDSWG 2011 Meeting – Semantic Web sub-group session Wednesday, November 2, 2011 Norfolk,
Advertisements

RDF Tutorial.
Semantic Web Introduction
Information Systems & Semantic Web University of Koblenz ▪ Landau, Germany Semantic Web - Query Languages – Steffen Staab
 Copyright 2004 Digital Enterprise Research Institute. All rights reserved. SPARQL Query Language for RDF presented by Cristina Feier.
SPARQL RDF Query.
Chapter 3 Querying RDF stores with SPARQL. TL;DR We will want to query large RDF datasets, e.g. LOD SPARQL is the SQL of RDF SPARQL is a language to query.
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 Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction.
Chapter 3A Semantic Web Primer 1 Chapter 3 Querying the Semantic Web Grigoris Antoniou Paul Groth Frank van Harmelen Rinke Hoekstra.
Logics for Data and Knowledge Representation SPARQL Protocol and RDF Query Language (SPARQL) Feroz Farazi.
© 2006 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice Publishing data on the Web (with.
1 Ontology Query and Reasoning Payam Barnaghi Institute for Communication Systems (ICS) Faculty of Engineering and Physical Sciences University of Surrey.
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.
Logics for Data and Knowledge Representation Resource Description Framework (RDF) Feroz Farazi.
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
Introduction to SPARQL. Acknowledgements This presentation is based on the W3C Candidate Recommendation “SPARQL Query Language for RDF” from
SPARQL Semantic Web - Spring 2008 Computer Engineering Department Sharif University of Technology.
Logics for Data and Knowledge Representation
The Semantic Web Web Science Systems Development Spring 2015.
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.
SPARQL W3C Simple Protocol And RDF Query Language
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:
Logics for Data and Knowledge Representation SPARQL -- Exercises Feroz Farazi.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
RDF and XML 인공지능 연구실 한기덕. 2 개요  1. Basic of RDF  2. Example of RDF  3. How XML Namespaces Work  4. The Abbreviated RDF Syntax  5. RDF Resource Collections.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Efficient RDF Storage and Retrieval in Jena2 Written by: Kevin Wilkinson, Craig Sayers, Harumi Kuno, Dave Reynolds Presented by: Umer Fareed 파리드.
1 SPARQL A. Emrah Sanön. 2 RDF RDF is quite committed to Semantic Web. Data model Serialization by means of XML Formal semantics Still something is missing!
05/01/2016 SPARQL SPARQL Protocol and RDF Query Language S. Garlatti.
Alexandra Cristea 1.  pronounced "sparkle“  recursive acronym for: ◦ SPARQL Protocol and RDF Query Language  a semantic query language  a query language.
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.
CC L A W EB DE D ATOS P RIMAVERA 2015 Lecture 7: SPARQL (1.0) Aidan Hogan
Semantic Web for the Working Ontologist Dean Allemang Jim Hendler SNU IDB laboratory.
Chapter 04 Semantic Web Application Architecture 23 November 2015 A Team 오혜성, 조형헌, 권윤, 신동준, 이인용.
Semantic Web in Depth SPARQL Protocol and RDF Query Language Dr Nicholas Gibbins –
Select Complex Queries Database Management Fundamentals LESSON 3.1b.
1 RDF Storage and Retrieval Systems Jan Pettersen Nytun, UiA.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Vincenzo Maltese, Fausto Giunchiglia University of Trento
CC La Web de Datos Primavera 2017 Lecture 7: SPARQL [i]
SPARQL.
Keyword Search over RDF Graphs
 2012 Pearson Education, Inc. All rights reserved.
Basic select statement
Introduction to SPARQL
Resource Description Framework
SPARQL SPARQL Protocol and RDF Query Language
Middleware independent Information Service
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
SPARQL: A query language for RDF
David M. Kroenke and David J
Logics for Data and Knowledge Representation
CC La Web de Datos Primavera 2016 Lecture 7: SPARQL (1.0)
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
RDF 1.1 Concepts and Abstract Syntax
PHP.
JSON-LD 1.0 Yanan Zhang.
Logics for Data and Knowledge Representation
Contents Preface I Introduction Lesson Objectives I-2
Chapter 8 Advanced SQL.
CC La Web de Datos Primavera 2018 Lecture 8: SPARQL [1.1]
Resource Description Framework (RDF)
Databases and Information Management
Presentation transcript:

Logics for Data and Knowledge Representation SPARQL Protocol and RDF Query Language (SPARQL) Feroz Farazi 1

SPARQL A language for expressing queries to retrieve information from various data represented in RDF [SPARQL Spec.] A query language with the capability to search graph patterns [SPARQL Spec.] Often SPARQL queries contain a basic graph pattern: a set of subject, object, predicate triple patterns RDF terms possibly substituted with variables Result of the query a subgraph of the RDF data graph

Terminologies RDF Terms: RDF Dataset: Given that I is the set of all IRIs, L is the set of all RDF literals and B is the set of all blank nodes in an RDF graph. Within the graph the set of all RDF Terms, T = I U L U B RDF Dataset: D = {G, (I1, G1), (I2, G2),…(Ik, Gk)}, where G is the default graph (Ii, Gi) are named graphs, i = 1 to k, k ≥ 0 An RDF dataset always contains a default graph, which does not have a name It contains zero or more named graphs Each named graph is identified by a URI

Terminologies Triple Pattern: Solution Mapping: Query Variable: A query variable, v ∈ V, where V is infinite and V ∩ T = ∅ Triple Pattern: A triple pattern P ∈ {(T U V) x (I U V) x (T U V)} Solution Mapping: A solution mapping is a partial function M:V -> T where V is the query variable and T is the set of all RDF Terms Solution Sequence: A list of solutions which might be unordered. Number of solutions might be zero, one or more.

Terminologies Others: IRIs and URIs Solution Sequence Modifier: (i) Order By (ii) Projection (iii) Distinct (iv) Reduced (v) Offset (vi) Limit Others: IRI (Internationalized Resource Identifier), Lexical form, language tag (e.g., en, it), datatype IRI (e.g., xsd:boolean), literal, plain literal and typed literal IRIs and URIs URIs include a subset of the ASCII character set IRIs can include Unicode characters (Universal Character Set) ASK: to perform a test to know if a query expression has a solution. It replies with yes/no.

Query Dataset: Query Expression: Query Result: Dataset: :paper1 :title “Semantic Matching” Query Expression: SELECT ?title WHERE { :paper1 :title ?title. } Query Result: “Semantic Matching” SELECT query form returns RDF Terms bound to the variables title Dataset: :paper1 :creator “Fausto Giunchiglia” Query Expression: SELECT ?author WHERE { :paper1 :creator ?author. } Query Result: “Fausto Giunchiglia”

Query Multiple Matches Dataset: Query Expression: Query Result: _:a :name "Tim Berners-Lee" . _:a :homepage <http://www.w3.org/People/Berners-Lee/> . _:b :name "Fausto Giunchiglia" . _:b :homepage <http://disi.unitn.it/~fausto/> . Query Expression: SELECT ?name ?homepage WHERE { ?x :name ?name . ?x :homepage ?homepage } Query Result: name homepage Tim Berners-Lee <http://www.w3.org/People/Berners-Lee/> Fausto Giunchiglia <http://disi.unitn.it/~fausto/>

Query RDF Literals Matching Dataset: :x :name "Tim Berners-Lee"@en . :y :name "Fausto Giunchiglia"@en. Query Expression 1: SELECT ?u WHERE { ?u :name "Tim Berners-Lee"} Query Result: u Query Expression 2: WHERE { ?u :name "Tim Berners-Lee"@en} :x This query has 0 solution because without language tag the search element does not match with dataset element This query has 1 solution because the inclusion of language tag bound u to :x

Building RDF Graphs CONSTRUCT: this query construct returns an RDF graph Dataset: _:a :creator "Tim Berners-Lee" . _:b :creator "Fausto Giunchiglia" . Query Expression: CONSTRUCT { ?x :name ?name } WHERE { ?x :creator ?name } Query Result: _:c :name "Tim Berners-Lee" . _:d :name "Fausto Giunchiglia" . In this dataset with :creator we mean Dublin Core (dc) creator metadata In the query with :name we mean FOAF name metadata We built a graph with FOAF name attribute which was not available in the source dataset

RDF Term Restrictions FILTER: solutions are restricted to those RDF Terms which match with the filter expression Dataset: _:a :creator "Tim Berners-Lee" . _:a :age 52 . _:b :creator "Fausto Giunchiglia" . _:b :age 53. Query Expression: SELECT ?author WHERE { ?x :creator ?author. FILTER regex(?author, "Tim") } Query Result: author "Tim Berners-Lee" . The above query can be made case insensitive by adding “i” flag in the filter as follows: FILTER regex(?author, “tim”, “i”) Query Expression: SELECT ?author ?age WHERE { ?x :creator ?author. ?x :age ?age FILTER (?age >52) } Query Result: author age "Fausto Giunchiglia" 53

Querying Optional Pattern OPTIONAL: to allow binding variables to RDF Terms to be included in the solution in case of availability Dataset: _:a :creator "Tim Berners-Lee" . _:a :age 52 . _:a :homepage <http://www.w3.org/People/Berners-Lee/> . _:b :creator "Fausto Giunchiglia" . _:b :age 53. Query Expression: SELECT ?author ?homepage WHERE { ?x :creator ?author. OPTIONAL {?x :homepage ?homepage}} Query Result: author homepage "Tim Berners-Lee" <http://www.w3.org/People/Berners-Lee/> "Fausto Giunchiglia" It is a left associative operator Why do we need it? All entities might not have the same set of attributes

ORDER BY Clause ORDER BY: a facility to order a solution sequence Dataset: _:a :creator "Tim Berners-Lee" . _:a :age 52 . _:b :creator "Fausto Giunchiglia" . _:b :age 53. Query Expression: SELECT ?author WHERE { ?x :creator ?author; ?x :age ?age} ORDER BY ?author DESC (?age) Query Result: author "Fausto Giunchiglia" "Tim Berners-Lee"

DISTINCT and REDUCED Modifiers DISTINCT: to remove duplicate from a solution sequence Dataset: _:b :creator "Fausto Giunchiglia" . _:b :age 53. _:c :creator "Fausto Giunchiglia" . _:c :age 37. Query Expression: SELECT DISTINCT ?creator WHERE { ?x :creator ?creator} Query Result: creator "Fausto Giunchiglia" REDUCED: to permit the duplicates to be removed. SELECT REDUCED ?creator The cardinality of the elements in the solution set is at least one and no more than the cardinality without removing duplicates

OFFSET and LIMIT Clauses OFFSET: to show the elements of the solution set starting after a specified number. If the number is zero, there will be no effect. Dataset: _:b :creator "Fausto Giunchiglia" . _:b :age 53. _:c :creator "Tim Berners-Lee" . _:c :age 52. Query Expression: SELECT ?author WHERE { ?x :creator ?author } ORDER BY ?author OFFSET 1 Query Result: author "Tim Berners-Lee" Limit: to put an upper bound on the number of elements of the solution set returned Query Expression: SELECT ?author WHERE { ?x :creator ?author } ORDER BY ?author LIMIT 1 OFFSET 1 Query Result: author "Tim Berners-Lee"

Relational vs RDF queries Relational queries consist of (among others): Relational algebra of joins Foreign key references RDF queries consists of (among others): (Logical) statements in triple form Unification variables are used to connect graph patterns A relational query: Produces a new database table that is a combination of two or more input tables (partially or completely) An RDF query: Produces a subset of the input RDF graph Simplifies some issues of table based queries, for example, no need to put subquery construct [D. Allemang and J. Hendler, 2008]

Turtle Turtle is a terse RDF triple language Turtle is a textual syntax for RDF facilitates writing RDF graph in a compact and natural language text form with abbreviations for common usage patterns and datatypes compatible with triple pattern syntax of SPARQL (and N-Triples) Triple: a sequence of (subject, predicate, object) terms separated by whitespace terminated by '.' after each triple e.g., <http://www.w3.org/.../Weaving/> <http://purl.org/dc/elements/1.1/creator> <http://www.w3.org/People/Berners-Lee> . List of predicates and objects: For the same subject can be codified without repeating the common part Reference to the subject of the previous triple is indicated by the use of a semicolon e.g., <http://www.w3.org/.../Weaving> <http://purl.org/dc/elements/1.1/creator> <http://www.w3.org/People/Berners-Lee> ; <http://purl.org/dc/elements/1.1/title> "Weaving the Web".

Turtle List of objects: SPARQL differs from Turtle: For the same subject and predicate can be codified without repeating the common part Reference to the subject and predicate of the previous triple is indicated by the use of a comma e.g., <http://www.w3.org/.../Weaving> <http://purl.org/dc/elements/1.1/creator> "Tim Berners-Lee", "TBL", "Tim BL" . SPARQL differs from Turtle: SPARQL permits RDF Literals as the subject of RDF triples SPARQL permits variables (?name or $name) in any part of the triple of the form prefix and base declarations Turtle allows prefix and base declarations anywhere outside of a triple In SPARQL, they are only allowed in the Prologue (at the start of the SPARQL query) case sensitivity SPARQL uses case insensitive keywords, except for 'a‘, where 'a' means the IRI http://www.w3.org/1999/02/22-rdf-syntax-ns#type Turtle's prefix and base declarations are case sensitive 'true' and 'false' are case insensitive in SPARQL and case sensitive in Turtle TrUe is not a valid boolean value in Turtle

SPARQL: Federated Query Federated SPARQL query can be used to express queries across diverse data sources if data is stored natively as RDF or data is viewed as RDF via middleware It is an opportunity for data consumers to get data distributed across the Web Federated Query is used for executing queries distributed over different SPARQL endpoints The SERVICE keyword allows a query author to direct a portion of a query to a particular SPARQL endpoint supports SPARQL queries merging data distributed across the Web

SPARQL: Federated Query An example query to a remote SPARQL endpoint Consider a query to find the names of the people we know Data about the names of various people is available at the http://people.example.org/sparql endpoint: and one wants to combine with a local FOAF file http://example.org/myfoaf.rdf that contains the single triple: DATASET 1: @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix : <http://example.org/> . :people1 foaf:name "Tim BL" . :people2 foaf:name "James" . DATASET 2: <http://example.org/myfoaf/I> <http://xmlns.com/foaf/0.1/knows> <http://example.org/people2> . QUERY: PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name FROM <http://example.org/myfoaf.rdf> WHERE { <http://example.org/myfoaf/I> foaf:knows ?person . SERVICE <http://people.example.org/sparql> { ?person foaf:name ?name . } } This query, on the datasets provided above, has one solution: RESULT: Name ---------- James

SPARQL: Federated Query An example query with OPTIONAL to two remote SPARQL endpoints Consider we want to query people and optionally obtain their interests and the names of people they know Data in the default graph at remote SPARQL endpoint: At http://people.example.org/sparql DATASET 1: @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix : <http://example.org/> . :people1 foaf:name "Tim BL" . :people2 foaf:name "James" . :people3 foaf:name "Jerome" . :people3 foaf:interest <http://www.w3.org/2001/sw/rdb2rdf/> . At http://people2.example.org/sparql DATASET 2: @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix : <http://example.org/> . :people1 foaf:knows :people21 . :people21 foaf:name " Chris" . :people3 foaf:knows :people22 . :people22 foaf:name “Frank" . QUERY: PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?person ?interest ?known WHERE { SERVICE <http://people.example.org/sparql> ?person foaf:name ?name . OPTIONAL { ?person foaf:interest ?interest . SERVICE <http://people2.example.org/sparql> { ?person foaf:knows ?known . } } This query, on the datasets provided above, has three solutions: RESULT: person interest known --------------------------------------------------------- Tim BL James Jerome <http…rdb2rdf/> <http…people22>

SPARQL Update Graph Store: an editable repository of RDF graphs managed by a single service Update service: a service (often referred to by the informal term SPARQL endpoint) that accepts and processes update requests Similarly to RDF dataset a Graph Store contains one (unnamed) slot holding a default graph and zero or more named slots holding named graphs Formal definition: Graph Store The Graph Store can be viewed as a mutable RDF Dataset. GS = {DG, (iri1, G1), ... , (irin, Gn) } Where the default graph DG is the RDF graph associated with the unnamed slot n ≥ 0 and for each 1 ≤ i ≤ n, Gi is an RDF graph associated with the named slot identified by IRI irii all IRIs are distinct, i.e., i≠j implies irii≠irij

SPARQL Update Update operations can specify graph(s) to be edited. Without such specification an operation is performed on the default graph The unnamed or default graph may refer to a separate graph, a graph describing the named graphs, a representation of a union of other graphs, and so on Unlike an RDF Dataset, named graphs can be added to or deleted from a Graph Store A Graph Store can keep local copies of RDF graphs defined elsewhere on the Web and modify those copies independently of the original graph SPARQL Update supports two categories of update operations on a Graph Store Graph Update - addition and removal of triples from some graphs Graph Management - creating and deletion of graphs and the graph update operations (to add, move, and copy graphs) for managing graphs In the case where there is one unnamed graph and no named graphs, SPARQL Update can be used as a graph update language (as opposed to a Graph Store update language)

References SPARQL Spec. (2008). W3C Recommendation. SPARQL 1.1 Federated Query (2013). W3C Recommendation. SPARQL 1.1 Update (2013). W3C Recommendation. Turtle Terse RDF Triple Language (2013). W3C Recommendation. D. Allemang and J. Hendler. Semantic web for the working ontologist: modeling in RDF, RDFS and OWL. Morgan Kaufmann Elsevier, Amsterdam, NL, 2008.