Chapter 3A Semantic Web Primer 1 Chapter 3 Querying the Semantic Web Grigoris Antoniou Paul Groth Frank van Harmelen Rinke Hoekstra.

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

ESDSWG2011 – Semantic Web session Semantic Web Sub-group Session ESDSWG 2011 Meeting – Semantic Web sub-group session Wednesday, November 2, 2011 Norfolk,
RDF Tutorial.
Semantic Web Introduction
 Copyright 2004 Digital Enterprise Research Institute. All rights reserved. SPARQL Query Language for RDF presented by Cristina Feier.
CSC271 Database Systems Lecture # 11.
Concepts of Database Management Seventh Edition
Concepts of Database Management Sixth Edition
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
SPARQL for Querying PML Data Jitin Arora. Overview SPARQL: Query Language for RDF Graphs W3C Recommendation since 15 January 2008 Outline: Basic Concepts.
Tutorial 7: Using Advanced Functions and Conditional Formatting
Instructor: Craig Duckett CASE, ORDER BY, GROUP BY, HAVING, Subqueries
1 RDF Aggregate Queries and Views Edward Hung, Yu Deng, V.S. Subrahmanian University of Maryland, College Park ICDE 2005, April 7, Tokyo, Japan.
Introduction to Structured Query Language (SQL)
Database Systems More SQL Database Design -- More SQL1.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
Introduction to Structured Query Language (SQL)
A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.
Microsoft Access 2010 Chapter 7 Using SQL.
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
MS Access: Database Concepts Instructor: Vicki Weidler.
Chapter 2 Describing Web Resources: RDF
Logics for Data and Knowledge Representation SPARQL Protocol and RDF Query Language (SPARQL) Feroz Farazi.
RDF (Resource Description Framework) Why?. XML XML is a metalanguage that allows users to define markup XML separates content and structure from formatting.
Concepts of Database Management, Fifth Edition
Rajashree Deka Tetherless World Constellation Rensselaer Polytechnic Institute.
SPARQL All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link:
ASP.NET Programming with C# and SQL Server First Edition
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
Chapter 3 Single-Table Queries
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.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
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.
XP Agenda Video Last Class Excel Tutorial 5: Working with Excel Lists Agenda for Next Class 1 New Perspectives on Microsoft Office Excel 2003 Tutorial.
Analyzing Data For Effective Decision Making Chapter 3.
Lesley Charles November 23, 2009.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Concepts of Database Management Seventh Edition
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
RQL: RDF Query language Jianguo Lu University of Windsor The following slides are from Grigoris Antoniou, Frank van Harmelen, “A Semantic Web Primer”
Chapter 8: SQL. Data Definition Modification of the Database Basic Query Structure Aggregate Functions.
Database Applications – Microsoft Access Lesson 4 Working with Queries 36 Slides in Presentation.
Efficient RDF Storage and Retrieval in Jena2 Written by: Kevin Wilkinson, Craig Sayers, Harumi Kuno, Dave Reynolds Presented by: Umer Fareed 파리드.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Chapter 6 Creating, Sorting, and Querying a Table
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
05/01/2016 SPARQL SPARQL Protocol and RDF Query Language S. Garlatti.
Of 38 lecture 6: rdf – axiomatic semantics and query.
IS6146 Databases for Management Information Systems Lecture 1: Introduction to IS6146 Rob Gleasure robgleasure.com.
CC L A W EB DE D ATOS P RIMAVERA 2015 Lecture 7: SPARQL (1.0) Aidan Hogan
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Knowledge Technologies Manolis Koubarakis 1 Some Other Useful Features of RDF.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 5: SQL I Rob Gleasure robgleasure.com.
1 Chapter 3 Single Table Queries. 2 Simple Queries Query - a question represented in a way that the DBMS can understand Basic format SELECT-FROM Optional.
Chapter 04 Semantic Web Application Architecture 23 November 2015 A Team 오혜성, 조형헌, 권윤, 신동준, 이인용.
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
1 RDF Storage and Retrieval Systems Jan Pettersen Nytun, UiA.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Teacher Workshop Database Design Pearson Education © 2014.
SQL Query Getting to the data ……..
CC La Web de Datos Primavera 2017 Lecture 7: SPARQL [i]
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Instructor: Craig Duckett Lecture 09: Tuesday, April 25th, 2017
CC La Web de Datos Primavera 2016 Lecture 7: SPARQL (1.0)
CC La Web de Datos Primavera 2018 Lecture 8: SPARQL [1.1]
Semantic-Web, Triple-Strores, and SPARQL
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

