Querying Linked Data
Upcoming SlideShare
Loading in...5
×
 

Querying Linked Data

on

  • 4,488 views

This presentation looks in detail at SPARQL (SPARQL Protocol and RDF Query Language) and introduces approaches for querying and updating semantic data. It covers the SPARQL algebra, the SPARQL ...

This presentation looks in detail at SPARQL (SPARQL Protocol and RDF Query Language) and introduces approaches for querying and updating semantic data. It covers the SPARQL algebra, the SPARQL protocol, and provides examples for reasoning over Linked Data. We use examples from the music domain, which can be directly tried out and ran over the MusicBrainz dataset. This includes gaining some familiarity with the RDFS and OWL languages, which allow developers to formulate generic and conceptual knowledge that can be exploited by automatic reasoning services in order to enhance the power of querying.

Statistics

Views

Total Views
4,488
Views on SlideShare
2,055
Embed Views
2,433

Actions

Likes
3
Downloads
161
Comments
5

6 Embeds 2,433

http://www.euclid-project.eu 2006
http://euclid-project.eu 303
http://data.linkededucation.org 117
http://oci.open.ac.uk 4
https://www.linkedin.com 2
http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • The webinars to the slides are available at: Part I http://vimeo.com/61618438 Part II http://vimeo.com/61618437
    Are you sure you want to
    Your message goes here
    Processing…
  • From Slide 22 the newer MusicBrainz mapping has a finer-grained distinction between 'album' (SignalGroup), and 'record' (the container of tracks), which is an artifact of a 'release' (of the album at a point in time). The examples are all encoded fully at:
    http://euclid.sti2.org/Exercises/Exercise2

    (Login is exercise2/exercise2)
    Are you sure you want to
    Your message goes here
    Processing…
  • On Slide 23 the variable ?date in the projection does not belong
    Are you sure you want to
    Your message goes here
    Processing…
  • Angle brackets are missing around the Music Ontology's namespace on Slide 21 (and the DBpedia ontology namespace is unneeded).
    Are you sure you want to
    Your message goes here
    Processing…
  • On Slide 32 the regex is over-defined.

    Without a start of string anchor ('^'), or an end of string anchor ('$'), it's unnecessary to have match-alls ('.*'). The substring will match with just ('love').
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • NOTE: the “CH 1” means that these topics were covered in EUCLID Chapter 1 already.
  • NOTE: the “CH 1” means that these topics were covered in EUCLID Chapter 1 already.
  • NOTE: the “CH 1” means that these topics were covered in EUCLID Chapter 1 already.
  • NOTE: the “CH 1” means that these topics were covered in EUCLID Chapter 1 already.
  • NOTE: the “CH 1” means that these topics were covered in EUCLID Chapter 1 already.

