Advertisement

Querying Linked Data

European Project at University of Southampton
Feb. 28, 2013
Advertisement

More Related Content

Slideshows for you(20)

Viewers also liked(20)

Advertisement
Advertisement

Querying Linked Data

  1. Querying Linked Data Presented by: Barry Norton
  2. Motivation: Music! 2 Visualization Module Metadata Streaming providers Physical Wrapper Downloads Dataacquisition D2R Transf.LD Wrapper Musical Content Application Analysis & Mining Module LDDatasetAccess LD Wrapper RDF/ XML Integrated Dataset Interlinking Cleansing Vocabulary Mapping SPARQL Endpoint Publishing RDFa Other content
  3. Agenda 1. Introduction to SPARQL 2. Querying Linked Data with SPARQL 3. SPARQL Algebra 4. Updating Linked Data with SPARQL 1.1 5. SPARQL Protocol 6. Reasoning over Linked Data 3EUCLID - Querying Linked Data
  4. INTRODUCTIONTO SPARQL EUCLID - Querying Linked Data 4
  5. SPARQL EUCLID - Querying Linked Data 5 Semantic Web Stack Berners-Lee (2006) * Protocol and RDF Query Language Declarative query language
  6. SPARQL EUCLID - Querying Linked Data 6 • SPARQL Query – Declarative query language for RDF data – http://www.w3.org/TR/rdf-sparql-query/ • SPARQL Algebra – Standard for communication between SPARQL services and clients – http://www.w3.org/2001/sw/DataAccess/rq23/rq24-algebra.html • SPARQL Update – Declarative manipulation language for RDF data – http://www.w3.org/TR/sparql11-update/ • SPARQL Protocol – Standard for communication between SPARQL services and clients – http://www.w3.org/TR/sparql11-protocol/
  7. SPARQL Query 1.1 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, A dd • Aggregates, Subqueries, Negation, E xpressions in the SELECT clause, Property paths, assignment, short form for CONSTRUCT, expanded set of functions and operators Federation extension • Service, values, service variables (informative) CH 5
  8. SPARQL Basics EUCLID - Querying Linked Data 8 • RDF triple: Basic building block, of the form subject, predicate, object. Example: • RDF triple pattern: Contains one or more variables. Examples: • RDF quad pattern: Contains graph name: URI or variable. Examples: dbpedia:The_Beatles foaf:name "The Beatles" . dbpedia:The_Beatles foaf:made ?album. ?album mo:track ?track . ?album ?p ?o . GRAPH <:g> {:s :p :o .} GRAPH ?g {dbpedia:The_Beatles foaf:name ?o.}
  9. SPARQL Basics EUCLID - Querying Linked Data 9 • RDF graph: Set of RDF assertions, 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 operations (queries or updates) • SPARQL protocol service: HTTP server that services requests for SPARQL Protocol operations • SPARQL endpoint: The URI at which a SPARQL Protocol service listens for requests from SPARQL clients
  10. QUERYING LINKED DATA WITH SPARQL EUCLID - Querying Linked Data 10
  11. SPARQL Query EUCLID - Querying Linked Data 11 Main idea: Pattern matching • Queries describe sub-graphs of the queried graph • Graph patterns are RDF graphs specified in Turtle syntax, which contain variables (prefixed by either “?” or “$”) • Sub-graphs that match the graph patterns yield a result ?albumdbpedia: The_Beatles foaf:made
  12. SPARQL Query EUCLID - Querying Linked Data 12 ?album dbpedia: The_Beatles foaf:made dbpedia: The_Beatlesfoaf:made <http:// musicbrainz.org /record/...> <http:// musicbrainz.org /record/...> foaf:made Data: Graph pattern: Results: "Help!" "Let It Be" dc:title dc:title <http:// musicbrainz.org /record/...> "Abbey Road" dc:title foaf:made ?album <http://musicbrainz.org...> <http://musicbrainz.org...> <http://musicbrainz.org...>
  13. SPARQL Query EUCLID - Querying Linked Data 13 ?album dbpedia: The_Beatles dbpedia: The_Beatlesfoaf:made <http:// musicbrainz.org /record/...> <http:// musicbrainz.org /record/...> foaf:made Data: Graph pattern: Results: "Help!" "Let It Be" dc:title dc:title <http:// musicbrainz.org /record/...> "Abbey Road" dc:title foaf:made ?album ?title <http://...> "Help!" <http://...> "Abbey Road" <http://...> "Let It Be" ?title dc:title
  14. SPARQL Query EUCLID - Querying Linked Data 14 ?album dbpedia: The_Beatles dbpedia: The_Beatlesfoaf:made <http:// musicbrainz.org /record/...> <http:// musicbrainz.org /track/...> foaf:made Data: Graph pattern: Results: "Help!" "Help!" dc:title dc:title mo:track a mo:Record mo:Track mo:Record ?album <http://musicbrainz.org...>
  15. SPARQL Query: Components EUCLID - Querying Linked Data 15 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 } ORDER BY ?title Prologue: • Prefix definitions • Subtly different from Turtle syntax - the final period is not used
  16. SPARQL Query: Components EUCLID - Querying Linked Data 16 Query form: • ASK, SELECT, DESCRIBE or CONSTRUCT • SELECT retrieves variables and their bindings as a table 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 } ORDER BY ?title
  17. SPARQL Query: Components EUCLID - Querying Linked Data 17 Data set specification: • This clause is optional • FROM or FROM NAMED • Indicates the sources for the data against which to find matches 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 } ORDER BY ?title
  18. SPARQL Query: Components EUCLID - Querying Linked Data 18 Query pattern: • Defines patterns to match against the data • Generalises Turtle with variables and keywords – N.B. final period optional 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 } ORDER BY ?title
  19. Solution modifier: • Modify the result set • ORDER BY, LIMIT or OFFSET re-organise rows; • GROUP BY combines them SPARQL Query: Components EUCLID - Querying Linked Data 19 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 } ORDER BY ?title
  20. Query Forms EUCLID - Querying Linked Data 20 SPARQL supports different query forms: • ASK tests whether or not a query pattern has a solution. Returns yes/no • SELECT returns variables and their bindings directly • CONSTRUCT returns a single RDF graph specified by a graph template • DESCRIBE returns a single RDF graph containing RDF data about resource
  21. Query Form: ASK EUCLID - Querying Linked Data 21 • Namespaces are added with the ‘PREFIX’ directive • Statement patterns 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.} Is Paul McCartney member of ‘The Beatles’?Query: true Results: Is Elvis Presley member of ‘The Beatles’?Query: false Results: 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. Query Form: SELECT EUCLID - Querying Linked Data 22 • The solution modifier projection nominates which components of the matches should be returned • “*” means all components should be returned 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 .} Query: What albums and tracks did ‘The Beatles’ make?
  23. Filter expressions • Different types of filters and functions may be used Query Form: SELECT (2) EUCLID - Querying Linked Data 23 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) } Query: Filter: Comparison and logical operators Retrieve the albums and tracks recorded by ‘The Beatles’, where the duration of the song is more than 300 secs. and no longer than 400 secs.
  24. Query Form: SELECT (3) EUCLID - Querying Linked Data 24 Elimination of duplicates 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 MODIFIER ?album_name WHERE { dbpedia:The_Beatles foaf:made ?album . ?album dc:title ?album_name . mo:track ?track1 . mo:track ?track2 . FILTER (?track1 != ?track2) } Retrieve the name of the albums recorded by ‘The Beatles’ which have at least two different songs. Query: ?album “Revolver” “Sessions” “Abbey Road” ?album “Revolver” “Revolver” “Revolver” “Sessions” “Abbey Road” “Abbey Road” DISTINCT Results: REDUCED MODIFIER= MODIFIER=
  25. 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 Query Form: SELECT (4) EUCLID - Querying Linked Data 25 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) Retrieve the duration of the albums recorded by ‘The Beatles’.Query:
  26. Query Form: DESCRIBE EUCLID - Querying Linked Data 26 Takes the resources within the solution, and provides information about them as RDF statements. They can be identified by: • Specifying 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 .} PREFIX dbpedia: <http://dbpedia.org/resource/> DESCRIBE dbpedia:Paul_McCartney
  27. 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 pattern in the template 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 .} Example: Query Form: CONSTRUCT
  28. Query Form: CONSTRUCT (2a) EUCLID - Querying Linked Data 28 dbpedia: The_Beatlesfoaf:made <http:// musicbrainz.org /record/...> <http:// musicbrainz.org /record/...> foaf:made Data: Query: Result: "Help!" "Let It Be" dc:title dc:title <http:// musicbrainz.org /record/...> "Abbey Road" dc:title foaf:made CONSTRUCT { ?album dc:creator dbpedia:The_Beatles .} WHERE { dbpedia:The_Beatles foaf:made ?album .} dbpedia: The_Beatles <http:// musicbrainz …> <http:// musicbrainz …> <http:// musicbrainz …> dc:creator dc:creator dc:creator
  29. EUCLID - Querying Linked Data 29 • Returns RDF statements created from variable bindings • Template: graph pattern with variables from the query pattern 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 .} Create the dc:creator descriptions for albums and their tracks recorded by ‘The Beatles’.Query: Query Form: CONSTRUCT (2b)
  30. Query Form: CONSTRUCT (3) EUCLID - Querying Linked Data 30 Subsets of results • It is possible to combine the query with solution modifiers (ORDER BY, LIMIT, OFFSET) 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 Create the dc:creator descriptions for the 10 most recent albums and their tracks recorded by ‘The Beatles’.Query:
  31. Union Graph Pattern • Allows the specification of alternatives (disjunctions) EUCLID - Querying Linked Data 31 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 .}} Create the dc:creator descriptions for the albums recorded by ‘The Beatles’ in ‘Abbey Road Studios’ or ‘Trident Studios’ Query: Query Form: CONSTRUCT (4)
  32. Filter expressions • Different types of filters and functions may be used EUCLID - Querying Linked Data 32 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)) } Query: Filter: Regular expressions over strings Create the dc:creator descriptions of the albums recorded by ‘The Beatles’ whose title contains the word ‘love . Query Form: CONSTRUCT (5)
  33. Type of function Function Result type Functional 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 Functions on RDF Terms isIRI, isBlank, isLiteral, isNumeric str, lang, datatype IRI BNODE xsd:boolean simple literal iri iri blank node Functions on Numerics ABS, ROUND, CEIL, FLOOR RAND numeric xsd:double Filter expressions EUCLID - Querying Linked Data 33 Source:http://www.w3.org/TR/sparql11-query/#SparqlOps Query Form: CONSTRUCT (6)
  34. Type of function Function Result type Functions 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 Functions on Dates and Times now year, month, day, hours, minutes seconds timezone tz xsd:dateTime xsd:integer xsd:decimal xsd:dayTimeDuration simple literal Filter expressions EUCLID - Querying Linked Data 34 Source:http://www.w3.org/TR/sparql11-query/#SparqlOps Query Form: CONSTRUCT (7)
  35. Optional Graph Pattern • OPTIONAL clause encloses the optional parts • If variables in the construct clause are not bound in the optional, the triple patterns with these variables are not generated EUCLID - Querying Linked Data 35 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 . } WHERE { ?artist foaf:made ?album . OPTIONAL {?artist foaf:depiction ?picture .}} Create the dc:creator and dc:depicts descriptions of artists.Query: Query Form: CONSTRUCT (8)
  36. Optional Graph Pattern • Can test if variables are bound in filter expressions • Solutions that meet the OPTIONAL clause can be filtered out by using the logical filter NOT (!) EUCLID - Querying Linked Data 36 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)) } Create the dc:creator descriptions of those artists who are not dead. Query: Query Form: CONSTRUCT (9) NOT EXISTS {?artist dbpedia-owl:deathPlace ?place_of_death .}
  37. Assigning Variables • The value of an expression can be added to a solution 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 EUCLID - Querying Linked Data 37 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) .} Calculate the duration of the tracks from ms to s, and store the value using the dbpedia-ont:runtime property . Query: Query Form: CONSTRUCT (10)
  38. Sub-queries and Aggregate Values • To combine the CONSTRUCT query form with aggregate values, a sub-query should be created inside the WHERE clause EUCLID - Querying Linked Data 38 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)} Materialize the duration of the albums recorded by ‘The Beatles’.Query: Query Form: CONSTRUCT (11)
  39. UPDATING LINKED DATA WITH SPARQL 1.1 EUCLID - Querying Linked Data 39
  40. Data Management EUCLID - Querying Linked Data 40 SPARQL 1.1 provides data update operations: • INSERT data: adds some triples, given inline in the request, into a graph • DELETE data: removes some triples, given inline in the request, if the respective graphs contains those • DELETE/INSERT data: uses in parallel INSERT and DELETE CH 1 CH 1
  41. Data Management (2) 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". } } Insert the following albums recorded byThe Beatles into the graph http://musicbrainz.org/20130209-004702 CH 1
  42. Data Management (3) EUCLID - Querying Linked Data 42 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
  43. Data Management (4) EUCLID - Querying Linked Data 43 DELETE/INSERT data 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 .} } WHERE { dbpedia:The_Beatles db-ont:currentMember ?x . ?x foaf:name "Peter Best" .} Delete the status of ‘Peter Best’ as current member of´The Beatles´, and insert his status as former member of the band.
  44. Graph Management EUCLID - Querying Linked Data 44 SPARQL 1.1 provides graph update operations: • CREATE: creates an empty graph in the Graph Store • 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 operations: COPY, MOVE, ADD
  45. Graph Management (2) 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 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/> Named graph
  46. Graph Management (3) EUCLID - Querying Linked Data 46 CLEAR • Removes all triples in the graph (it is emptied 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 CLEAR GRAPH <http://musicbrainz.org/20130302> DROP GRAPH <http://musicbrainz.org/20130302>
  47. Graph Management (4) EUCLID - Querying Linked Data 47 SPARQL 1.1 provides other graph management operations: • COPY …TO … • MOVE …TO … • ADD …TO … COPY GRAPH <http://musicbrainz.org/20130302> TO GRAPH <http://musicbrainz.org/20130303> MOVE GRAPH <http://musicbrainz.org/temp> TO GRAPH <http://musicbrainz.org/20130303> ADD GRAPH <http://musicbrainz.org/20130302> TO GRAPH <http://musicbrainz.org/20130303>
  48. SPARQL PROTOCOL FOR RDF EUCLID - Querying Linked Data 48
  49. SPARQL 1.1. Protocol EUCLID - Querying Linked Data 49 • Consists of two operations: query and update • An operation 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. 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 Operation XML, JSON, CSV/TSV from a SELECT query RDF/XML, Turtle from a CONSTRUCT query
  51. EUCLID - Querying Linked Data 51 Example: 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 SPARQL Query: Query Operation (2) HTTP GET request: Try this query! (Click on the hurl icon)
  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 operation
  53. REASONING OVER LINKED DATA EUCLID - Querying Linked Data 53
  54. Reasoning for Linked Data Integration EUCLID - Querying Linked Data 54 • Example: Integration of the MusicBrainz data set and the DBpedia data set Integration Data set Data set
  55. Reasoning for Linked Data Integration EUCLID - Querying Linked Data 55 mo:b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d 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. dbpedia:The_Beatles dbpedia-ont:origin dbpedia:Liverpool; dbpedia-ont:genre dbpedia:Rock_music; foaf:depiction . Integration Data set Data set same
  56. Reasoning for Linked Data Integration EUCLID - Querying Linked Data 56 mo:b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d 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. dbpedia:The_Beatles dbpedia-ont:origin dbpedia:Liverpool; dbpedia-ont:genre dbpedia:Rock_music; foaf:depiction . same SELECT ?m ?g WHERE { dbpedia:The_Beatles dbpedia-ont:genre ?g; mo:member ?m.} Query: ?m ?g mo:ba550d0e-adac-4864-b88b- 407cab5e76af dbpedia:Rock_music mo:4d5447d7-c61c-4120-ba1b- d7f471d385b9 dbpedia:Rock_music mo42a8f507-8412-4611-854f- 926571049fa0; dbpedia:Rock_music mo300c4c73-33ac-4255-9d57- 4e32627f5e13 dbpedia:Rock_music Result set:
  57. SPARQL 1.1: Entailment Regimes EUCLID - Querying Linked Data 57 • SPARQL 1.0 was defined only for simple entailment (pattern 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: http://www.w3.org/TR/rdf-mt/#RDFSRules
  58. RDFS EUCLID - Querying Linked Data 58 Resource Description Framework Schema Semantic Web Stack Berners-Lee (2006) Taxonomies and inferences
  59. RDFS Entailment Regimes EUCLID - Querying Linked Data 59 • Contains 13 entailment rules denominated rdfsi for inference over RDFS definitions*: – 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: http://www.w3.org/TR/rdf-mt/#RDFSRules
  60. rdfs2 – rdfs:domain EUCLID - Querying Linked Data 60 dbpedia: The_Beatles 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. rdfs3 – rdfs:range EUCLID - Querying Linked Data 61 dbpedia: The_Beatles 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 dbpedia-ont: bandMember
  62. rdfs7 – rdfs:subPropertyOf EUCLID - Querying Linked Data 62 dbpedia: Yesterday 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:performermo:performer mo:performer
  63. rdfs9 – rdfs:subClassOf EUCLID - Querying Linked Data 63 dbpedia: The_Beatles SELECT ?x WHERE { ?x a mo:MusicArtist.} mo:MusicGroup rdfs:subClassOf mo:MusicArtist . ?x ?x dbpedia:The_Beatles … Schema: Query: Result set: Result set with inference: mo: MusicArtist rdf:type mo: MusicGroup rdf:type
  64. Inference from Schema EUCLID - Querying Linked Data 64 • Knowledge encoded in the schema leads to infer new facts • This is also captured in the set of axiomatic triples, which provide basic meaning for all the vocabulary terms mo:MusicGroup rdfs:subClassOf mo:MusicArtist . mo:MusicGroup a rdfs:Class . mo:MusicArtist a rdfs:Class . Schema: Inferred facts: rdfs:subClassOf rdfs:domain rdfs:Class . rdfs:subClassOf rdfs:range rdfs:Class .
  65. RDFS: Lack of Consistency Check 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 . Existing :PaulMcCartney a :SoloMusicArtist ; facts: :member :TheBeatles . Inferred :PaulMcCartney a :MusicGroup . facts: No contradiction!: The mis-modeling is not diagnosed rdfs2
  66. • We might wish further inferences, but these are beyond the entailment rules implemented by RDFS RDFS: Inference Limitations 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’ Cannot model with RDFS that if ‘x makes y’ implies that ‘the creator of y is x’
  67. OWL EUCLID - Querying Linked Data 67 Web Ontology Language Semantic Web Stack Berners-Lee (2006) Ontologies and inferences
  68. Introduction to OWL EUCLID - Querying Linked Data 68 • Provides more ontological constructs and avoids some of the potential confusion in RDFS • OWL 2 is divided into sub-languages denominated profiles: – OWL 2 EL: Limited to basic classification, but with polynomial-time reasoning – OWL 2 QL: Designed to be translatable to relational 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++ More restrictive than OWL DL
  69. OWL Properties EUCLID - Querying Linked Data 69 OWL distinguishes between two types of properties: • OWL ObjectProperties: resources as values • OWL DatatypeProperties: 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. PropertyAxioms 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: Paul_McCartney mo:member dbpedia: John_Lennon dbpedia: George_Harrison dbpedia: Ringo_Starr mo:member mo:member mo:member SELECT ?x {dbpedia:The_Beatles dbpedia-ont:bandMember ?x.} Query: ?x Result set: ?x dbpedia:Paul_McCartney dbpedia:John_Lennon dbpedia:Ringo_Starr dbpedia:George_Harrison Result set with inference:
  71. PropertyAxioms 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 implementing inconsistency reports under SPARQL ≡ ≡
  72. PropertyAxioms (2) EUCLID - Querying Linked Data 72 OWL allows the definition of property characteristics to infer new facts relating to instances and their properties • Symmetry • Transitivity • Inverse • Functional • Inverse Functional
  73. Property Axioms: Symmetry EUCLID - Querying Linked Data 73 dbpedia: The_Beatles dbpedia: Billy_Preston dbpedia: Plastic_Ono_ Band :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: SELECT ?x WHERE { dbpedia:The_Beatles :associatedMusicalArtist ?x.} Query: :associatedMusicalArtist
  74. Property Axioms: Transitivity EUCLID - Querying Linked Data 74 :Rock :Heavy_ metal :Black_ metal :Punk_ rock SELECT ?genre WHERE { :Rock :subgenre ?genre .} :subgenre a owl:TransitiveProperty . ?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. Property Axioms: Inverse EUCLID - Querying Linked Data 75 SELECT ?x WHERE { ?x mo:member_of dbpedia:The_Beatles .} mo:member_of owl:inverseOf mo:member. ?x dbpedia:John_Lennon dbpedia:George_Harrison ?x dbpedia:John_Lennon dbpedia:George_Harrison dbpedia:Paul_McCartney dbpedia:Ringo_Starr Schema: Query: Result set: Result set with inference: dbpedia: The_Beatles dbpedia: Paul_McCartney mo:member_of dbpedia: John_Lennon dbpedia: George_Harrison dbpedia: Ringo_Starr mo:member mo:member_of mo:member mo:member_of mo:member_of
  76. Example: Every artist primarily plays only one musical 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 . Property Axioms: Functional EUCLID - Querying Linked Data 76 It refers to a property that can have only one (unique) value for each instance r2 same r1
  77. Example: Every recording has a unique ISRC (International 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 . Property Axioms: Inverse Functional EUCLID - Querying Linked Data 77 It is useful for specifying unique properties identifying an individual r2 same r1
  78. Individual Axioms EUCLID - Querying Linked Data 78 OWL Individuals represent instances of classes. They are related to their class by the rdf:type property • We can state that two individuals are the same SameIndividual(<artist/ba550d0e-adac-4864-b88b-407cab5e76af#_> dbpedia:PaulMcCartney) <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. Class Axioms EUCLID - Querying Linked Data 79 Axioms declare general statements about concepts which are used in logical inference (reasoning). Class axioms: • Sub-class relationship (from RDF Schema) • Equivalent relationship: 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. Class Construction 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 Artist Artist :MusicArtist rdfs:subClassOf :Artist .
  81. Class Construction (2) EUCLID - Querying Linked Data 81 These class constructs are available in OWL, not in RDFS The class of female music artists ObjectIntersectionOf(:Female :MusicArtist) [a owl:Class; owl:intersectionOf(:Female :MusicArtist)] The class of music artists 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 Artist Solo Group Instrumental ≡ ≡ ≡ NOTE: Anonymous classes!
  82. Naming Class Constructions EUCLID - Querying Linked Data 82 • Direct naming can be achieved via owl:equivalentClass • This construction provides necessary and sufficient conditions for class membership • Class naming can be also achieved using rdfs:subClassOf, it provides a necessary but insufficient condition for class membership Music Artist Solo Group EquivalentClass(:MusicArtist ObjectUnionOf(:SoloMusicArtist :MusicGroup)) :MusicArtist owl:equivalentClass [owl:unionOf (:SoloMusicArtist :MusicGroup)] ≡
  83. Summary EUCLID - Querying Linked Data 83 • Basic concepts: triple patterns, graph patterns, SPARQL endpoint ... • SPARQL Query: • Query forms: ASK, SELECT, DESCRIBE, CONSTRUCT • Query patterns: 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 operation, update operation QueryingLinkedData In this chapter we studied:
  84. Summary (2) EUCLID - Querying Linked Data 84 • Reasoning over Linked Data: • SPARQL 1.1 entailment regimes • RDFS: entailment regimes, lacks of consistency check, inference limitations • OWL: properties, property axioms (symmetry, transitivity, inverse, functional, inverse functional), individual axioms, class axioms, class constructions, naming classes … ReasoningoverLinkedData In this chapter we studied:
  85. For exercises, quiz and further material visit our website: EUCLID - Providing Linked Data 85 @euclid_project euclidproject euclidproject http://www.euclid-project.eu Other channels: eBook Course
  86. Acknowledgements • Alexander Mikroyannidis • Alice Carpentier • 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

Editor's Notes

  1. NOTE: the “CH 1” means that these topics were covered in EUCLID Chapter 1 already.
  2. NOTE: the “CH 1” means that these topics were covered in EUCLID Chapter 1 already.
  3. NOTE: the “CH 1” means that these topics were covered in EUCLID Chapter 1 already.
  4. NOTE: the “CH 1” means that these topics were covered in EUCLID Chapter 1 already.
  5. NOTE: the “CH 1” means that these topics were covered in EUCLID Chapter 1 already.
Advertisement