Chapter 3A Semantic Web Primer 1 Chapter 3 Querying the Semantic Web Grigoris Antoniou Paul Groth Frank van Harmelen Rinke Hoekstra

2 Chapter 3A Semantic Web Primer 2 Lecture Outline 1. SPARQL Infrastructure 2. Basics: Matching Patterns 3. Filters 4. Constructs for Dealing with an Open World 5. Organizing Result Sets 6. Other forms of SPARQL Queries 7. Querying Schemas 8. Adding Information with SPARQL Update 9. The Follow Your Nose Principle 10. Summary

3 SPARQL Infrastructure To perform a SPARQL query, one needs software to execute the query The most common software that does this is called a triple store (三元组存储) ― a database for RDF Within the specifications for SPARQL, a triple store is termed as a Graph Store Chapter 3A Semantic Web Primer

4 Populating Triple Stores with RDF A triple store needs to be populated with RDF before one can query the triple store There is a mechanism called SPARQL Update that provides options for inserting and loading RDF into a triple store as well as deleting RDF from a triple store Chapter 3A Semantic Web Primer

5 SPARQL Endpoints One can query a triple store by sending SPARQL queries once data is loaded into the store Each triple store provides an endpoint to which SPARQL queries can be submitted Clients can send queries to an endpoint using the HTTP protocol Chapter 3A Semantic Web Primer

6 SPARQL Endpoints on the Web SPARQL uses standard Web technologies, so you will find numerous SPARQL endpoints on the Web These endpoints provide access to large amounts of data – e.g. dbpedia.org/sparql provides an endpoint to query over an RDF representation of Wikipedia – A complete list of SPARQL endpoints at CKAN.org Chapter 3A Semantic Web Primer

7 Chapter 3A Semantic Web Primer 7 Lecture Outline 1. SPARQL Infrastructure 2. Basics: Matching Patterns 3. Filters 4. Constructs for Dealing with an Open World 5. Organizing Result Sets 6. Other forms of SPARQL Queries 7. Querying Schemas 8. Adding Information with SPARQL Update 9. The Follow Your Nose Principle 10. Summary

8 A Previous Example of dbpedia-owl:. swp:BaronWayApartment swp:hasNumberOfBedrooms 3; swp:isPartOf swp:BaronWayBuilding. swp:BaronWayBuilding dbpedia-owl:location dbpedia:Amsterdam, dbpedia:Netherlands. Chapter 3A Semantic Web Primer

9 Expressing a Query in SPARQL We might like to ask a query over this data – for instance, find the location of the Baron Way building We would want to match the following triples: swp:BaronWayBuilding dbpedia-owl:location dbpedia:Amsterdam. swp:BaronWayBuilding dbpedia-owl:location dbpedia:Netherlands. Chapter 3A Semantic Web Primer

10 Expressing a Query in SPARQL We can just replace any component of the triple with a variable Variables are denoted by a preceding ? mark We can introduce a variable for location and write the following triple pattern (三元组模式) swp:BaronWayBuilding dbpedia-owl:location ?location. Chapter 3A Semantic Web Primer

11 Executing a SPARQL Query The triple store will take this triple pattern, or graph pattern, and try to find set of triples that match the pattern In this case, what the triple store would return? – dbpedia:Amsterdam and dbpedia:Netherlands The triple store finds all triples with swp:BaronWayBuilding as the subject and dbpedia- owl:location as the predicate Chapter 3A Semantic Web Primer

12 Making a Complete SPARQL Query First, all prefixes need to be defined PREFIX swp:. PREFIX dbpedia:. PREFIX dbpedia-owl:.  The PREFIX keyword denotes various abbreviations for URLs We also need to tell the triple store that we are interested in particular variables in the results  ?location Chapter 3A Semantic Web Primer

13 Making a Complete SPARQL Query A complete SPARQL would look like PREFIX swp:. PREFIX dbpedia:. PREFIX dbpedia-owl:. SELECT ?location WHERE { swp:BaronWayBuilding dbpedia-owl:location ?location. } – The SELECT keyword indicates which variables are of interest – The graph pattern that needs to be matched appears with brackets after the WHERE keyword Chapter 3A Semantic Web Primer

14 Results of a SPARQL Query The results of the query are returned in a set of mappings called bindings – Bindings denote which elements correspond to a given variable Each row in the table is a single result or binding ?location Chapter 3A Semantic Web Primer

