Alexandra Cristea 1.  pronounced "sparkle“  recursive acronym for: ◦ SPARQL Protocol and RDF Query Language  a semantic query language  a query language.

Slides:



Advertisements
Similar presentations
1 SPARQL: A query language for RDF Matthew Yau
Advertisements

Alexandra Cristea & Matthew Yau 1.
CH-4 Ontologies, Querying and Data Integration. Introduction to RDF(S) RDF stands for Resource Description Framework. RDF is a standard for describing.
Introduction to RDF Based on tutorial at
ESDSWG2011 – Semantic Web session Semantic Web Sub-group Session ESDSWG 2011 Meeting – Semantic Web sub-group session Wednesday, November 2, 2011 Norfolk,
RDF Tutorial.
 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.
5/17/20151 FOAF. 5/17/20152 Introduction Metadata is data about data The terms refer to data used to identify, describe, or locate information resources.
SPARQL for Querying PML Data Jitin Arora. Overview SPARQL: Query Language for RDF Graphs W3C Recommendation since 15 January 2008 Outline: Basic Concepts.
CSCI 572 Project Presentation Mohsen Taheriyan Semantic Search on FOAF profiles.
Dr. Alexandra I. Cristea RDF.
RDF: Building Block for the Semantic Web Jim Ellenberger UCCS CS5260 Spring 2011.
Semantic Web Query Processing with Relational Databases Artem Chebotko Department of Computer Science Wayne State University.
Module 2b: Modeling Information Objects and Relationships IMT530: Organization of Information Resources Winter, 2007 Michael Crandall.
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.
1 Ontology Query and Reasoning Payam Barnaghi Institute for Communication Systems (ICS) Faculty of Engineering and Physical Sciences University of Surrey.
RDF (Resource Description Framework) Why?. XML XML is a metalanguage that allows users to define markup XML separates content and structure from formatting.
SPARQL All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link:
1cs The Need “Most of the Web's content today is designed for humans to read, not for computer programs to manipulate meaningfully.” Berners-Lee,
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.
RDF Query language The following slides are from Grigoris Antoniou, Frank van Harmelen, “A Semantic Web Primer” Dean Allemang, Jim Hendler, “Semantic Web.
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.
By: Dan Johnson & Jena Block. RDF definition What is Semantic web? Search Engine Example What is RDF? Triples Vocabularies RDF/XML Why 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.
RDF and triplestores CMSC 461 Michael Wilson. Reasoning  Relational databases allow us to reason about data that is organized in a specific way  Data.
EEL 5937 Ontologies EEL 5937 Multi Agent Systems Lecture 5, Jan 23 th, 2003 Lotzi Bölöni.
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!
Semantic Web Basics Dominic DiFranzo PhD Student/Research Assistant Rensselaer Polytechnic Institute Tetherless World Constellation.
Tool for Ontology Paraphrasing, Querying and Visualization on the Semantic Web Project By Senthil Kumar K III MCA (SS)‏
The future of the Web: Semantic Web 9/30/2004 Xiangming Mu.
Introduction to the Semantic Web and Linked Data Module 1 - Unit 2 The Semantic Web and Linked Data Concepts 1-1 Library of Congress BIBFRAME Pilot Training.
Dr. Lowell Vizenor Ontology and Semantic Technology Practice Lead Alion Science and Technology Semantic Technology: A Basic Introduction.
1cs The Need “Most of the Web's content today is designed for humans to read, not for computer programs to manipulate meaningfully.” Berners-Lee,
05/01/2016 SPARQL SPARQL Protocol and RDF Query Language S. Garlatti.
Chapter 3 Querying RDF stores with SPARQL
THE SEMANTIC WEB By Conrad Williams. Contents  What is the Semantic Web?  Technologies  XML  RDF  OWL  Implementations  Social Networking  Scholarly.
EEL 5937 Ontologies EEL 5937 Multi Agent Systems Lotzi Bölöni.
CC L A W EB DE D ATOS P RIMAVERA 2015 Lecture 7: SPARQL (1.0) Aidan Hogan
Internet Technologies 1 Master of Information System Management Internet Technologies Making Queries on RDF.
Graph and RDF Databases Context : Course of Advanced Databases Prepared by : Nassim BAHRI Nabila HOSNI February 19th, 2015.
Semantic Web for the Working Ontologist Dean Allemang Jim Hendler SNU IDB laboratory.
Semantic Web in Depth RDFa, GRDDL and POWDER Dr Nicholas Gibbins
Semantic Web in Depth SPARQL Protocol and RDF Query Language Dr Nicholas Gibbins –
Setting the stage: linked data concepts Moving-Away-From-MARC-a-thon.
1 RDF Storage and Retrieval Systems Jan Pettersen Nytun, UiA.
Vincenzo Maltese, Fausto Giunchiglia University of Trento
CC La Web de Datos Primavera 2017 Lecture 7: SPARQL [i]
SPARQL.
RDF and RDB 1 Some slides adapted from a presentation by Ivan Herman at the Semantic Technology & Business Conference, 2012.
Introduction to SPARQL
SPARQL SPARQL Protocol and RDF Query Language
SPARQL: A query language for RDF
Jan Pettersen Nytun, UiA
Logics for Data and Knowledge Representation
CC La Web de Datos Primavera 2016 Lecture 7: SPARQL (1.0)
JSON for Linked Data: a standard for serializing RDF using JSON
Logics for Data and Knowledge Representation
Presentation transcript:

Alexandra Cristea 1

 pronounced "sparkle“  recursive acronym for: ◦ SPARQL Protocol and RDF Query Language  a semantic query language  a query language for RDF(S)  W3C Recommendation 15 th January 2008 ◦ provides a standard format for writing queries that target RDF data ◦ and a set of standard rules for processing queries and returning the results  2

 New version: 21 st of March 2013:   Query language at:   Implemented in various programming languages 3

4 Subject Predicate author Object Jan Egil Refsnes SPARQL searches for all sub-graphs that match the graph described by the triples in the query. ?subject ?predicate ?object

SELECT ?student WHERE { ?student b:studies bmod:CS414 } ~ SQL – why? Which are the namespace prefixes? 5

In RDF: In SPARQL: PREFIX b: PREFIX bmod: <  The PREFIX keyword is SPARQL ’ s version of an xmlns:namespace declaration and works in basically the same way. 6

PrefixIRI rdf: rdfs: xsd: fn: sfn: 7 Prefixes are not optional in SPARQL!

 Capitals of Europe: 8

    9

    - Fluidops     

 OpenLink Query point ◦  Semanticweb.org data: ◦  Diseases: ◦  Country statistics: ◦  Nobelprize info: ◦  W3C’s list of endpoints: ◦

   ◦ make sure to allow at ‘Sponging’ to ‘Retrieve remote RDF data for all missing source graphs’ 

 Different syntax from XML  Variables: begin with ? or $  triples patterns enclosed within braces {}  Result: variables after SELECT (~SQL) 13

 PREFIX foo:  PREFIX bar:  SELECT …  FROM …  WHERE {…}  GROUP BY …  HAVING …  ORDER BY …  LIMIT …  OFFSET …  VALUES … 14 ~ SQL

 SELECT queries  CONSTRUCT queries  ASK queries  DESCRIBE queries 15

PREFIX foaf: SELECT ?x ?y ?z FROM WHERE { ?x ?y ?z } 16

PREFIX b: PREFIX bmod: PREFIX foaf: SELECT ?name WHERE { ?student b:studies bmod:CS328. ?student foaf:name ?name } 17

 FOAF (Friend Of A Friend)  experimental project using RDF, defining a standardised vocabulary.  Goal: make personal homepages machine- readable & understandable, create an internet- wide connected database of people. Defined at: 18

 Idea: most personal homepages contain similar info. ◦ E.g, person’s name, living place, work place, details on work of the moment, links to friends. ◦ define RDF predicates to represent them. ◦ So: Pages: understood/ manipulated by computers.  So a db can be queried for: ◦ “ what projects are my friends working on? ”, ◦ “ do any of my friends know the director of BigCorp? ” etc.. 19

Alexandra I. Cristea <foaf:mbox rdf:resource=" mailto: "/> 20

<rdf:RDF xmlns:rdf=" xmlns:rdfs=" xmlns:foaf=" Peter Brusilovsky Peter Brusilovsky 1fa1a097b3fae4594fa0ec18e2e3da11ac7e0349 Alexandra I. Cristea dba246a0d9ec4a f9a035a7a608ff227f8 sha1sum dba246a0d9ec4a f9a035a7a608ff227f8 21

PREFIX b: PREFIX bmod: PREFIX foaf: SELECT ?module ?name WHERE { ?student b:studies ?module. ?student foaf:name ?name } 22

PREFIX b: PREFIX bmod: terial/ PREFIX foaf: < SELECT ?module ?name WHERE { ?student b:studies ?module ; foaf:name ?name } 23

