SPARQL Query Andy Seaborne. Apache Jena he.org/jena ● Open source - Apache License ● Apache Incubator (accepted November 2010) ●

Slides:



Advertisements
Similar presentations
SQL Introduction Standard language for querying and manipulating data Structured Query Language Many standards out there: SQL92, SQL2, SQL3. Vendors support.
Advertisements

RDF Tutorial.
Semantic Web Introduction
 Copyright 2004 Digital Enterprise Research Institute. All rights reserved. SPARQL Query Language for RDF presented by Cristina Feier.
SPARQL RDF Query.
Database Security CS461/ECE422 Spring Overview Database model – Relational Databases Access Control Inference and Statistical Databases Database.
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.
Introduction to Structured Query Language (SQL)
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
Microsoft Access 2010 Chapter 7 Using SQL.
Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction.
Semantic Web Bootcamp Dominic DiFranzo PhD Student/Research Assistant Rensselaer Polytechnic Institute Tetherless World Constellation.
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.
More on SPARQL. Acknowledgements This presentation is based on the W3C Candidate Recommendation “SPARQL Query Language for RDF” (
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
SPARQL All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link:
Microsoft Access 2010 Chapter 7 Using SQL. Change the font or font size for SQL queries Create SQL queries Include fields in SQL queries Include simple.
Example: Jena and Fuseki
Introduction to SPARQL. Acknowledgements This presentation is based on the W3C Candidate Recommendation “SPARQL Query Language for RDF” from
Entity Recognition via Querying DBpedia ElShaimaa Ali.
SPARQL Semantic Web - Spring 2008 Computer Engineering Department Sharif University of Technology.
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.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
KIT – University of the State of Baden-Württemberg and National Large-scale Research Center of the Helmholtz Association Institute of Applied Informatics.
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:
Using Special Operators (LIKE and IN)
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Master Informatique 1 Semantic Technologies Part 7SPARQL 1.1 Werner Nutt.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Privacy Framework for RDF Data Mining Master’s Thesis Project Proposal By: Yotam Aron.
Semantic Web Basics Dominic DiFranzo PhD Student/Research Assistant Rensselaer Polytechnic Institute Tetherless World Constellation.
SPARQL In-Class Shared Exercise. Pop Quiz If you have a large knowledge store, why should you not issue: SELECT ?s ?p ?o WHERE { ?s ?p ?o } Ans: It returns.
Ontology engineering Lab #8 – October 20, 2014.
05/01/2016 SPARQL SPARQL Protocol and RDF Query Language S. Garlatti.
Chapter 3 Querying RDF stores with SPARQL
Of 38 lecture 6: rdf – axiomatic semantics and query.
CC L A W EB DE D ATOS P RIMAVERA 2015 Lecture 8: SPARQL (1.1) Aidan Hogan
Oracle & SQL. Oracle Data Types Character Data Types: Char(2) Varchar (20) Clob: large character string as long as 4GB Bolb and bfile: large amount of.
Knowledge Technologies Manolis Koubarakis 1 Some Other Useful Features of RDF.
1 CS 430 Database Theory Winter 2005 Lecture 13: SQL DML - Modifying Data.
Chapter 04 Semantic Web Application Architecture 23 November 2015 A Team 오혜성, 조형헌, 권윤, 신동준, 이인용.
Semantic Web in Depth SPARQL Protocol and RDF Query Language Dr Nicholas Gibbins –
Semantic Web In Depth Resource Description Framework Dr Nicholas Gibbins –
NEDA ALIPANAH, MARIA ADELA GRANDO DBMI 11/19/2012.
1 RDF Storage and Retrieval Systems Jan Pettersen Nytun, UiA.
Developing Linked Data Applications
SPARQL.
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
Resource Description Framework
PL/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-1
SPARQL SPARQL Protocol and RDF Query Language
SPARQL: A query language for RDF
SPARQL Exercise Much of this exercise has been copied from: INF3580/INF4580 – MANDATORY EXERCISE 3
Miguel Azurin, Andrew Engroff, Ahmad Sadiq
Bus Routes.
Logics for Data and Knowledge Representation
Access: SQL Participation Project
SPARQL Exercise Most of this exercise has been copied from: INF3580/INF4580 – MANDATORY EXERCISE 3
Contents Preface I Introduction Lesson Objectives I-2
CC La Web de Datos Primavera 2018 Lecture 8: SPARQL [1.1]
Logics for Data and Knowledge Representation
Triple Stores.
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

SPARQL Query Andy Seaborne

Apache Jena he.org/jena ● Open source - Apache License ● Apache Incubator (accepted November 2010) ● Old web site: ● RDF: parsers and writers ● SPARQL: Query, Update, Server

SPARQL 1.1 ● SPARQL Query ● Sub-queries ● Aggregation ● Negation ● Property Paths ● SPARQL Update ● Language ● Protocol ● Other ● Entailment ● Service Description ● Function Library

Recap: Basic Graph Pattern ● Basic graph patterns ● Building blocks of SPARQL queries ● A number of triples, all of which mush match. PREFIX rdf: PREFIX foaf: SELECT ?name WHERE { ?x rdf:type foaf:Person ; foaf:name ?name. } PREFIX rdf: PREFIX foaf: SELECT ?name WHERE { ?x rdf:type foaf:Person. ?x foaf:name ?name. }

SPARQL Subquery and aggregation PREFIX rdf: PREFIX foaf: SELECT (count(*) AS ?count) { ?x rdf:type foaf:Person. } | count | ========= | 12 |

SPARQL Subquery and aggregation PREFIX rdf: PREFIX foaf: SELECT ?group (count(*) AS ?count) { ?x rdf:type foaf:Person. ?group foaf:member ?x. } GROUP BY ?group | group | count | =============================== | | 4 | | | 3 |

Example: All people who know 3 others PREFIX rdf: PREFIX foaf: SELECT ?name { { SELECT ?x (count(*) AS ?count) { ?x foaf:knows ?y. } GROUP BY ?x HAVING (?count = 3) } ?x foaf:name ?name. } | name | ============ | "Clare" | | "Brenda" | | "Alice" |

Aggregate Functions ● COUNT ● MIN ● MAX ● SUM ● AVG ● GROUP_CONCAT ● SAMPLE

Negation ● 2 forms – stylistic and conceptual differences ● Absence of a pattern ● Removing rows from a result set ● Nearly the same, but not quite

Negation ● Example: People without declared name PREFIX rdf: PREFIX foaf: SELECT ?x { ?x rdf:type foaf:Person. FILTER NOT EXISTS { ?x foaf:name ?name } } PREFIX rdf: PREFIX foaf: SELECT ?x { ?x rdf:type foaf:Person. MINUS { ?x foaf:name ?name } }

Negation : NOT EXISTS ● Filters results by a pattern ● Tests applied to each row ● Variables substituted for values for that row ● EXISTS version also in SPARQL { ?x rdf:type foaf:Person. FILTER NOT EXISTS { ?x foaf:name ?name } } ({?x = :X}, {?x = :Y} ) :X rdf:type foaf:Person. :X foaf:name “Xavier”. :Y rdf:type foaf:Person. 1: ({?x = :X}) test { :X foaf:name ?name } => triple pattern exists 2: ({?x = :Y}) test { :Y foaf:name ?name } => triple pattern does not exist ( {?x = :Y} )

Negation : Differences SELECT * { ?s ?p ?o FILTER NOT EXISTS { ?x ?y ?z } } SELECT * { ?s ?p ?o MINUS { ?x ?y ?z } } SELECT * { ?s ?p ?o FILTER NOT EXISTS { } } SELECT * { ?s ?p ?o MINUS { } } SELECT * { ?s :p ?o FILTER ( NOT EXISTS { ?s :q ?v. FILTER (?o < ?v ) } ) } SELECT * { ?s :p ?o MINUS { ?s :q ?v. FILTER (?o < ?v ) } ) }