15 Basis of SPARQL The whole basis of SPARQL is this simple notion of trying to find sets of triples that match a given graph pattern SPARQL provides functionality for specifying more complex graph patterns and providing results in different formats – The same procedure applies Chapter 3A Semantic Web Primer

16 Another Example SPARQL Query Find where the BaronWayApartment is located PREFIX swp:. PREFIX dbpedia:. PREFIX dbpedia-owl:. SELECT ?location WHERE { swp:BaronWayApartment swp:isPartOf ?building. ?building dbpedia-owl:location ?location. } Chapter 3A Semantic Web Primer

17 Another Example SPARQL Query SELECT ?location WHERE { swp:BaronWayApartment swp:isPartOf ?building. ?building dbpedia-owl:location ?location. } The graph pattern has been extended The variable is also in the subject position – can occurs in any position in the SPARQL query The query reuses the variable name ?building Chapter 3A Semantic Web Primer

18 Another Example SPARQL Query swp:BaronWayApartment swp:hasNumberOfBedrooms 3; swp:isPartOf swp:BaronWayBuilding. swp:BaronWayBuilding dbpedia-owl:location dbpedia:Amsterdam, dbpedia:Netherlands. SELECT ?location WHERE { swp:BaronWayApartment swp:isPartOf ?building. ?building dbpedia-owl:location ?location. } Chapter 3A Semantic Web Primer

19 Matching More Than One Single Variable in SPARQL Queries We might want to find all the information about Baron Way Apartment in the triple store SELECT ?p ?o WHERE { swp:BaronWayApartment ?p ?o. } ?p ?o swp:hasNumberOfBedrooms 3 swp:isPartOf swp:BaronWayBuilding Chapter 3A Semantic Web Primer

20 Limiting the Number of Answers to a SPARQL Query Chapter 3A Semantic Web Primer For small datasets, all possible answers can be easily returned For larger datasets, we may not know how many results there are or if the query would return a whole dataset It is good practice to limit the number of answers a query would return by using the LIMIT keyword

21 Using the LIMIT Keyword Chapter 3A Semantic Web Primer SELECT ?p ?o WHERE { swp:BaronWayApartment ?p ?o. } LIMIT 10 We limit the number of results to be returned to ten

22 Property Paths Chapter 3A Semantic Web Primer SPARQL provides a way of expressing concisely chains of properties – This facility is called property paths There are a number of property paths that can be used to help express long or arbitrary paths in SPARQL queries

23 An Example of Property Paths Chapter 3A Semantic Web Primer Find all the apartments which are part of a building in Amsterdam SELECT ?apartment WHERE { ?apartment swp:isPartOf ?building. ?building dbpedia-owl:location dbpedia:Amsterdam. }

24 An Example of Property Paths Chapter 3A Semantic Web Primer We can express the same thing as SELECT ?apartment WHERE { ?apartment swp:isPartOf/dbpedia-owl:location dbpedia:Amsterdam. }

25 Chapter 3A Semantic Web Primer 25 Lecture Outline 1. SPARQL Infrastructure 2. Basics: Matching Patterns 3. Filters 4. Constructs for Dealing with an Open World 5. Organizing Result Sets 6. Other forms of SPARQL Queries 7. Querying Schemas 8. Adding Information with SPARQL Update 9. The Follow Your Nose Principle 10. Summary

26 Chapter 3A Semantic Web Primer 26 Filters Sometimes we want to put more complex constraints on the results of queries – Those constraints can be expressed using filters (过滤器) For example, we would want to find apartments with more or less than a certain number of bedrooms We can ask this question in SPARQL using the FILTER keyword

27 Chapter 3A Semantic Web Primer 27 Using Filters SELECT ?apartment WHERE { ?apartment swp:hasNumberOfBedrooms ?bedrooms. FILTER (?bedrooms>2). } ?apartment swp:BaronWayAparment

28 Chapter 3A Semantic Web Primer 28 Numeric Filters and String Filters Less than, greater than, and equality are supported for numeric data types as well as date/time SPARQL allows for filtering on strings – e.g. assume that the dataset contains the triple: swp:BaronWayApartment swp:address “4 Baron Way Circle”. – We might want to find all the resources that contain “4 Baron Way” in their address

29 Chapter 3A Semantic Web Primer 29 Regular Expressions We can use regular expressions (常规表达式) which are supported within SPARQL Regular expressions are a powerful of expressing string searches The regular expression for find the string “4 Baron Way” at the beginning of another string is “^4 Baron Way”