SELECT ?module ?name WHERE { ?student b:studies ?module. ?student b:studies bmod:CS328 ; foaf:name ?name } is identical to: SELECT ?module ?name WHERE { ?student b:studies ?module, bmod:CS328 ; foaf:name ?name } 24

SELECT ?student ? WHERE { ?student b:studies mod:CS328. ?student foaf:mbox ? }  PB: if a student does not have an address registered, with a foaf:mbox predicate, then the query will not match !! 25

SELECT ?student ? WHERE { ?student b:studies mod:CS328. OPTIONAL { ?student foaf:mbox ? } }  OPTIONAL: match it if it can, but otherwise not reject the overall pattern. 26

 SPARQL basics  SPARQL endpoints: dbpedia, foaf, others  SPARQL type of queries: ◦ SELECT; CONSTRUCT; ASK; DESCRIBE  SQL-like constructs: ◦ SELECT; FROM; WHERE; GROUP BY; HAVING; ORDER BY; LIMIT; OFFSET; VALUES  Some specific constructs: ◦ PREFIX not optional; FROM not always used; OPTIONAL ◦ We are going to look at more specific constructs 27

 Try out at: PREFIX books: PREFIX dc: SELECT $book WHERE {$book title $title }  >> this gives an empty answer/ error.  Versus: PREFIX books: PREFIX dc: SELECT $book WHERE {$book dc:title $title } 28

 try out at : With or without optional PREFIX books: PREFIX dc: SELECT ?book ?author ?title ?date WHERE { ?book dc:creator ?author. ?book dc:title ?title. ?book dc:date ?date } PREFIX books: PREFIX dc: SELECT ?book ?author ?title ?date WHERE { ?book dc:creator ?author. ?book dc:title ?title. OPTIONAL { ?book dc:date ?date } } 29

 Try analysing RDF documents  e.g.:  (on or Protégé, or specific endpoints)  Using SPARQL to find Concepts  endpoints Dbpedia SNORQL query explorer ( the BBC Backstage SPARQL Editor ( or GeoSparql ( to analyse content.Dbpedia SNORQL query explorerBBC Backstage SPARQL EditorGeoSparql  Listing DISTINCT RDF Types  The following query lists the distinct rdf:types used in a dataset  PREFIX rdf: SELECT DISTINCT ?type WHERE { ?s rdf:type ?type }  Listing OWL Classes PREFIX owl: SELECT ?class WHERE { ?class a owl:Class } 30

SELECT ?module ?name ?phone WHERE { ?student b:studies ?module. ?student foaf:name ?name. OPTIONAL { ?student b:contactpermission true. ?student b:phone ?phone } SELECT ?module ?name ?age WHERE { ?student b:studies ?module. ?student foaf:name ?name. OPTIONAL { ?student b:age ?age. FILTER (?age > 25) } } 31

SELECT ?student ? ?home WHERE { ?student b:studies mod:CS328. OPTIONAL { ?student foaf:mbox ? . ?student foaf:homepage ?home } } SELECT ?student ? ?home WHERE { ?student b:studies mod:CS328. OPTIONAL { ?student foaf:mbox ? }. OPTIONAL { ?student foaf:homepage ?home } } 32

SELECT ?student WHERE { ?student foaf:mbox ? . { ?student b:studies mod:CS328 } UNION { ?student b:studies mod:CS909 } }  When patterns are combined using the UNION keyword, the resulting combined pattern will match if any of the subpatterns is matched. 33

 Consider A and B as graph patterns.  { A } UNION { B } ◦ Either / or graph patterns ◦ Disjunction; include both the results of solving A and the results of solving B  { A } MINUS { B } ◦ “subtracted” graph patterns (SPARQL 1.1) ◦ Negation; Solve A; Solve B; Include only those results from A that are not compatible with any of the results from B. 34

 All the previous queries: single RDF graphs.  Often: multiple RDF graphs.  RDF graphs: identified by IRI. ◦ Note: IRI that represents the graph does not have to be the actual IRI of the graph file ◦ although the program processing the query will need to somehow relate the IRI to an actual RDF graph stored somewhere. 35

SELECT ?student ? ?home FROM WHERE { ?student b:studies mod:CS414. OPTIONAL { ?student foaf:mbox ? . ?student foaf:homepage ?home } } By using several FROM declarations, you can combine several graphs in the dataset: SELECT ?student ? ?home FROM WHERE { ?student b:studies mod:CS414. OPTIONAL { ?student foaf:mbox ? . ?student foaf:homepage ?home } } 36

 one (optional) default graph  + any number of named graphs.  FROM specifies default graph. ◦ Many FROM keywords, the graphs are merged into the default graph.  Additionally: named graphs, w FROM NAMED. ◦ However, to match patterns you must use GRAPH keyword to state which graph ! 37

SELECT ?student ? ?home FROM NAMED FROM NAMED WHERE { GRAPH { ?student b:studies mod:CS909 }. GRAPH { OPTIONAL { ?student foaf:mbox ? . ?student foaf:homepage ?home } } 38

PREFIX brdf: SELECT ?student ? ?home FROM NAMED FROM NAMED WHERE { GRAPH brdf:student { ?student b:studies mod:CS909 }. GRAPH brdf:foaf{ OPTIONAL { ?student foaf:mbox ? . ?student foaf:homepage ?home } } 39

PREFIX brdf: SELECT ?student ? ?home FROM FROM NAMED WHERE { ?student b:studies mod:CS909. GRAPH brdf:foaf{ OPTIONAL { ?studentfoaf:mbox? . ?studentfoaf:homepage ?home } } 40

 the GRAPH can also be a variable. ◦ to query which graph in the dataset holds a particular relationship, ◦ or which graph to search based on data in another graph.  not mandatory to declare all graphs ◦ even if specified, the dataset can be overridden on a per-query basis. 41

PREFIX brdf: SELECT ?student ?graph WHERE { ?student b:studies mod:CS909. GRAPH ?graph { ?student foaf:mbox ? }  output var graph holds graph URL (matching student to address).  Presumption: query processor has knowledge of a finite set of graphs + their locations 42

PREFIX brdf: SELECT ?student ? WHERE { ?student b:studies mod:CS909. ?student rdfs:seeAlso ?graph. GRAPH ?graph { ?student foaf:mbox ? }  Note: if student doesn’t have a rdfs:seeAlso property which points to a graph holding their address, they will not appear in the result at all. 43

 Specific SPARQL constructs: ◦ Revisited OPTIONAL, PREFIX, FROM - single ◦ New ones: FILTER, UNION, MINUS, FROM –multiple, FROM NAMED, GRAPH, GRAPH with prefix, GRAPH as (query-able + reusable) variable  More online/ offline queries: ◦ Endpoints ◦ Sparql.com ◦ Protégé  Next: other SQL-like constructs; non-SQL-like behaviour: ASK, DESCRIBE, CONSTRUCT 44

SELECT ?name ?module WHERE { ?student b:studies ?module. ?student foaf:name ?name } ORDER BY ?name SELECT ?name ?age WHERE { ?student b:age ?age. ?student foaf:name ?name } ORDER BY DESC (?age) ASC (?name) 45

SELECT ?name ?module WHERE { ?student b:studies ?module. ?student foaf:name ?name } LIMIT 20 46

SELECT ?name ?module WHERE { ?student b:studies ?module. ?student foaf:name ?name } ORDER BY ?name OFFSET 10 LIMIT 20 47

SELECT ?student WHERE { ?student b:studies ?module } versus: SELECT DISTINCT ?student WHERE { ?student b:studies ?module } 48

 Is any student studying any module? ASK { ?student b:studies ?module }  Is any student studying CS909? ASK { ?student b:studies bmod:CS909 }  Is student studying CS909? ASK { bstu: b:studies bmod:CS909 }  Is anyone whom knows, studying CS909? ASK {bstu: foaf:knows ?x. ?x b:studies bmod: CS909 }  Is any student aged over 30 studying CS909? ASK { ?student b:studies bmod:CS909. ?student b:age ?age. FILTER { ?age > 30 } } 49

CONSTRUCT { ?student b:studyFriend ?friend } WHERE { ?student b:studies ?module. ?student foaf:knows ?friend. ?friend b:studies ?module } }  If there is more than one search result, the triples from each result are combined. 50

 DESCRIBE ?country  Result is in RDF triples, in any RDF serialization 51

52

53

54

 [1] Dean Allemang & Jim Hendler Semantic Web for the working ontologist. Morgan Kaufmann publishers. ISBN  [2] Eric Prud'hommeaux ; & Andy Seaborne SPARQL Query Language for RDF, [Online]

 Download Jena from  Prot é g é 3.4 and above  Fuseki: x.html x.html 56

 SPARQL language is used for querying RDF.  SPARQL is not based on XML, but on SQL- like syntax.  Building blocks of SPARQL queries are graph patterns that include variables. The result of the query will be the values the vars must take to match the RDF graph.  A SPARQL query can return results in several different ways, as determined by the query.  SPARQL queries can also be used for OWL querying. 57

58