Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mon norton tut_queryinglinkeddata02

413 views

Published on

  • Be the first to comment

  • Be the first to like this

Mon norton tut_queryinglinkeddata02

  1. 1. Querying Linked Data Presented by: Barry Norton
  2. 2. Motivation: Music! 2 Visualiza6on Module Metadata Physical Wrapper Streaming providers Downloads Access Data acquisi6on LD Wrapper D2R Transf. Musical Content Applica6on Analysis & Mining Module LD Dataset LD Wrapper RDF/ XML Integrated Dataset Vocabulary Interlinking Cleansing Mapping SPARQL Endpoint Publishing RDFa Other content
  3. 3. Agenda 1. Introduc+on to SPARQL 2. Querying Linked Data with SPARQL 3. SPARQL Algebra 4. Upda+ng Linked Data with SPARQL 1.1 5. SPARQL Protocol 6. Reasoning over Linked Data EUCLID -­‐ Querying Linked Data 3
  4. 4. INTRODUCTION TO SPARQL EUCLID -­‐ Querying Linked Data 4
  5. 5. SPARQL Seman6c Web Stack Berners-­‐Lee (2006) * Protocol and RDF Query Language EUCLID -­‐ Querying Linked Data 5 Declara6ve query language
  6. 6. SPARQL EUCLID -­‐ Querying Linked Data 6 • SPARQL Query – Declara6ve query language for RDF data – hp://www.w3.org/TR/rdf-­‐sparql-­‐query/ • SPARQL Algebra – Standard for communica6on between SPARQL services and clients – hp://www.w3.org/2001/sw/DataAccess/rq23/rq24-­‐algebra.html • SPARQL Update – Declara6ve manipula6on language for RDF data – hp://www.w3.org/TR/sparql11-­‐update/ • SPARQL Protocol – Standard for communica6on between SPARQL services and clients – hp://www.w3.org/TR/sparql11-­‐protocol/
  7. 7. SPARQL Query 1.1 • Aggregates, Subqueries, Nega6on, Expressions in the SELECT clause, Property paths, assignment, short form for CONSTRUCT, expanded set of func6ons and operators EUCLID -­‐ Querying Linked Data 7 • SPARQL 1.0 only allows accessing the data (query) • SPARQL 1.1 introduces: Query extensions Updates • Data management: Insert, Delete, Delete/Insert • Graph management: Create, Load, Clear, Drop, Copy, Move, Add Federa6on extension • Service, values, service variables (informa6ve) CH 5
  8. 8. SPARQL Basics dbpedia:The_Beatles foaf:name "The Beatles" . dbpedia:The_Beatles foaf:made ?album. ?album mo:track ?track . ?album ?p ?o . EUCLID -­‐ Querying Linked Data 8 • RDF triple: Basic building block, of the form subject, predicate, object. Example: • RDF triple paNern: Contains one or more variables. Examples: • RDF quad paNern: Contains graph name: URI or variable. Examples: GRAPH <:g> {:s :p :o .} GRAPH ?g {dbpedia:The_Beatles foaf:name ?o.}
  9. 9. SPARQL Basics EUCLID -­‐ Querying Linked Data 9 • RDF graph: Set of RDF asser6ons, manipulated as a labeled directed graph. • RDF data set: set of RDF triples. It is comprised of: • One default graph • Zero or more named graphs • SPARQL protocol client: HTTP client that sends requests for SPARQL Protocol opera6ons (queries or updates) • SPARQL protocol service: HTTP server that services requests for SPARQL Protocol opera6ons • SPARQL endpoint: The URI at which a SPARQL Protocol service listens for requests from SPARQL clients
  10. 10. QUERYING LINKED DATA WITH SPARQL EUCLID -­‐ Querying Linked Data 10
  11. 11. SPARQL Query EUCLID -­‐ Querying Linked Data 11 Main idea: PaNern matching • Queries describe sub-­‐graphs of the queried graph • Graph paNerns are RDF graphs specified in Turtle syntax, which contain variables (prefixed by either “?” or “$”) • Sub-­‐graphs that match the graph paerns yield a result dbpedia: ?album The_Beatles foaf:made
  12. 12. SPARQL Query foaf:made foaf:made dc:6tle EUCLID -­‐ Querying Linked Data 12 dbpedia: ?album The_Beatles foaf:made dbpedia: foaf:made The_Beatles <hp:// musicbrainz.org /record/...> <hp:// musicbrainz.org /record/...> Data: Graph paern: Results: "Help!" "Let It Be" dc:6tle dc:6tle <hp:// musicbrainz.org /record/...> "Abbey Road" ?album <hp://musicbrainz.org...> <hp://musicbrainz.org...> <hp://musicbrainz.org...>
  13. 13. SPARQL Query foaf:made dc:6tle ?album foaf:made dc:6tle EUCLID -­‐ Querying Linked Data 13 dbpedia: The_Beatles dbpedia: foaf:made The_Beatles <hp:// musicbrainz.org /record/...> <hp:// musicbrainz.org /record/...> Data: Graph paern: Results: "Help!" "Let It Be" dc:6tle dc:6tle <hp:// musicbrainz.org /record/...> "Abbey Road" ?album ?+tle <hp://...> "Help!" <hp://...> "Abbey Road" <hp://...> "Let It Be" ?6tle
  14. 14. SPARQL Query ?album foaf:made EUCLID -­‐ Querying Linked Data 14 dbpedia: The_Beatles dbpedia: foaf:made The_Beatles <hp:// musicbrainz.org /record/...> <hp:// musicbrainz.org /track/...> Data: Graph paern: Results: "Help!" "Help!" dc:6tle dc:6tle mo:track a mo:Record mo:Track mo:Record ?album <hp://musicbrainz.org...>
  15. 15. SPARQL Query: Components PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX mo: <http://purl.org/ontology/mo/> SELECT ?album FROM <http://musicbrainz.org/20130302> WHERE { dbpedia:The_Beatles foaf:made ?album . ?album a mo:Record ; dc:title ?title EUCLID -­‐ Querying Linked Data 15 } ORDER BY ?title Prologue: • Prefix defini6ons • Subtly different from Turtle syntax -­‐ the final period is not used
  16. 16. SPARQL Query: Components PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX mo: <http://purl.org/ontology/mo/> SELECT ?album FROM <http://musicbrainz.org/20130302> WHERE { dbpedia:The_Beatles foaf:made ?album . ?album a mo:Record ; dc:title ?title EUCLID -­‐ Querying Linked Data 16 } ORDER BY ?title Query form: • ASK, SELECT, DESCRIBE or CONSTRUCT • SELECT retrieves variables and their bindings as a table
  17. 17. SPARQL Query: Components PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX mo: <http://purl.org/ontology/mo/> SELECT ?album FROM <http://musicbrainz.org/20130302> WHERE { dbpedia:The_Beatles foaf:made ?album . ?album a mo:Record ; dc:title ?title EUCLID -­‐ Querying Linked Data 17 } ORDER BY ?title Data set specifica+on: • This clause is op6onal • FROM or FROM NAMED • Indicates the sources for the data against which to find matches
  18. 18. SPARQL Query: Components PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX mo: <http://purl.org/ontology/mo/> SELECT ?album FROM <http://musicbrainz.org/20130302> WHERE { dbpedia:The_Beatles foaf:made ?album . ?album a mo:Record ; dc:title ?title EUCLID -­‐ Querying Linked Data 18 } ORDER BY ?title Query paNern: • Defines paerns to match against the data • Generalises Turtle with variables and keywords – N.B. final period op6onal
  19. 19. SPARQL Query: Components PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX mo: <http://purl.org/ontology/mo/> SELECT ?album FROM <http://musicbrainz.org/20130302> WHERE { dbpedia:The_Beatles foaf:made ?album . ?album a mo:Record ; dc:title ?title Solu+on modifier: • Modify the result set • ORDER BY, LIMIT or OFFSET re-­‐organise rows; • GROUP BY combines them EUCLID -­‐ Querying Linked Data 19 } ORDER BY ?title
  20. 20. Query Forms SPARQL supports different query forms: • ASK tests whether or not a query paern has a solu6on. Returns yes/no • SELECT returns variables and their bindings EUCLID -­‐ Querying Linked Data 20 directly • CONSTRUCT returns a single RDF graph specified by a graph template • DESCRIBE returns a single RDF graph containing RDF data about resource
  21. 21. Query Form: ASK Is Paul McCartney member Results: Results: EUCLID -­‐ Querying Linked Data 21 • Namespaces are added with the ‘PREFIX’ direc6ve • Statement paerns that make up the graph are specified between brackets (“{}”) PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX dbpedia-­‐ont: <http://dbpedia.org/ontology/> PREFIX mo: http://purl.org/ontology/mo/ ASK WHERE { dbpedia:The_Beatles mo:member dbpedia:Paul_McCartney.} Query: of ‘The Beatles’? true Query: Is Elvis Presley member of ‘The Beatles’? false PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX dbpedia-­‐ont: <http://dbpedia.org/ontology/> PREFIX mo: http://purl.org/ontology/mo/ ASK WHERE { dbpedia:The_Beatles mo:member dbpedia:Elvis_Presley.}
  22. 22. Query Form: SELECT What albums and tracks did ‘The Beatles’ make? EUCLID -­‐ Querying Linked Data 22 • The solu6on modifier projec+on nominates which components of the matches should be returned • “*” means all components should be returned Query: PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX mo: <http://purl.org/ontology/mo/> SELECT ?album_name ?track_title WHERE { dbpedia:The_Beatles foaf:made ?album . ?album dc:title ?album_name ; mo:track ?track . ?track dc:title ?track_title .}
  23. 23. Query Form: SELECT (2) Filter expressions • Different types of filters and func6ons may be used Filter: Comparison and logical operators PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX mo: <http://purl.org/ontology/mo/> SELECT ?album_name ?track_title ?date ?duration WHERE { dbpedia:The_Beatles foaf:made ?album . ?album dc:title ?album_name ; mo:track ?track . ?track dc:title ?track_title ; mo:duration ?duration; FILTER (?duration>300000 && ?duration<400000) } EUCLID -­‐ Querying Linked Data 23 Query: Retrieve the albums and tracks recorded by ‘The Beatles’, where the duraCon of the song is more than 300 secs. and no longer than 400 secs.
  24. 24. Query Form: SELECT (3) Elimina+on of duplicates Retrieve the name of the albums recorded by ‘The Beatles’ which have at least Query: two different songs. PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX mo: <http://purl.org/ontology/mo/> SELECT Results: EUCLID -­‐ Querying Linked Data 24 MODIFIER ?album_name WHERE { dbpedia:The_Beatles foaf:made ?album . ?album dc:title ?album_name . mo:track ?track1 . mo:track ?track2 . FILTER (?track1 != ?track2) } ?album “Revolver” “Sessions” “Abbey Road” ?album “Revolver” “Revolver” “Revolver” “Sessions” “Abbey Road” “Abbey Road” DISTINCT REDUCED MODIFIER= MODIFIER=
  25. 25. Query Form: SELECT (4) Aggregates • Calculate aggregate values: COUNT, SUM, MIN, MAX, AVG, GROUP_CONCAT and SAMPLE • Built around the GROUP BY operator • Prune at group level (cf. FILTER) using HAVING Retrieve the duraCon of the albums recorded PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX mo: <http://purl.org/ontology/mo/> SELECT ?album (SUM(?track_duration) AS ?album_duration) WHERE { dbpedia:The_Beatles foaf:made ?album . ?album mo:track ?track . ?track mo:duration ?track_duration . } GROUP BY ?album HAVING (SUM(?track_duration) > 3600000) EUCLID -­‐ Querying Linked Data 25 Query: by ‘The Beatles’.
  26. 26. Query Form: DESCRIBE Takes the resources within the solu6on, and provides informa6on about them as RDF statements. They can be iden6fied by: • Specifying PREFIX dbpedia: <http://dbpedia.org/resource/> DESCRIBE dbpedia:Paul_McCartney EUCLID -­‐ Querying Linked Data 26 explicit IRIs • Bindings of variables in the WHERE clause PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX mo: <http://purl.org/ontology/mo/> DESCRIBE ?member WHERE { dbpedia:The_Beatles mo:member ?member .}
  27. 27. Query Form: CONSTRUCT EUCLID -­‐ Querying Linked Data 27 • CONSTRUCT WHERE: In order to query for a subgraph, without change, it is no longer necessary to repeat the graph paern in the template Example: PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX mo: <http://purl.org/ontology/mo/> PREFIX dc: <http://purl.org/dc/elements/1.1/> CONSTRUCT WHERE { dbpedia:The_Beatles foaf:made ?album . ?album mo:track ?track .}
  28. 28. Query Form: CONSTRUCT (2a) dbpedia: foaf:made foaf:made dc:6tle EUCLID -­‐ Querying Linked Data 28 foaf:made The_Beatles <hp:// musicbrainz.org /record/...> <hp:// musicbrainz.org /record/...> Data: Query: Result: "Help!" "Let It Be" dc:6tle dc:6tle <hp:// musicbrainz.org /record/...> "Abbey Road" CONSTRUCT { ?album dc:creator dbpedia:The_Beatles .} WHERE { dbpedia:The_Beatles foaf:made ?album .} dbpedia: The_Beatles <hp:// musicbrainz …> <hp:// musicbrainz …> <hp:// musicbrainz …> dc:creator dc:creator dc:creator
  29. 29. Query Form: CONSTRUCT (2b) Create the dc:creator descripCons for albums and their tracks recorded by ‘The Beatles’. EUCLID -­‐ Querying Linked Data 29 • Returns RDF statements created from variable bindings • Template: graph paern with variables from the query paern Query: PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX mo: <http://purl.org/ontology/mo/> PREFIX dc: <http://purl.org/dc/elements/1.1/> CONSTRUCT { ?album dc:creator dbpedia:The_Beatles . ?track dc:creator dbpedia:The_Beatles .} WHERE { dbpedia:The_Beatles foaf:made ?album . ?album mo:track ?track .}
  30. 30. Query Form: CONSTRUCT (3) Create the dc:creator descripCons for the 10 most recent albums and their tracks recorded EUCLID -­‐ Querying Linked Data 30 Subsets of results • It is possible to combine the query with solu+on modifiers (ORDER BY, LIMIT, OFFSET) Query: PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX mo: <http://purl.org/ontology/mo/> PREFIX dc: <http://purl.org/dc/elements/1.1/> CONSTRUCT { ?album dc:creator dbpedia:The_Beatles . ?track dc:creator dbpedia:The_Beatles .} WHERE { dbpedia:The_Beatles foaf:made ?album . ?album mo:track ?track ; dc:date ?date . } ORDER BY DESC(?date) LIMIT 10 by ‘The Beatles’.
  31. 31. Query Form: CONSTRUCT (4) Union Graph PaNern • Allows the specifica6on of alterna6ves (disjunc6ons) Create the dc:creator descripCons for the albums recorded by ‘The Beatles’ in ‘Abbey Road Studios’ PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: http://xmlns.com/foaf/0.1/ PREFIX dc: <http://purl.org/dc/elements/1.1/> CONSTRUCT { ?album dc:creator dbpedia:The_Beatles . ?track dc:creator dbpedia:The_Beatles .} WHERE { dbpedia:The_Beatles foaf:made ?album . ?album dc:title ?album_name . {?album dbpedia-­‐ont:recordedIn dbpedia:Abbey_Road_Studios .} UNION {?album dbpedia-­‐ont:recordedIn dbpedia:Trident_Studios .}} EUCLID -­‐ Querying Linked Data 31 Query: or ‘Trident Studios’
  32. 32. Query Form: CONSTRUCT (5) Filter expressions • Different types of filters and func6ons may be used Filter: Regular expressions over strings PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> CONSTRUCT {?album dc:creator dbpedia:The_Beatles .} WHERE { dbpedia:The_Beatles foaf:made ?album . ?album dc:title ?album_name ; FILTER (REGEX(?album_name, ".*love.*", i)) } EUCLID -­‐ Querying Linked Data 32 Query: Create the dc:creator descripCons of the albums recorded by ‘The Beatles’ whose Ctle contains the word ‘love .
  33. 33. Query Form: CONSTRUCT (6) Type of func+on Func+on Result type Func6onal Forms bound IF COALESCE NOT EXISTS, EXISTS or, and RDFTerm-­‐equal (=), sameTerm IN, NOT IN xsd:boolean rdfTerm rdfTerm xsd:boolean xsd:boolean xsd:boolean boolean Func6ons on RDF Terms isIRI, isBlank, isLiteral, isNumeric str, lang, datatype IRI BNODE xsd:boolean simple literal iri iri blank node Func6ons on Numerics ABS, ROUND, CEIL, FLOOR RAND numeric xsd:double Filter expressions Source:hp://www.w3.org/TR/sparql11-­‐query/#SparqlOps EUCLID -­‐ Querying Linked Data 33
  34. 34. Query Form: CONSTRUCT (7) Type of func+on Func+on Result type Func6ons on Strings STRLEN SUBSTR, UCASE, LCASE STRSTARTS, STRENDS, CONTAINS STRBEFORE, STRAFTER ENCODE_FOR_URI CONCAT langMatches REGEX REPLACE xsd:integer string literal xsd:boolean literal simple literal string literal xsd:boolean xsd:boolean string literal Func6ons on Dates and Times now year, month, day, hours, minutes seconds 6mezone tz xsd:dateTime xsd:integer xsd:decimal xsd:dayTimeDura6on simple literal Filter expressions Source:hp://www.w3.org/TR/sparql11-­‐query/#SparqlOps EUCLID -­‐ Querying Linked Data 34
  35. 35. Query Form: CONSTRUCT (8) Op+onal Graph PaNern • OPTIONAL clause encloses the op6onal parts • If variables in the construct clause are not bound in the op6onal, the triple paerns with these variables are not generated Create the dc:creator and dc:depicts descripQuery: PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX dbpedia-­‐owl: <http://dbpedia.org/ontology/> CONSTRUCT { ?album dc:creator ?artist . ?picture dc:depicts ?artist . } EUCLID -­‐ Querying Linked Data 35 WHERE { ?artist foaf:made ?album . OPTIONAL {?artist foaf:depiction ?picture .}} Cons of arCsts.
  36. 36. Query Form: CONSTRUCT (9) Op+onal Graph PaNern • Can test if variables are bound in filter expressions • Solu6ons that meet the OPTIONAL clause can be filtered out by using the logical filter NOT (!) PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX dbpedia-­‐owl: <http://dbpedia.org/ontology/> CONSTRUCT { ?album dc:creator ?artist . } WHERE { ?artist foaf:made ?album . OPTIONAL {?artist dbpedia-­‐owl:deathPlace ?place_of_death .} FILTER (!BOUND(?place_of_death)) EUCLID -­‐ Querying Linked Data 36 } Create the dc:creator descripCons of those arCsts who are not dead. Query: NOT EXISTS {?artist dbpedia-­‐owl:deathPlace ?place_of_death .}
  37. 37. Query Form: CONSTRUCT (10) Assigning Variables • The value of an expression can be added to a solu6on mapping by binding a new variable (which can be further used and returned) • The BIND form allows to assign a value to a variable from a BGP Calculate the duraCon of the tracks from ms to s, and store the value using the dbpedia-­‐ont:runCme property . PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX mo: <http://purl.org/ontology/mo/> PREFIX dbpedia-­‐ont: <http://dbpedia.org/ontology/> CONSTRUCT { ?track dbpedia-­‐ont:runtime ?secs .} WHERE { dbpedia:The_Beatles foaf:made ?album . ?album mo:track ?track . ?track mo:duration ?duration . BIND((?duration/1000) AS ?secs) .} EUCLID -­‐ Querying Linked Data 37 Query:
  38. 38. Query Form: CONSTRUCT (11) Sub-­‐queries and Aggregate Values • To combine the CONSTRUCT query form with aggregate values, a sub-­‐query should be created inside the WHERE clause Materialize the duraCon of the albums recorded PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX mo: <http://purl.org/ontology/mo/> CONSTRUCT {?album music-­‐ont:duration ?album_duration .} WHERE { SELECT ?album (SUM(?track_duration) AS ?album_duration) { dbpedia:The_Beatles foaf:made ?album . ?album mo:track ?track . ?track mo:duration ?track_duration . } GROUP BY ?album HAVING (SUM(?track_duration) > 3600000)} EUCLID -­‐ Querying Linked Data 38 Query: by ‘The Beatles’.
  39. 39. UPDATING LINKED DATA WITH SPARQL 1.1 EUCLID -­‐ Querying Linked Data 39
  40. 40. Data Management SPARQL 1.1 provides data update opera6ons: • INSERT EUCLID -­‐ Querying Linked Data 40 data: adds some triples, given inline in the request, into a graph • DELETE data: removes some triples, given inline in the request, if the respec6ve graphs contains those • DELETE/INSERT data: uses in parallel INSERT and DELETE CH 1 CH 1
  41. 41. Data Management (2) Insert the following albums recorded by The Beatles into the graph http://musicbrainz.org/20130209-­‐004702 EUCLID -­‐ Querying Linked Data 41 INSERT data PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> INSERT DATA { GRAPH { <http://musicbrainz.org/20130302> <http://musicbrainz.org/artist/b10bbbfc-­‐cf9e-­‐42e0-­‐be17-­‐e2c3e1d2600d> foaf:made <http://musicbrainz.org/release/3a685770-­‐7326-­‐34fc-­‐9f18-­‐e5f5626f3dc5> , < http://musicbrainz.org/release/cb6f8798-­‐d51e-­‐4fa5-­‐a4d1-­‐2c0602bfe1b6 > . <http://musicbrainz.org/release/3a685770-­‐7326-­‐34fc-­‐9f18-­‐e5f5626f3dc5> dc:title "Please Please Me". < http://musicbrainz.org/release/cb6f8798-­‐d51e-­‐4fa5-­‐a4d1-­‐2c0602bfe1b6 > dc:title "Something New". } } CH 1
  42. 42. Data Management (3) DELETE data Delete all the information about the album Casualities of The Beatles. PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> DELETE { ?album ?predicate ?object . } WHERE { <http://musicbrainz.org/artist/b10bbbfc-­‐cf9e-­‐42e0-­‐be17-­‐e2c3e1d2600d> foaf:made ?album . ?album dc:title "Casualities". ?album ?predicate ?object .} CH 1 EUCLID -­‐ Querying Linked Data 42
  43. 43. Data Management (4) DELETE/INSERT data Delete the status of ‘Peter Best’ as current member of´The Beatles´, and insert his status as former member of the band. PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX db-­‐ont: <http://dbpedia.org/ontology/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> DELETE { dbpedia:The_Beatles db-­‐ont:currentMember ?x . } INSERT { GRAPH <http://musicbrainz.org/20130209-­‐004702> { dbpedia:The_Beatles db-­‐ont:formerBandMember ?x .} } EUCLID -­‐ Querying Linked Data 43 WHERE { dbpedia:The_Beatles db-­‐ont:currentMember ?x . ?x foaf:name "Peter Best" .}
  44. 44. Graph Management SPARQL 1.1 provides graph update opera6ons: • CREATE: creates an empty graph in the Graph Store EUCLID -­‐ Querying Linked Data 44 • LOAD: reads the content of a document into a graph in the Graph Store • CLEAR: removes all triples in one or more graphs • DROP: removes the graph from the Graph Store • Other opera+ons: COPY, MOVE, ADD
  45. 45. Graph Management (2) CREATE GRAPH <http://musicbrainz.org/20130302> LOAD <http://xmlns.com/foaf/spec/20100809.rdf> LOAD <http://xmlns.com/foaf/spec/20100809.rdf> INTO <http://xmlns.com/foaf/0.1/> EUCLID -­‐ Querying Linked Data 45 CREATE • Creates a new named graph • Can be used with the DEFAULT and ALL keywords LOAD • An RDF graph can be loaded from a URL • LOAD can be used with the SILENT keyword Named graph
  46. 46. Graph Management (3) CLEAR GRAPH <http://musicbrainz.org/20130302> EUCLID -­‐ Querying Linked Data 46 CLEAR • Removes all triples in the graph (it is emp6ed but not deleted!) • The graph(s) can be specified with the following keywords: DEFAULT, NAMED, ALL, GRAPH • Can be used with the SILENT keyword DROP • The given graph is removed from the Graph Store, including its content • Can be used with the DEFAULT and ALL keywords DROP GRAPH <http://musicbrainz.org/20130302>
  47. 47. Graph Management (4) SPARQL 1.1 provides other graph management opera6ons: • COPY COPY GRAPH <http://musicbrainz.org/20130302> TO GRAPH <http://musicbrainz.org/20130303> MOVE GRAPH <http://musicbrainz.org/temp> TO GRAPH <http://musicbrainz.org/20130303> EUCLID -­‐ Querying Linked Data 47 … TO … • MOVE … TO … • ADD … TO … ADD GRAPH <http://musicbrainz.org/20130302> TO GRAPH <http://musicbrainz.org/20130303>
  48. 48. SPARQL PROTOCOL FOR RDF EUCLID -­‐ Querying Linked Data 48
  49. 49. SPARQL 1.1. Protocol EUCLID -­‐ Querying Linked Data 49 • Consists of two opera+ons: query and update • An opera6on defines: • The HTTP method (GET or POST) • The HTTP query string parameters • The message content included in the HTTP request body • The message content included in the HTTP response body SPARQL Client SPARQL Endpoint Request alt [no errors]! [else]! Success Response Failure Response
  50. 50. Query Operation XML, JSON, CSV/TSV from a SELECT EUCLID -­‐ Querying Linked Data 50 • Sends a SPARQL query to a service and receives the results of the query • The response is: • May be invoked using HTTP GET or HTTP POST. The method POST with URL encoding is mostly used when the query string is too long query RDF/XML, Turtle from a CONSTRUCT query
  51. 51. Query Operation (2) EUCLID -­‐ Querying Linked Data 51 Example: SPARQL Query: PREFIX dbpedia: <http://dbpedia.org/resource/> PREFIX dbpedia-­‐ont: <http://dbpedia.org/ontology/> SELECT ?album WHERE { ?album dbpedia-­‐ont:artist dbpedia:The_Beatles .} LIMIT 3 HTTP GET request: Try this query! (Click on the hurl icon)
  52. 52. Update Operation EUCLID -­‐ Querying Linked Data 52 • Sends a SPARQL update request to a service • Should be invoked using the HTTP PATCH/POST method • The response consists of a HTTP response status code, which indicates success or failure of the opera6on
  53. 53. REASONING OVER LINKED DATA EUCLID -­‐ Querying Linked Data 53
  54. 54. Reasoning for Linked Data Integration EUCLID -­‐ Querying Linked Data 54 • Example: Integra6on of the MusicBrainz data set and the DBpedia data set Integra+on Data set Data set
  55. 55. Reasoning for Linked Data Integration mo:b10bbbfc-­‐cf9e-­‐42e0-­‐be17-­‐e2c3e1d2600d dbpedia:The_Beatles dbpedia-­‐ont:origin dbpedia:Liverpool; dbpedia-­‐ont:genre dbpedia:Rock_music; foaf:depiction . foaf:name The Beatles; mo:member mo:ba550d0e-­‐adac-­‐4864-­‐b88b-­‐407cab5e76af; mo:member mo:4d5447d7-­‐c61c-­‐4120-­‐ba1b-­‐d7f471d385b9; mo:member mo:42a8f507-­‐8412-­‐4611-­‐854f-­‐926571049fa0; mo:member mo:300c4c73-­‐33ac-­‐4255-­‐9d57-­‐4e32627f5e13. Integra+on EUCLID -­‐ Querying Linked Data 55 Data set Data set same
  56. 56. Reasoning for Linked Data Integration same mo:b10bbbfc-­‐cf9e-­‐42e0-­‐be17-­‐e2c3e1d2600d dbpedia:The_Beatles dbpedia-­‐ont:origin dbpedia:Liverpool; dbpedia-­‐ont:genre dbpedia:Rock_music; foaf:depiction . foaf:name The Beatles; mo:member mo:ba550d0e-­‐adac-­‐4864-­‐b88b-­‐407cab5e76af; mo:member mo:4d5447d7-­‐c61c-­‐4120-­‐ba1b-­‐d7f471d385b9; mo:member mo:42a8f507-­‐8412-­‐4611-­‐854f-­‐926571049fa0; mo:member mo:300c4c73-­‐33ac-­‐4255-­‐9d57-­‐4e32627f5e13. Result set: EUCLID -­‐ Querying Linked Data 56 Query: SELECT ?m ?g WHERE { dbpedia:The_Beatles dbpedia-­‐ont:genre ?g; mo:member ?m.} ?m ?g mo:ba550d0e-­‐adac-­‐4864-­‐ b88b-­‐407cab5e76af dbpedia:Rock_music mo:4d5447d7-­‐c61c-­‐4120-­‐ba1b-­‐ d7f471d385b9 dbpedia:Rock_music mo42a8f507-­‐8412-­‐4611-­‐854f-­‐92 6571049fa0; dbpedia:Rock_music mo300c4c73-­‐33ac-­‐4255-­‐9d57-­‐4e 32627f5e13 dbpedia:Rock_music
  57. 57. SPARQL 1.1: Entailment Regimes EUCLID -­‐ Querying Linked Data 57 • SPARQL 1.0 was defined only for simple entailment (paern matching ) • SPARQL 1.1 is extended with entailment regimes other than simple entailment: – RDF entailment – RDFS entailment – D-­‐Entailment – OWL RL entailment – OWL Full entailment – OWL 2 DL, EL, and QL entailment – RIF entailment Source: hp://www.w3.org/TR/rdf-­‐mt/#RDFSRules
  58. 58. RDFS Resource Descrip+on Framework Schema Seman6c Web Stack Berners-­‐Lee (2006) EUCLID -­‐ Querying Linked Data 58 Taxonomies and inferences
  59. 59. RDFS Entailment Regimes EUCLID -­‐ Querying Linked Data 59 • Contains 13 entailment rules denominated rdfsi for inference over RDFS defini6ons*: – rdfs:Literal (rdfs1, rdfs13) – rdfs:domain (rdfs2), rdfs:range (rdfs3) – rdfs:Resource (rdfs4a, rdfs4, rdfs8) – rdfs:subPropertyOf (rdfs5, rdfs6, rdfs7, rdfs12) – rdfs:Class (rdfs8, rdfs10) – rdfs:subClassOf (rdfs9, rdfs10, rdfs11) – rdfs:ContainerMembershipProperty (rdfs12) – rdfs:Datatype (rdfs13) * Source: hp://www.w3.org/TR/rdf-­‐mt/#RDFSRules
  60. 60. rdfs2 – rdfs:domain dbpedia: The_Beatles EUCLID -­‐ Querying Linked Data 60 dbpedia: Paul_McCartney SELECT ?x WHERE { ?x a mo:MusicGroup.} mo:member rdfs:domain mo:MusicGroup . ?x ?x dbpedia:The_Beatles … mo:member Schema: Query: Result set: Result set with inference: dbpedia: John_Lennon dbpedia: George_Harrison dbpedia: Ringo_Starr mo:member mo:member mo:member
  61. 61. rdfs3 – rdfs:range dbpedia: The_Beatles dbpedia-­‐ont: bandMember EUCLID -­‐ Querying Linked Data 61 dbpedia: Paul_McCartney SELECT ?x WHERE { ?x a foaf:Agent.} mo:member rdfs:range foaf:Agent . ?x ?x dbpedia:Paul_McCartney dbpedia:John_Lennon dbpedia:Ringo_Starr dbpedia:George_Harrison … dbpedia-­‐ont: bandMember Schema: Query: Result set: Result set with inference: dbpedia: John_Lennon dbpedia: George_Harrison dbpedia: Ringo_Starr dbpedia-­‐ont: bandMember dbpedia-­‐ont: bandMember
  62. 62. rdfs7 – rdfs:subPropertyOf dbpedia: Yesterday EUCLID -­‐ Querying Linked Data 62 dbpedia: Paul_McCartney SELECT ?x WHERE { dbpedia:Yesterday mo:performer ?x.} mo:singer rdfs:subPropertyOf mo:performer . ?x dbpedia:John_Lennon dbpedia:Ringo_Starr dbpedia:George_Harrison ?x dbpedia:John_Lennon dbpedia:Ringo_Starr dbpedia:George_Harrison dbpedia:Paul_McCartney mo:singer Schema: Query: Result set: Result set with inference: dbpedia: John_Lennon dbpedia: George_Harrison dbpedia: Ringo_Starr mo:performer mo:performer mo:performer mo:performer
  63. 63. rdfs9 – rdfs:subClassOf mo: MusicAr6st EUCLID -­‐ Querying Linked Data 63 dbpedia: The_Beatles SELECT ?x WHERE { ?x a mo:MusicArtist.} rdf:type mo:MusicGroup rdfs:subClassOf mo:MusicArtist . ?x ?x dbpedia:The_Beatles … Schema: Query: Result set: Result set with inference: rdf:type mo: MusicGroup
  64. 64. Inference from Schema mo:MusicGroup rdfs:subClassOf mo:MusicArtist . mo:MusicGroup a rdfs:Class . mo:MusicArtist a rdfs:Class . EUCLID -­‐ Querying Linked Data 64 • Knowledge encoded in the schema leads to infer new facts Schema: Inferred facts: • This is also captured in the set of axioma+c triples, which provide basic meaning for all the vocabulary terms rdfs:subClassOf rdfs:domain rdfs:Class . rdfs:subClassOf rdfs:range rdfs:Class .
  65. 65. RDFS: Lack of Consistency Check rdfs2 EUCLID -­‐ Querying Linked Data 65 • It is possible to infer facts that seem incorrect facts, but RDFS cannot prevent this: Schema: mo:member rdfs:domain mo:MusicGroup ; rdfs:range foaf:Agent . Exis6ng :PaulMcCartney a :SoloMusicArtist ; facts: :member :TheBeatles . Inferred :PaulMcCartney a :MusicGroup . facts: No contradic+on!: The mis-­‐modeling is not diagnosed
  66. 66. • We might wish further inferences, but these are beyond the entailment rules implemented by RDFS RDFS: Inference Limitations Cannot model with RDFS that if ‘x makes y’ implies that ‘the creator of y is x’ EUCLID -­‐ Querying Linked Data 66 foaf:knows rdfs:domain foaf:Person ; rdfs:range foaf:Person . foaf:made rdfs:domain foaf:Agent . :PaulMcCartney foaf:made :Yesterday ; foaf:knows :RingoStarr . :PaulMcCartney a foaf:Agent ; a foaf:Person . :RingoStarr a foaf:Person . Schema: Existing fact: Inferred facts: :Yesterday dc:creator :PaulMcCartney. :RingoStarr foaf:knows :PaulMcCartney . These inferences require OWL! NOT inferred: Cannot model with RDFS that ‘x knows y’ implies ‘y knows x’
  67. 67. OWL Web Ontology Language Seman6c Web Stack Berners-­‐Lee (2006) EUCLID -­‐ Querying Linked Data 67 Ontologies and inferences
  68. 68. Introduction to OWL More restric6ve than OWL DL EUCLID -­‐ Querying Linked Data 68 • Provides more ontological constructs and avoids some of the poten6al confusion in RDFS • OWL 2 is divided into sub-­‐languages denominated profiles: – OWL 2 EL: Limited to basic classifica6on, but with polynomial-­‐6me reasoning – OWL 2 QL: Designed to be translatable to rela6onal database querying – OWL 2 RL: Designed to be efficiently implementable in rule-­‐based systems • Most triple stores concentrate on the use of RDFS with a subset of OWL features, called OWL-­‐Horst or RDFS++
  69. 69. OWL Properties OWL dis6nguishes between two types of proper6es: • OWL ObjectProper+es: resources as values EUCLID -­‐ Querying Linked Data 69 • OWL DatatypeProper+es: literals as values :plays rdf:type owl:ObjectProperty; rdfs:domain :Musician; rdfs:range :Instrument . :hasMembers rdf:type owl:DatatypeProperty; rdfs:domain :MusicGroup rdfs:range xsd:int .
  70. 70. Property Axioms SELECT ?x {dbpedia:The_Beatles dbpedia-­‐ont:bandMember ?x.} Result set with inference: EUCLID -­‐ Querying Linked Data 70 • Property axioms include those from RDF Schema • OWL allows for property equivalence. Example: EquivalentObjectProperties(dbpedia-­‐ont:bandMember mo:member) ≡ dbpedia-­‐ont:bandMember owl:equivalentProperty mo:member. dbpedia: The_Beatles dbpedia: John_Lennon mo:member dbpedia: Paul_McCartney dbpedia: George_Harrison dbpedia: Ringo_Starr mo:member mo:member mo:member Query: ?x Result set: ?x dbpedia:Paul_McCartney dbpedia:John_Lennon dbpedia:Ringo_Starr dbpedia:George_Harrison
  71. 71. Property Axioms EUCLID -­‐ Querying Linked Data 71 • Property axioms include those from RDF Schema • OWL allows for property equivalence. Example: EquivalentObjectProperties(dbpedia-­‐ont:bandMember mo:member) dbpedia-­‐ont:bandMember owl:equivalentProperty mo:member. • OWL allows for property disjointness. Example: DisjointObjectProperty(dbpedia-­‐ont:length mo:duration) dbpedia-­‐ont:length owl:propertyDisjointWith mo:duration. • There is no standard for implemen6ng inconsistency reports under SPARQL ≡ ≡
  72. 72. Property Axioms (2) OWL allows the defini6on of property characteris6cs to infer new facts rela6ng to instances and their proper6es • Symmetry • Transi6vity • Inverse • Func6onal • Inverse Func6onal EUCLID -­‐ Querying Linked Data 72
  73. 73. Property Axioms: Symmetry Query: SELECT ?x WHERE { dbpedia:The_Beatles :associatedMusicalArtist ?x.} EUCLID -­‐ Querying Linked Data 73 dbpedia: Plas6c_Ono_ Band dbpedia: The_Beatles dbpedia: Billy_Preston :associatedMusicalArtist a owl:SymmetricProperty . ?genre dbpedia:Plastic_Ono_Band ?genre dbpedia:Plastic_Ono_Band dbpedia:Billy_Preston :associatedMusicalArtist Schema: Result set: Result set with inference: :associatedMusicalArtist
  74. 74. Property Axioms: Transitivity :subgenre a owl:TransitiveProperty . EUCLID -­‐ Querying Linked Data 74 :Rock :Heavy_ metal :Black_ metal :Punk_ rock SELECT ?genre WHERE { :Rock :subgenre ?genre .} ?genre :Heavy_metal :Punk_rock ?genre :Heavy_metal :Punk_rock :Black_metal :subgenre :subgenre :subgenre :subgenre Schema: Query: Result set: Result set with inference:
  75. 75. Property Axioms: Inverse Schema: mo:member_of owl:inverseOf mo:member. Query: SELECT ?x WHERE { ?x mo:member_of dbpedia:The_Beatles .} EUCLID -­‐ Querying Linked Data 75 ?x dbpedia: John_Lennon mo:member_of dbpedia:John_Lennon dbpedia:George_Harrison ?x dbpedia:John_Lennon dbpedia:George_Harrison dbpedia:Paul_McCartney dbpedia:Ringo_Starr Result set: Result set with inference: dbpedia: The_Beatles dbpedia: Paul_McCartney dbpedia: George_Harrison dbpedia: Ringo_Starr mo:member mo:member_of mo:member mo:member_of mo:member_of
  76. 76. Property Axioms: Functional It refers to a property that can have only one (unique) value for each instance Example: Every ar6st primarily plays only one musical instrument r1 r2 mo:primary_ instrument same mo:primary_ instrument mo:primary_instrument rdf:type owl:FunctionalProperty . dbpedia:Jimi_Hendrix mo:primary_instrument dbpedia:Electric_Guitar. dbpedia:Jimi_Hendrix mo:primary_instrument dbpedia:E-­‐Guitar. Conclusion dbpedia:Electric_Guitar owl:sameAs dbpedia:E-­‐Guitar . EUCLID -­‐ Querying Linked Data 76
  77. 77. Property Axioms: Inverse Functional It is useful for specifying unique proper6es iden6fying Example: Every recording has a unique ISRC (Interna6onal Standard Recording Code) mo:isrc rdf:type owl:InverseFunctionalProperty . mo:21047249-­‐7b3f-­‐4651-­‐acca-­‐246669c081fd mo:isrc "GBAYE6300412" . dbpedia:She_Loves_You mo:isrc "GBAYE6300412" . Conclusion mo:21047249-­‐7b3f-­‐4651-­‐acca-­‐246669c081fd owl:sameAs :dbpedia:She_Loves_You . EUCLID -­‐ Querying Linked Data 77 an individual r2 mo:isrc mo:isrc same r1
  78. 78. Individual Axioms OWL Individuals represent instances of classes. They are related to their class by the rdf:type property EUCLID -­‐ Querying Linked Data 78 • We can state that two individuals are the same SameIndividual(<artist/ba550d0e-­‐adac-­‐4864-­‐b88b-­‐407cab5e76af#_> dbpedia:PaulMcCartney)s ≡ <artist/ba550d0e-­‐adac-­‐4864-­‐b88b-­‐407cab5e76af#_> owl:sameAs dbpedia:PaulMcCartney . • We can state that two individuals are different DifferentIndividuals(:TheBeatles_band :TheBeatles_TVseries) ≡ :TheBeatles_band owl:differentFrom :TheBeatles_Tvseries .
  79. 79. Class Axioms Axioms declare general statements about concepts which are used in logical inference (reasoning). Class axioms: • Sub-­‐class rela6onship (from RDF Schema) EUCLID -­‐ Querying Linked Data 79 • Equivalent rela6onship: classes have the same individuals EquivalentClass(:Musician :MusicArtist) ≡ :Musician owl:equivalentClass :MusicArtist . • Disjointness: classes have no shared individuals DisjointClasses(:SoloMusicArtist :MusicGroup) ≡ :SoloMusicArtist owl:disjointWith :MusicGroup .
  80. 80. Class Construction Ar6st EUCLID -­‐ Querying Linked Data 80 • OWL classes are defined by the OWL term owl:Class • OWL classes can be subclassed as in RDFS: • OWL classes may be combined with class constructs to build new classes Music Ar6st :MusicArtist rdfs:subClassOf :Artist .
  81. 81. Class Construction (2) These class constructs are available in OWL, not in RDFS The class of female music ar6sts ObjectIntersectionOf(:Female :MusicArtist)s [a owl:Class; owl:intersectionOf(:Female :MusicArtist)] The class of music ar6sts ObjectUnionOf(:SoloMusicArtist :MusicGroup) [a owl:Class; owl:unionOf(:SoloMusicArtist :MusicGroup)] Everything that’s not instrumental music ObjectComplementOf(:InstrumentalMusic) [a owl:Class; owl:complementOf(:InstrumentalMusic)] Female Music Ar6st Solo Group Instrumental EUCLID -­‐ Querying Linked Data 81 ≡ ≡ ≡ NOTE: Anonymous classes!
  82. 82. Naming Class Constructions EUCLID -­‐ Querying Linked Data 82 • Direct naming can be achieved via owl:equivalentClass • This construc6on provides necessary and sufficient condi6ons for class membership • Class naming can be also achieved using rdfs:subClassOf, it provides a necessary but insufficient condi6on for class membership Music Ar6st Solo Group EquivalentClass(:MusicArtist ObjectUnionOf(:SoloMusicArtist :MusicGroup)) :MusicArtist owl:equivalentClass [owl:unionOf (:SoloMusicArtist :MusicGroup)] ≡
  83. 83. Summary In this chapter we studied: EUCLID -­‐ Querying Linked Data 83 • Basic concepts: triple paerns, graph paerns, SPARQL endpoint ... • SPARQL Query: • Query forms: ASK, SELECT, DESCRIBE, CONSTRUCT • Query paNerns: BGP, UNION, OPTIONAL, FILTER • Sequence modifiers: DISTINCT, REDUCED, ORDER BY, LIMIT, OFFSET • SPARQL 1.1 Update: • Data management: INSERT, DELETE; DELETE/INSERT • Graph management: LOAD, CLEAR, CREATE, DROP, COPY/MOVE/ADD • SPARQL Protocol: query opera6on, update opera6on Querying Linked Data
  84. 84. Summary (2) In this chapter we studied: EUCLID -­‐ Querying Linked Data 84 • Reasoning over Linked Data: • SPARQL 1.1 entailment regimes • RDFS: entailment regimes, lacks of consistency check, inference limita6ons • OWL: proper6es, property axioms (symmetry, transi6vity, inverse, func6onal, inverse func6onal), individual axioms, class axioms, class construc6ons, naming classes … Reasoning over Linked Data
  85. 85. For exercises, quiz and further material visit our website: http://www.euclid-­‐project.eu EUCLID -­‐ Providing Linked Data 85 eBook @euclid_project euclidproject euclidproject Other channels: Course
  86. 86. Acknowledgements • Alexander Mikroyannidis • Alice Carpen6er • Andreas Harth • Andreas Wagner • Andriy Nikolov • Barry Norton • Daniel M. Herzig • Elena Simperl • Günter Ladwig • Inga Shamkhalov • Jacek Kopecky • John Domingue • Juan Sequeda • Kalina Bontcheva • Maria Maleshkova • Maria-­‐Esther Vidal • Maribel Acosta • Michael Meier • Ning Li • Paul Mulholland • Peter Haase • Richard Power • Steffen Stadtmüller 86 People who have contributed to crea6ng Euclid training content:

×