30 Chapter 3A Semantic Web Primer 30 An Example of Using Regular Expressions in SPARQL Filters SELECT ?apartment WHERE { ?apartment swp:address ?address. FILTER regex (?address, “^4 Baron Way”). } A specific filter function name is introduced, regex, after the FILTER keyword Parameters are given in the parentheses afterwards

31 Chapter 3A Semantic Web Primer 31 The str Function The str function will convert resources and literals into string representations that can then be used in regex – e.g. we can search for Baron in the URL of the resource SELECT ?apartment ?address WHERE { ?apartment swp:address ?address. FILTER regex(str(?apartment), “Baron”). }

32 Chapter 3A Semantic Web Primer 32 Lecture Outline 1. SPARQL Infrastructure 2. Basics: Matching Patterns 3. Filters 4. Constructs for Dealing with an Open World 5. Organizing Result Sets 6. Other forms of SPARQL Queries 7. Querying Schemas 8. Adding Information with SPARQL Update 9. The Follow Your Nose Principle 10. Summary

33 Chapter 3A Semantic Web Primer 33 Open World Assumption Every resource on the Semantic Web may not be described using the same schema or does not have to share the same set of properties – unlike in the traditional database – This is called the open world assumption (开放世界 假设) – For instance, some apartments may be more well described than others or – they may be described using different ontologies

34 Chapter 3A Semantic Web Primer 34 An Example of Open World Assumption swp:BaronWayApartment swp:hasNumberOfBedrooms 3. swp:BaronWayApartment dbpedia-owl:location dbpedia:Amsterdam. swp:BaronWayApartment rdfs:label “Baron Way Apartment for Rent”. swp:FloridaAveStudio swp:hasNumberOfBedrooms 1. swp:FloridaAveStudio dbpedia-owl:locationCity dbpedia:Amsterdam. The Florida Ave studio does not have a human-friendly label Its location is described using dbpedia-owl:locationCity instead of dbpedia-owl:location

35 Chapter 3A Semantic Web Primer 35 Constructs for Dealing with an Open World Even with this inconsistency, we would still like to query over the data We want to find the apartments located in Amsterdam and return their human-friendly label if they have one SPARQL provides two constructs for expressing such a query: UNION and OPTIONAL

36 Chapter 3A Semantic Web Primer 36 Constructs for Dealing with an Open World SELECT ?apartment ?label WHERE { {?apartment dbpedia-owl:location dbpedia:Amsterdam.} UNION {?apartment dbpedia-owl:locationCity dbpedia:Amsterdam.} OPTIONAL {?apartment rdfs:label ?label.} } ?apartment ?label swp:BaronWayApartment Baron Way Apartment for Rent swp:FloridaAveStudio

37 Chapter 3A Semantic Web Primer 37 Constructs for Dealing with an Open World The UNION keyword tells the triple store to return results that match one or both graph patterns The OPTIONAL keyword tells the triple store to return results for a particular graph pattern if available – The graph pattern does not have to be satisfied for the query to return – Without the optional graph pattern, the Florida Ave studio would not have been returned

38 Chapter 3A Semantic Web Primer 38 Constructs for Dealing with an Open World Property paths can also be used to create a more concise SPARQL query by using | operator SELECT ?apartment ?label WHERE { {?apartment dbpedia-owl:location|dbpedia-owl:locationCity dbpedia:Amsterdam.} OPTIONAL {?apartment rdfs:label ?label.} }

39 Chapter 3A Semantic Web Primer 39 Lecture Outline 1. SPARQL Infrastructure 2. Basics: Matching Patterns 3. Filters 4. Constructs for Dealing with an Open World 5. Organizing Result Sets 6. Other forms of SPARQL Queries 7. Querying Schemas 8. Adding Information with SPARQL Update 9. The Follow Your Nose Principle 10. Summary

40 Chapter 3A Semantic Web Primer 40 Organizing Result Sets We often want the query result to be returned in a particular way – grouped, counted, or ordered SPARQL provides a number of functions to help organize the query result, for instance, LIMIT We can eliminate duplicate results from the result set using the DISTINCT keyword – e.g. SELECT DISTINCT ?name WHERE

41 Chapter 3A Semantic Web Primer 41 ORDER BY Keyword SPARQL enables the ordering of a returned result set using the ORDER BY keyword – e.g. we can ask for the apartments ordered by the number of bedrooms SELECT ?apartment ?bedrooms WHERE { ?apartment swp:hasNumberOfBedrooms ?bedrooms. } ORDER BY DESC(?bedrooms)