Property Paths ● Regular expressions over properties ● Simple paths : adds easy of expressibility ● Concat ● Alternate ● {N} ● {N,M} ● Adds arbitrary length paths ● :p*, :p+ ● Paths can combine other paths

Property Paths : Simple Path Example PREFIX rdf: PREFIX foaf: SELECT ?xName ?yName { ?x rdf:type foaf:Person. ?x foaf:name ?xName ?x foaf:knows{2}/foaf:name ?yName. } { ?x rdf:type foaf:Person. ?x foaf:name ?xName ?x foaf:knows ?_2. ?_2 foaf:knows ?_1. ?_1 foaf:name ?yName. } { ?x rdf:type foaf:Person. ?x foaf:name ?xName ?x foaf:knows{2} ?_1. ?_1 foaf:name ?yName. }

Property Paths and Inference rdfs:subClassOf PREFIX rdf: PREFIX rdfs: PREFIX : SELECT ?s { ?s rdf:type ?T. ?T rdfs:subClassOf* :SomeClass. }

Property Paths and Inference rdfs:subPropertyOf PREFIX rdf: PREFIX rdfs: PREFIX : SELECT * { ?s ?p ?o. ?p rdfs:subPropertyOf* :property. }

Property Path : Accessing RDF rdf:. :x :p (“a” “b” rdf:. :x :p _:b1. _:b1 rdf:first “a”. _:b1 rdf:rest _:b2. _:b2 rdf:first “b”. _:b2 rdf:rest _:b3. _:b3 rdf:first “c”. _:b3 rdf:rest rdf:nil. :x_:b1 rdf:rest rdf:first “a” :p _:b2 rdf:rest rdf:first “b” _:b3 rdf:rest rdf:first “c” rdf:nil

Property Path : Accessing RDF lists ● Partial solution ● Order in list not visible PREFIX rdf: PREFIX rdfs: PREFIX : SELECT ?member { :x :p ?list. ?list rdf:rest*/rdf:first ?member. }

SPARQL 1.1 Update ● Fine grain graph manipulations ● Act on a “graph store” ● Add and remove graphs ● Act on the contents of graphs ● Quad centric ● LOAD, DROP, CREATE ● INSERT, DELETE ● Data and patterns ● One request is multiple operations

Data Operations PREFIX rdf: PREFIX foaf: DELETE DATA { foaf:name “DEF”. } ; INSERT DATA { foaf:name “ABC”. } ;

Data Operations PREFIX rdf: PREFIX foaf: DELETE DATA { GRAPH { foaf:name “DEF”. } } ; INSERT DATA { GRAPH { foaf:name “ABC”. } } ;

Empty Graphs Graph stores not required to know about empty graphs. ● Quads stores with no graph management can't distinguish no graph (no quads) from empty graph (no quads) ● Stores that are collections of graphs often do have an “empty graph”

Pattern Operations : DELETE-INSERT PREFIX foaf: PREFIX vc: DELETE { ?p vc:fn ?x } INSERT { ?p foaf:name ?x } WHERE { GRAPH { ?p vc:fn ?x. ?p foaf:knows } } Pattern → Delete triples → Insert triples

Other INSERT and DELETE forms # INSERT with template-pattern INSERT { ?p foaf:name ?x } WHERE { GRAPH { ?p vc:fn ?x. ?p foaf:knows } } # DELETE with template-pattern DELETE { ?p foaf:name ?x } WHERE { GRAPH { ?p foaf:name ?x } } # DELETE WHERE DELETE WHERE { foaf:name ?x } ; DELETE WHERE { GRAPH { foaf:name ?x } } ;

Graph Management CREATE ; CREATE SILENT ; DROP ; DROP SILENT ; DROP ALL ; DROP NAMED ;

LOAD ; LOAD INTO GRAPH ; CLEAR DEFAULT ; CLEAR ALL ; CLEAR NAMED ; CLEAR GRAPH ; CLEAR SILENT GRAPH ; Whole Graph Operations

# ADD : triples added to a graph. # Source unchanged. ADD :graph1 TO DEFAULT ; ADD :graph1 TO ; # MOVE # Old contents lost. # Rename a graph MOVE :graph TO :graph2 ; # COPY # Copy over triples # Old contents lost. # Graph 2 is the same triples as :graph1. COPY :graph TO :graph2 ;

Q & A

PREFIX : PREFIX rdf: SELECT (?s1 AS ?subset) (?s2 AS ?superset) WHERE { ?s2 rdf:type :Set. ?s1 rdf:type :Set. FILTER(?s1 != ?s2) MINUS { ?s1 rdf:type :Set. ?s2 rdf:type :Set. FILTER(?s1 != ?s2) ?s1 :member ?x. FILTER NOT EXISTS { ?s2 :member ?x. } :. :a rdf:type :Set. :a :member 1. :a :member 2. :a :member 3. :b rdf:type :Set. :b :member 1. :b :member 9. :c rdf:type :Set. :c :member 1. :c :member 2. :d rdf:type :Set. :d :member 1. :d :member 9. :e rdf:type :Set. :e :member 1. :e :member 2. :empty rdf:type :Set. PREFIX : PREFIX rdf: SELECT (?s1 AS ?subset) (?s2 AS ?superset) WHERE { ?s2 rdf:type :Set. ?s1 rdf:type :Set. FILTER(?s1 != ?s2) MINUS { ?s1 rdf:type :Set. ?s2 rdf:type :Set. FILTER(?s1 != ?s2) ?s1 :member ?x. FILTER NOT EXISTS { ?s2 :member ?x. } :. :a rdf:type :Set. :a :member 1. :a :member 2. :a :member 3. :b rdf:type :Set. :b :member 1. :b :member 9. :c rdf:type :Set. :c :member 1. :c :member 2. :d rdf:type :Set. :d :member 1. :d :member 9. :e rdf:type :Set. :e :member 1. :e :member 2. :empty rdf:type :Set. Negation Use Case: Subset