Querying Linked Data Querying Linked Data Presentation Transcript

  • Querying Linked DataPresented by:Barry Norton
  • Motivation: Music!2VisualizationModuleMetadataStreaming providersPhysical WrapperDownloadsDataacquisitionD2R Transf.LD WrapperMusical ContentApplicationAnalysis &Mining ModuleLDDatasetAccessLD WrapperRDF/XMLIntegratedDatasetInterlinking CleansingVocabularyMappingSPARQLEndpointPublishingRDFaOther content
  • Agenda1. Introduction to SPARQL2. Querying Linked Data with SPARQL3. SPARQL Algebra4. Updating Linked Data with SPARQL 1.15. SPARQL Protocol6. Reasoning over Linked Data3EUCLID - Querying Linked Data
  • INTRODUCTIONTO SPARQLEUCLID - Querying Linked Data 4
  • SPARQLEUCLID - Querying Linked Data 5Semantic Web StackBerners-Lee (2006)* Protocol and RDF Query LanguageDeclarative query language
  • SPARQLEUCLID - 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/
  • SPARQL Query 1.1EUCLID - Querying Linked Data 7• SPARQL 1.0 only allows accessing the data (query)• SPARQL 1.1 introduces:Query extensionsUpdates• Data management:Insert, Delete, Delete/Insert• Graph management:Create, Load, Clear, Drop, Copy, Move, Add• Aggregates, Subqueries, Negation, Expressions in the SELECTclause, Propertypaths, assignment, short form forCONSTRUCT, expanded set offunctions and operatorsFederation extension • Service, values, service variables(informative) CH 5
  • SPARQL BasicsEUCLID - Querying Linked Data 8• RDF triple: Basic building block, of the formsubject, 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.}
  • SPARQL BasicsEUCLID - Querying Linked Data 9• RDF graph: Set of RDF assertions, manipulated asa 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 forSPARQL Protocol operations (queries or updates)• SPARQL protocol service: HTTP server that services requests forSPARQL Protocol operations• SPARQL endpoint: The URI at which a SPARQL Protocol servicelistens for requests from SPARQL clients
  • QUERYING LINKED DATA WITHSPARQLEUCLID - Querying Linked Data 10
  • SPARQL QueryEUCLID - Querying Linked Data 11Main idea: Pattern matching• Queries describe sub-graphs of the queried graph• Graph patterns are RDF graphs specified in Turtlesyntax, which contain variables (prefixed by either “?” or “$”)• Sub-graphs that match the graph patterns yield aresult?albumdbpedia:The_Beatlesfoaf:made
  • SPARQL QueryEUCLID - Querying Linked Data 12?albumdbpedia:The_Beatlesfoaf:madedbpedia:The_Beatlesfoaf:made<http://musicbrainz.org/record/...><http://musicbrainz.org/record/...>foaf:madeData:Graph pattern:Results:"Help!" "Let It Be"dc:title dc:title<http://musicbrainz.org/record/...>"Abbey Road"dc:titlefoaf:made?album<http://musicbrainz.org...><http://musicbrainz.org...><http://musicbrainz.org...>
  • SPARQL QueryEUCLID - Querying Linked Data 13?albumdbpedia:The_Beatlesdbpedia:The_Beatlesfoaf:made<http://musicbrainz.org/record/...><http://musicbrainz.org/record/...>foaf:madeData:Graph pattern:Results:"Help!" "Let It Be"dc:title dc:title<http://musicbrainz.org/record/...>"Abbey Road"dc:titlefoaf:made?album ?title<http://...> "Help!"<http://...> "Abbey Road"<http://...> "Let It Be"?titledc:title
  • SPARQL QueryEUCLID - Querying Linked Data 14?albumdbpedia:The_Beatlesdbpedia:The_Beatlesfoaf:made<http://musicbrainz.org/record/...><http://musicbrainz.org/track/...>foaf:madeData:Graph pattern:Results:"Help!" "Help!"dc:title dc:titlemo:trackamo:Record mo:Trackmo:Record?album<http://musicbrainz.org...>
  • SPARQL Query: ComponentsEUCLID - Querying Linked Data 15PREFIX 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 ?albumFROM <http://musicbrainz.org/20130302>WHERE {dbpedia:The_Beatles foaf:made ?album .?album a mo:Record ; dc:title ?title}ORDER BY ?titlePrologue:• Prefix definitions• Subtly different from Turtle syntax - the final period is not used
  • SPARQL Query: ComponentsEUCLID - Querying Linked Data 16Query form:• ASK, SELECT, DESCRIBE or CONSTRUCT• SELECT retrieves variables and their bindings as a tablePREFIX 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 ?albumFROM <http://musicbrainz.org/20130302>WHERE {dbpedia:The_Beatles foaf:made ?album .?album a mo:Record ; dc:title ?title}ORDER BY ?title
  • SPARQL Query: ComponentsEUCLID - Querying Linked Data 17Data set specification:• This clause is optional• FROM or FROM NAMED• Indicates the sources for the data against which to find matchesPREFIX 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 ?albumFROM <http://musicbrainz.org/20130302>WHERE {dbpedia:The_Beatles foaf:made ?album .?album a mo:Record ; dc:title ?title}ORDER BY ?title
  • SPARQL Query: ComponentsEUCLID - Querying Linked Data 18Query pattern:• Defines patterns to match against the data• Generalises Turtle with variables and keywords – N.B. final period optionalPREFIX 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 ?albumFROM <http://musicbrainz.org/20130302>WHERE {dbpedia:The_Beatles foaf:made ?album .?album a mo:Record ; dc:title ?title}ORDER BY ?title
  • Solution modifier:• Modify the result set• ORDER BY, LIMIT or OFFSET re-organise rows;• GROUP BY combines themSPARQL Query: ComponentsEUCLID - Querying Linked Data 19PREFIX 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 ?albumFROM <http://musicbrainz.org/20130302>WHERE {dbpedia:The_Beatles foaf:made ?album .?album a mo:Record ; dc:title ?title}ORDER BY ?title
  • Query FormsEUCLID - Querying Linked Data 20SPARQL supports different query forms:• ASK tests whether or not a query pattern has asolution. Returns yes/no• SELECT returns variables and their bindingsdirectly• CONSTRUCT returns a single RDF graph specifiedby a graph template• DESCRIBE returns a single RDF graph containingRDF data about resource
  • Query Form: ASKEUCLID - Querying Linked Data 21• Namespaces are added with the ‘PREFIX’ directive• Statement patterns that make up the graph arespecified 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:memberdbpedia:Paul_McCartney.}Is Paul McCartney member of ‘The Beatles’?Query:trueResults:Is Elvis Presley member of ‘The Beatles’?Query:falseResults: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:memberdbpedia:Elvis_Presley.}
  • Query Form: SELECTEUCLID - Querying Linked Data 22• The solution modifier projection nominates whichcomponents of the matches should be returned• “*” means all components should be returnedPREFIX 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_titleWHERE {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?
  • Filter expressions• Different types of filters and functions may be usedQuery Form: SELECT (2)EUCLID - Querying Linked Data 23PREFIX 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 ?durationWHERE {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 operatorsRetrieve the albums and tracks recorded by ‘The Beatles’, where theduration of the song is more than 300 secs. and no longer than 400 secs.
  • Query Form: SELECT (3)EUCLID - Querying Linked Data 24Elimination of duplicatesPREFIX 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_nameWHERE {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”DISTINCTResults:REDUCEDMODIFIER= MODIFIER=
  • 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 HAVINGQuery Form: SELECT (4)EUCLID - Querying Linked Data 25PREFIX 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 ?albumHAVING (SUM(?track_duration) > 3600000)Retrieve the duration of the albums recorded by ‘The Beatles’.Query:
  • Query Form: DESCRIBEEUCLID - Querying Linked Data 26Takes the resources within the solution, and providesinformation about them as RDF statements. They canbe identified by:• Specifying explicit IRIs• Bindings of variables in the WHERE clausePREFIX dbpedia: <http://dbpedia.org/resource/>PREFIX mo: <http://purl.org/ontology/mo/>DESCRIBE ?memberWHERE {dbpedia:The_Beatles mo:member ?member .}PREFIX dbpedia: <http://dbpedia.org/resource/>DESCRIBE dbpedia:Paul_McCartney
  • EUCLID - Querying Linked Data 27• CONSTRUCT WHERE: In order to query for asubgraph, without change, it is no longer necessaryto repeat the graph pattern in the templatePREFIX 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
  • Query Form: CONSTRUCT (2a)EUCLID - Querying Linked Data 28dbpedia:The_Beatlesfoaf:made<http://musicbrainz.org/record/...><http://musicbrainz.org/record/...>foaf:madeData:Query: Result:"Help!" "Let It Be"dc:title dc:title<http://musicbrainz.org/record/...>"Abbey Road"dc:titlefoaf:madeCONSTRUCT {?album dc:creator dbpedia:The_Beatles .}WHERE {dbpedia:The_Beatles foaf:made ?album .}dbpedia:The_Beatles<http://musicbrainz…><http://musicbrainz…><http://musicbrainz…>dc:creatordc:creatordc:creator
  • EUCLID - Querying Linked Data 29• Returns RDF statements created from variablebindings• Template: graph pattern with variables from thequery patternPREFIX 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 tracksrecorded by ‘The Beatles’.Query:Query Form: CONSTRUCT (2b)
  • Query Form: CONSTRUCT (3)EUCLID - Querying Linked Data 30Subsets 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 10Create the dc:creator descriptions for the 10 most recentalbums and their tracks recorded by ‘The Beatles’.Query:
  • Union Graph Pattern• Allows the specification of alternatives (disjunctions)EUCLID - Querying Linked Data 31PREFIX 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)
  • Filter expressions• Different types of filters and functions may be usedEUCLID - Querying Linked Data 32PREFIX 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 stringsCreate the dc:creator descriptions of the albums recorded by‘The Beatles’ whose title contains the word ‘love .Query Form: CONSTRUCT (5)
  • Type of function Function Result typeFunctional FormsboundIFCOALESCENOT EXISTS, EXISTSor, andRDFTerm-equal (=), sameTermIN, NOT INxsd:booleanrdfTermrdfTermxsd:booleanxsd:booleanxsd:booleanbooleanFunctions on RDF TermsisIRI, isBlank, isLiteral, isNumericstr, lang,datatypeIRIBNODExsd:booleansimple literaliriiriblank nodeFunctions on Numerics ABS, ROUND, CEIL, FLOORRANDnumericxsd:doubleFilter expressionsEUCLID - Querying Linked Data 33Source:http://www.w3.org/TR/sparql11-query/#SparqlOpsQuery Form: CONSTRUCT (6)
  • Type of function Function Result typeFunctions on Strings STRLENSUBSTR, UCASE, LCASESTRSTARTS, STRENDS, CONTAINSSTRBEFORE, STRAFTERENCODE_FOR_URICONCATlangMatchesREGEXREPLACExsd:integerstring literalxsd:booleanliteralsimple literalstring literalxsd:booleanxsd:booleanstring literalFunctions on Dates andTimesnowyear, month, day, hours, minutessecondstimezonetzxsd:dateTimexsd:integerxsd:decimalxsd:dayTimeDurationsimple literalFilter expressionsEUCLID - Querying Linked Data 34Source:http://www.w3.org/TR/sparql11-query/#SparqlOpsQuery Form: CONSTRUCT (7)
  • 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 generatedEUCLID - Querying Linked Data 35PREFIX 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)
  • Optional Graph Pattern• Can test if variables are bound in filter expressions• Solutions that meet the OPTIONAL clause can be filtered out byusing the logical filter NOT (!)EUCLID - Querying Linked Data 36PREFIX 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 notdead.Query:Query Form: CONSTRUCT (9)NOT EXISTS {?artist dbpedia-owl:deathPlace ?place_of_death .}
  • Assigning Variables• The value of an expression can be added to a solution mapping bybinding a new variable (which can be further used and returned)• The BIND form allows to assign a value to a variable from a BGPEUCLID - Querying Linked Data 37PREFIX 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 thevalue using the dbpedia-ont:runtime property .Query:Query Form: CONSTRUCT (10)
  • Sub-queries and Aggregate Values• To combine the CONSTRUCT query form with aggregate values, asub-query should be created inside the WHERE clauseEUCLID - Querying Linked Data 38PREFIX 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 ?albumHAVING (SUM(?track_duration) > 3600000)}Materialize the duration of the albums recorded by ‘The Beatles’.Query:Query Form: CONSTRUCT (11)
  • UPDATING LINKED DATA WITHSPARQL 1.1EUCLID - Querying Linked Data 39
  • Data ManagementEUCLID - Querying Linked Data 40SPARQL 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 therequest, if the respective graphs contains those• DELETE/INSERT data: uses in parallel INSERT andDELETECH 1CH 1
  • Data Management (2)EUCLID - Querying Linked Data 41INSERT dataPREFIX 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 graphhttp://musicbrainz.org/20130209-004702CH 1
  • Data Management (3)EUCLID - Querying Linked Data 42DELETE dataDelete 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
  • Data Management (4)EUCLID - Querying Linked Data 43DELETE/INSERT dataPREFIX 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.
  • Graph ManagementEUCLID - Querying Linked Data 44SPARQL 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 inthe Graph Store• CLEAR: removes all triples in one or more graphs• DROP: removes the graph from the Graph Store• Other operations: COPY, MOVE, ADD
  • Graph Management (2)EUCLID - Querying Linked Data 45CREATE• Creates a new named graph• Can be used with the DEFAULT and ALL keywordsLOAD• An RDF graph can be loaded from a URL• LOAD can be used with the SILENT keywordCREATE 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
  • Graph Management (3)EUCLID - Querying Linked Data 46CLEAR• 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 keywordDROP• The given graph is removed from the Graph Store, including itscontent• Can be used with the DEFAULT and ALL keywordsCLEAR GRAPH <http://musicbrainz.org/20130302>DROP GRAPH <http://musicbrainz.org/20130302>
  • Graph Management (4)EUCLID - Querying Linked Data 47SPARQL 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>
  • SPARQL PROTOCOL FOR RDFEUCLID - Querying Linked Data 48
  • SPARQL 1.1. ProtocolEUCLID - 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 bodySPARQL Client SPARQL EndpointRequestalt [no errors][else]Success ResponseFailure Response
  • EUCLID - Querying Linked Data 50• Sends a SPARQL query to a service and receives the results ofthe query• The response is:• May be invoked using HTTP GET or HTTP POST. The methodPOST with URL encoding is mostly used when the query stringis too longQuery OperationXML, JSON, CSV/TSV from a SELECT queryRDF/XML, Turtle from a CONSTRUCT query
  • EUCLID - Querying Linked Data 51Example:PREFIX dbpedia: <http://dbpedia.org/resource/>PREFIX dbpedia-ont: <http://dbpedia.org/ontology/>SELECT ?albumWHERE { ?album dbpedia-ont:artist dbpedia:The_Beatles .}LIMIT 3SPARQL Query:Query Operation (2)HTTP GET request:Try this query!(Click on the hurl icon)
  • Update OperationEUCLID - Querying Linked Data 52• Sends a SPARQL update request to a service• Should be invoked using the HTTP PATCH/POSTmethod• The response consists of a HTTP response statuscode, which indicates success or failure of theoperation
  • REASONING OVER LINKED DATAEUCLID - Querying Linked Data 53
  • Reasoning forLinked Data IntegrationEUCLID - Querying Linked Data 54• Example: Integration of the MusicBrainz data set andthe DBpedia data setIntegrationData set Data set
  • Reasoning forLinked Data IntegrationEUCLID - Querying Linked Data 55mo:b10bbbfc-cf9e-42e0-be17-e2c3e1d2600dfoaf:name The Beatles;mo:membermo:ba550d0e-adac-4864-b88b-407cab5e76af;mo:membermo:4d5447d7-c61c-4120-ba1b-d7f471d385b9;mo:membermo:42a8f507-8412-4611-854f-926571049fa0;mo:membermo:300c4c73-33ac-4255-9d57-4e32627f5e13.dbpedia:The_Beatlesdbpedia-ont:origin dbpedia:Liverpool;dbpedia-ont:genre dbpedia:Rock_music;foaf:depiction .IntegrationData set Data setsame
  • Reasoning forLinked Data IntegrationEUCLID - Querying Linked Data 56mo:b10bbbfc-cf9e-42e0-be17-e2c3e1d2600dfoaf:name The Beatles;mo:membermo:ba550d0e-adac-4864-b88b-407cab5e76af;mo:membermo:4d5447d7-c61c-4120-ba1b-d7f471d385b9;mo:membermo:42a8f507-8412-4611-854f-926571049fa0;mo:membermo:300c4c73-33ac-4255-9d57-4e32627f5e13.dbpedia:The_Beatlesdbpedia-ont:origin dbpedia:Liverpool;dbpedia-ont:genre dbpedia:Rock_music;foaf:depiction .sameSELECT ?m ?g WHERE {dbpedia:The_Beatlesdbpedia-ont:genre ?g;mo:member ?m.}Query: ?m ?gmo:ba550d0e-adac-4864-b88b-407cab5e76afdbpedia:Rock_musicmo:4d5447d7-c61c-4120-ba1b-d7f471d385b9dbpedia:Rock_musicmo42a8f507-8412-4611-854f-926571049fa0;dbpedia:Rock_musicmo300c4c73-33ac-4255-9d57-4e32627f5e13dbpedia:Rock_musicResult set:
  • SPARQL 1.1:Entailment RegimesEUCLID - Querying Linked Data 57• SPARQL 1.0 was defined only for simple entailment(pattern matching )• SPARQL 1.1 is extended with entailment regimes otherthan simple entailment:– RDF entailment– RDFS entailment– D-Entailment– OWL RL entailment– OWL Full entailment– OWL 2 DL, EL, and QL entailment– RIF entailmentSource: http://www.w3.org/TR/rdf-mt/#RDFSRules
  • RDFSEUCLID - Querying Linked Data 58Resource Description Framework SchemaSemantic Web StackBerners-Lee (2006)Taxonomies and inferences
  • RDFS Entailment RegimesEUCLID - Querying Linked Data 59• Contains 13 entailment rules denominated rdfsi forinference 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
  • rdfs2 – rdfs:domainEUCLID - Querying Linked Data 60dbpedia:The_Beatlesdbpedia:Paul_McCartneySELECT ?x WHERE {?x a mo:MusicGroup.}mo:member rdfs:domainmo:MusicGroup .?x ?xdbpedia:The_Beatles …mo:memberSchema: Query:Result set: Result set with inference:dbpedia:John_Lennondbpedia:George_Harrisondbpedia:Ringo_Starrmo:member mo:membermo:member
  • rdfs3 – rdfs:rangeEUCLID - Querying Linked Data 61dbpedia:The_Beatlesdbpedia:Paul_McCartneySELECT ?x WHERE {?x a foaf:Agent.}mo:member rdfs:rangefoaf:Agent .?x ?xdbpedia:Paul_McCartneydbpedia:John_Lennondbpedia:Ringo_Starrdbpedia:George_Harrison …dbpedia-ont:bandMemberSchema: Query:Result set: Result set with inference:dbpedia:John_Lennondbpedia:George_Harrisondbpedia:Ringo_Starrdbpedia-ont:bandMemberdbpedia-ont:bandMemberdbpedia-ont:bandMember
  • rdfs7 – rdfs:subPropertyOfEUCLID - Querying Linked Data 62dbpedia:Yesterdaydbpedia:Paul_McCartneySELECT ?x WHERE {dbpedia:Yesterday mo:performer ?x.}mo:singer rdfs:subPropertyOfmo:performer .?xdbpedia:John_Lennondbpedia:Ringo_Starrdbpedia:George_Harrison?xdbpedia:John_Lennondbpedia:Ringo_Starrdbpedia:George_Harrisondbpedia:Paul_McCartneymo:singerSchema: Query:Result set: Result set with inference:dbpedia:John_Lennondbpedia:George_Harrisondbpedia:Ringo_Starrmo:performer mo:performermo:performermo:performer
  • rdfs9 – rdfs:subClassOfEUCLID - Querying Linked Data 63dbpedia:The_BeatlesSELECT ?x WHERE {?x a mo:MusicArtist.}mo:MusicGroup rdfs:subClassOfmo:MusicArtist .?x ?xdbpedia:The_Beatles …Schema: Query:Result set: Result set with inference:mo:MusicArtistrdf:typemo:MusicGrouprdf:type
  • Inference from SchemaEUCLID - Querying Linked Data 64• Knowledge encoded in the schema leads to infer newfacts• This is also captured in the set of axiomatic triples,which provide basic meaning for all the vocabulary termsmo:MusicGroup rdfs:subClassOf mo:MusicArtist .mo:MusicGroup a rdfs:Class .mo:MusicArtist a rdfs:Class .Schema:Inferredfacts:rdfs:subClassOf rdfs:domain rdfs:Class .rdfs:subClassOf rdfs:range rdfs:Class .
  • RDFS:Lack of Consistency CheckEUCLID - 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 isnot diagnosedrdfs2
  • • We might wish further inferences, but these arebeyond the entailment rules implemented by RDFSRDFS:Inference LimitationsEUCLID - Querying Linked Data 66foaf: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:Existingfact:Inferredfacts::Yesterday dc:creator :PaulMcCartney.:RingoStarr foaf:knows :PaulMcCartney .These inferences require OWL!NOTinferred:Cannot model withRDFS that ‘x knows y’implies ‘y knows x’Cannot model withRDFS that if ‘x makesy’ implies that ‘thecreator of y is x’
  • OWLEUCLID - Querying Linked Data 67Web Ontology LanguageSemantic Web StackBerners-Lee (2006)Ontologies and inferences
  • Introduction to OWLEUCLID - Querying Linked Data 68• Provides more ontological constructs and avoids some ofthe potential confusion in RDFS• OWL 2 is divided into sub-languages denominatedprofiles:– OWL 2 EL: Limited to basicclassification, but with polynomial-timereasoning– OWL 2 QL: Designed to be translatableto relational database querying– OWL 2 RL: Designed to be efficientlyimplementable in rule-based systems• Most triple stores concentrate on the use of RDFS with asubset of OWL features, called OWL-Horst or RDFS++More restrictivethan OWL DL
  • OWL PropertiesEUCLID - Querying Linked Data 69OWL 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 :MusicGrouprdfs:range xsd:int .
  • PropertyAxiomsEUCLID - 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_Beatlesdbpedia:Paul_McCartneymo:memberdbpedia:John_Lennondbpedia:George_Harrisondbpedia:Ringo_Starrmo:membermo:membermo:memberSELECT ?x {dbpedia:The_Beatlesdbpedia-ont:bandMember ?x.}Query:?xResult set:?xdbpedia:Paul_McCartneydbpedia:John_Lennondbpedia:Ringo_Starrdbpedia:George_HarrisonResult set with inference:
  • PropertyAxiomsEUCLID - 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 inconsistencyreports under SPARQL≡≡
  • PropertyAxioms (2)EUCLID - Querying Linked Data 72OWL allows the definition of property characteristics to infer newfacts relating to instances and their properties• Symmetry• Transitivity• Inverse• Functional• Inverse Functional
  • Property Axioms:SymmetryEUCLID - Querying Linked Data 73dbpedia:The_Beatlesdbpedia:Billy_Prestondbpedia:Plastic_Ono_Band :associatedMusicalArtista owl:SymmetricProperty .?genredbpedia:Plastic_Ono_Band?genredbpedia:Plastic_Ono_Banddbpedia:Billy_Preston:associatedMusicalArtistSchema:Result set: Result set with inference:SELECT ?x WHERE {dbpedia:The_Beatles:associatedMusicalArtist ?x.}Query::associatedMusicalArtist
  • Property Axioms:TransitivityEUCLID - Querying Linked Data 74:Rock:Heavy_metal:Black_metal:Punk_rockSELECT ?genre WHERE {:Rock :subgenre ?genre .}:subgenre a owl:TransitiveProperty .?genre:Heavy_metal:Punk_rock?genre:Heavy_metal:Punk_rock:Black_metal:subgenre :subgenre:subgenre :subgenreSchema:Query:Result set: Result set with inference:
  • Property Axioms:InverseEUCLID - Querying Linked Data 75SELECT ?x WHERE {?x mo:member_ofdbpedia:The_Beatles .}mo:member_of owl:inverseOf mo:member.?xdbpedia:John_Lennondbpedia:George_Harrison?xdbpedia:John_Lennondbpedia:George_Harrisondbpedia:Paul_McCartneydbpedia:Ringo_StarrSchema:Query:Result set: Result set with inference:dbpedia:The_Beatlesdbpedia:Paul_McCartneymo:member_ofdbpedia:John_Lennondbpedia:George_Harrisondbpedia:Ringo_Starrmo:membermo:member_ofmo:membermo:member_of mo:member_of
  • Example: Every artist primarily playsonly one musical instrumentmo: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_Guitarowl:sameAs dbpedia:E-Guitar .Property Axioms:FunctionalEUCLID - Querying Linked Data 76It refers to a property that can have only one (unique)value for each instancer2samer1
  • 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-246669c081fdowl:sameAs :dbpedia:She_Loves_You .Property Axioms:Inverse FunctionalEUCLID - Querying Linked Data 77It is useful for specifying unique properties identifyingan individualr2samer1
  • Individual AxiomsEUCLID - Querying Linked Data 78OWL Individuals represent instances of classes. They are related totheir class by the rdf:type property• We can state that two individuals are the sameSameIndividual(<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 differentDifferentIndividuals(:TheBeatles_band :TheBeatles_TVseries):TheBeatles_band owl:differentFrom :TheBeatles_Tvseries .≡≡
  • Class AxiomsEUCLID - Querying Linked Data 79Axioms declare general statements about concepts which are usedin logical inference (reasoning). Class axioms:• Sub-class relationship (from RDF Schema)• Equivalent relationship: classes have the same individualsEquivalentClass(:Musician :MusicArtist):Musician owl:equivalentClass :MusicArtist .• Disjointness: classes have no shared individualsDisjointClasses(:SoloMusicArtist :MusicGroup):SoloMusicArtist owl:disjointWith :MusicGroup .≡≡
  • Class ConstructionEUCLID - 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 tobuild new classesMusic ArtistArtist:MusicArtist rdfs:subClassOf :Artist .
  • Class Construction (2)EUCLID - Querying Linked Data 81These class constructs are available in OWL, not in RDFSThe class of female music artistsObjectIntersectionOf(:Female :MusicArtist)[a owl:Class;owl:intersectionOf(:Female :MusicArtist)]The class of music artistsObjectUnionOf(:SoloMusicArtist :MusicGroup)[a owl:Class;owl:unionOf(:SoloMusicArtist :MusicGroup)]Everything that’s not instrumental musicObjectComplementOf(:InstrumentalMusic)[a owl:Class;owl:complementOf(:InstrumentalMusic)]FemaleMusic ArtistSoloGroupInstrumental≡≡≡NOTE: Anonymous classes!
  • Naming Class ConstructionsEUCLID - Querying Linked Data 82• Direct naming can be achieved via owl:equivalentClass• This construction provides necessary and sufficient conditionsfor class membership• Class naming can be also achieved using rdfs:subClassOf,it provides a necessary but insufficient condition for classmembershipMusic ArtistSoloGroupEquivalentClass(:MusicArtistObjectUnionOf(:SoloMusicArtist:MusicGroup)):MusicArtist owl:equivalentClass[owl:unionOf (:SoloMusicArtist :MusicGroup)]≡
  • SummaryEUCLID - 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 operationQueryingLinkedDataIn this chapter we studied:
  • Summary (2)EUCLID - Querying Linked Data 84• Reasoning over Linked Data:• SPARQL 1.1 entailment regimes• RDFS: entailment regimes, lacks of consistency check, inferencelimitations• OWL: properties, property axioms(symmetry, transitivity, inverse, functional, inversefunctional), individual axioms, class axioms, classconstructions, naming classes …ReasoningoverLinkedDataIn this chapter we studied:
  • For exercises, quiz and further material visit our website:EUCLID - Providing Linked Data 85@euclid_project euclidproject euclidprojecthttp://www.euclid-project.euOther channels:eBook Course
  • 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üller86