42 Chapter 3A Semantic Web Primer 42 ORDER BY Keyword The keyword DESC denotes descending order and ASC denotes ascending order Ordering strings or urls is done alphabetically ?apartment ?bedrooms swp:BaronWayApartment 3 swp:FloridaAveStudio 1

43 Chapter 3A Semantic Web Primer 43 Collecting Results Using Aggregate Functions Aggregates (统计值) are used where the querier wishes to see a result which is computed over a group of results We can count the number of results using COUNT We can get a sum over the results using SUM, We can also compute the minimum, maximum, and average of the result set using MIN, MAX, and AVG

44 Chapter 3A Semantic Web Primer 44 Collecting Results Using Aggregate Functions An example to compute the average number of bedrooms in the dataset SELECT (AVG(?bedrooms) AS ?avgNumRooms) WHERE { ?apartment swp:hasNumberOfBedrooms ?bedrooms. } ?avgNumRooms 2

45 Chapter 3A Semantic Web Primer 45 Collecting Results Using Aggregate Functions The aggregate function AVG is combined with the keyword AS to denote the variable in the result set We are not limited to applying these aggregations over the entire result set We can also aggregate for particular groups using the GROUP BY keyword ( sparql11-query /#groupby)

46 Chapter 3A Semantic Web Primer 46 Collecting Results Using Aggregate Functions For example, given a list of variable bindings S, ( {?x→2, ?y→3}, {?x→2, ?y→5}, {?x→6, ?y→7} ), we might wish to group the bindings according to the value of ?x, and calculate the average of the values of ?y for each group. This could be written as: SELECT (AVG(?y) AS ?avg) WHERE { ?a :x ?x ; :y ?y. } GROUP BY ?x Result?

47 Chapter 3A Semantic Web Primer 47 Lecture Outline 1. SPARQL Infrastructure 2. Basics: Matching Patterns 3. Filters 4. Constructs for Dealing with an Open World 5. Organizing Result Sets 6. Other forms of SPARQL Queries 7. Querying Schemas 8. Adding Information with SPARQL Update 9. The Follow Your Nose Principle 10. Summary

48 Chapter 3A Semantic Web Primer 48 ASK Form So far we have focused on selecting certain values from a set of RDF data SPARQL also supports other forms of queries: ASK and CONSTRUCT The ASK form simply checks whether a graph pattern exists in a dataset instead of returning a result set (the following one would return true) ASK { ?apartment swp:hasNumberOfBedrooms 3.}

49 Chapter 3A Semantic Web Primer 49 CONSTRUCT Form The CONSTRUCT form is used to retrieve an RDF graph from a larger set of RDF Thus, one can query a triple store and retrieve an RDF graph other than a list of variable bindings For instance, we can create a new graph that labels big apartments as those having more than 2 bedrooms

50 Chapter 3A Semantic Web Primer 50 An Example of CONSTRUCT Form PREFIX ex: PREFIX dbpedia: PREFIX geo: CONSTRUCT { ?apartment swp:hasNumberOfBedrooms ?bedrooms. ?apartment swp:isBigApartment true.} WHERE { ?apartment swp:hasNumberOfBedrooms ?bedrooms. FILTER (?bedrooms > 2) }

51 Chapter 3A Semantic Web Primer 51 An Example of CONSTRUCT Form The query would return the following xsd:. swp:BaronWayApartment swp:hasNumberOfBedrooms 3. swp:BaronwayApartment swp:isBigApartment true.

52 Chapter 3A Semantic Web Primer 52 Lecture Outline 1. SPARQL Infrastructure 2. Basics: Matching Patterns 3. Filters 4. Constructs for Dealing with an Open World 5. Organizing Result Sets 6. Other forms of SPARQL Queries 7. Querying Schemas 8. Adding Information with SPARQL Update 9. The Follow Your Nose Principle 10. Summary

53 Chapter 3A Semantic Web Primer 53 Querying Schemas Schema information is represented in RDF, so SPARQL can be used to query information about the schema For example, we can use the following ontology from the previous rdfs:.

54 Chapter 3A Semantic Web Primer 54 Querying Schemas swp:Unit rdf:type rdfs:Class. swp:ResidentialUnit rdf:type rdfs:Class. swp:ResidentialUnit rdfs:subClassOf swp:Unit. swp:Apartment rdf:type rdfs:Class. swp:Apartment rdfs:subClassOf swp:ResidentialUnit.

55 Chapter 3A Semantic Web Primer 55 Querying Schemas We can determine the Residential Units by querying both the instance data and the schema simultaneously PREFIX swp:. PREFIX rdfs:. SELECT ?apartment WHERE { ?apartment rdf:type ?unitType. ?unitType rdfs:subClassOf swp:ResidentialUnit. }

56 Chapter 3A Semantic Web Primer 56 Lecture Outline 1. SPARQL Infrastructure 2. Basics: Matching Patterns 3. Filters 4. Constructs for Dealing with an Open World 5. Organizing Result Sets 6. Other forms of SPARQL Queries 7. Querying Schemas 8. Adding Information with SPARQL Update 9. The Follow Your Nose Principle 10. Summary

57 Chapter 3A Semantic Web Primer 57 SPARQL Update Protocol SPARQL update protocol is intended to update the contents of a triple store It adds a series of keywords to SPARQL that allows for the insertion, loading, and deletion of triples

58 Chapter 3A Semantic Web Primer 58 Inserting Triples The following inserts a statement that says Luxury Apartment is a subclass of Apartment PREFIX swp:. PREFIX rdfs:. INSERT DATA { swp:LuxuryApartment rdfs:subClassOf swp:Apartment. }

59 Chapter 3A Semantic Web Primer 59 Loading Triples If you have a large file containing RDF available on the Web, you can load it into a triple store using the following command: LOAD

60 Chapter 3A Semantic Web Primer 60 Deleting Triples One way of deleting triples from a triple store is to specify exactly which triples you want to delete using the DELETE DATA keyword PREFIX swp:. PREFIX rdfs:. DELETE DATA { swp:LuxuryApartment rdfs:subClassOf swp:Apartment. }

61 Chapter 3A Semantic Web Primer 61 Deleting Triples in a More Flexible Form One can use the DELETE WHERE construct to delete triples in a more flexible manner Triples that are matched by the specified graph pattern will be removed DELETE WHERE { ?apartment swp:hasNumberOfBedrooms ?bedrooms. FILTER (?bedrooms > 2) }

62 Chapter 3A Semantic Web Primer 62 Deleting All Triples One can use the CLEAR construct to delete all the triples in the default graph, all named graphs, or all graphs of a triple store CLEAR DEFAULT | NAMED | ALL SPARQL Update provides several more constructs for managing parts of triple stores – see SPARQL 1.1 Update at update/ update/

63 Chapter 3A Semantic Web Primer 63 Lecture Outline 1. SPARQL Infrastructure 2. Basics: Matching Patterns 3. Filters 4. Constructs for Dealing with an Open World 5. Organizing Result Sets 6. Other forms of SPARQL Queries 7. Querying Schemas 8. Adding Information with SPARQL Update 9. The Follow Your Nose Principle 10. Summary

64 Chapter 3A Semantic Web Primer 64 How Triple Stores Get Populated? Many data providers make their data available via SPARQL endpoints However, other data providers only make their data available as Linked Data – That is, RDF data are available either as files on the Web or embedded in Web pages We can insert these triples into our local triple store

65 Chapter 3A Semantic Web Primer 65 The Follow Your Nose Principle The Semantic Web allows any providers to describe their information using other resources and information on the Web The follow your nose principle can be applied: For any given URL that points to an RDF file, one can dereference that URL and load the corresponding data One can continue to do so until there are enough triples for answering the given queries

66 Chapter 3A Semantic Web Primer 66 The Follow Your Nose Principle Query search engines such as SQUIN ( implement this feature The newer version of SPARQL includes commands for such federated ( 联合 ) querying, which offers data consumers an opportunity to merge data distributed across the Web and is often time intensive Following your nose is one way to collect the information needed for process a query using the Semantic Web

67 Chapter 3A Semantic Web Primer 67 Lecture Outline 1. SPARQL Infrastructure 2. Basics: Matching Patterns 3. Filters 4. Constructs for Dealing with an Open World 5. Organizing Result Sets 6. Other forms of SPARQL Queries 7. Querying Schemas 8. Adding Information with SPARQL Update 9. The Follow Your Nose Principle 10. Summary

68 Chapter 3A Semantic Web Primer 68 Summary SPARQL selects information by matching graph patterns SPARQL provides facilities for filtering based on both numeric and string comparisons SPARQL queries follow a syntax similar to Turtle Both data and schema can be queried using SPARQL

69 Chapter 3A Semantic Web Primer 69 Summary UNION and OPTIONAL are constructs that allow SPARQL to more easily deal with open world data SPARQL Update provides mechanisms for updating and deleting information from triple stores