Successfully reported this slideshow.

08 Linked Data Engineering - 3

410 Aufrufe

Veröffentlicht am

Lecture 8, Linked Data Engineering, SPARQL, Federated queries, SPARQL 11

Veröffentlicht in: Bildung
  • Als Erste(r) kommentieren

  • Gehören Sie zu den Ersten, denen das gefällt!

08 Linked Data Engineering - 3

  1. 1. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology Information Service Engineering Lecture 8: Linked Data Engineering - 3 Prof. Dr. Harald Sack FIZ Karlsruhe - Leibniz Institute for Information Infrastructure AIFB - Karlsruhe Institute of Technology Summer Semester 2017 This file is licensed under the Creative Commons Attribution-NonCommercial 3.0 (CC BY-NC 3.0)
  2. 2. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology Information Service Engineering Last Lecture: Linked Data Engineering - 2 3.1 Knowledge Representations and Ontologies 3.2 Semantic Web and the Web of Data 3.3 Linked Data Principles 3.4 How to name Things - URIs 3.5 Resource Description Framework (RDF) 3.6 Creating new Models with RDFS 3.7 Querying RDF(S) with SPARQL 3.8 More Expressivity with Web Ontology Language (OWL) 3.9 Wikipedia, DBpedia, and Wikidata 3.10 Linked Data Programming ● RDF Building Blocks ● RDF Blank Nodes ● RDF Schema ● SPARQL Query Language ● Graph Triple Patterns ● SPARQL General Query Format 2
  3. 3. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology Information Service Engineering Lecture 8: Linked Data Engineering - 3 3.1 Knowledge Representations and Ontologies 3.2 Semantic Web and the Web of Data 3.3 Linked Data Principles 3.4 How to name Things - URIs 3.5 Resource Description Framework (RDF) as simple Data Model 3.6 Creating new Models with RDFS 3.7 Querying RDF(S) with SPARQL 3.8 More Expressivity with Web Ontology Language (OWL) 3.9 Wikipedia, DBpedia, and Wikidata 3.10 Linked Data Programming 3
  4. 4. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology 4 https://www.flickr.com/photos/stefanobe/4305452977/ http://bnode.org/blog/2009/07/08/the-semantic-web-not-a-piece-of-cake
  5. 5. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology user interface SPARQL Query Language SPARQL Endpoint Client Server SPARQL Protocol Layer HTTP SPARQL - A Query Language for RDF(S) 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 5
  6. 6. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● SPARQL Protocol and RDF Query Language is ○ a Query Language for RDF graph traversal (SPARQL Query Language Specification) ○ a Protocol Layer, to use SPARQL via http (SPARQL Protocol for RDF Specification) ○ an XML Output Format Specification for SPARQL queries (SPARQL Query XML Results Format) SPARQL - A Query Language for RDF(S) 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 6
  7. 7. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● SPARQL results are given as well formed and valid XML documents <?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> ... </sparql> ● In a <head> element all variables of the SPARQL query are listed <head> <variable name="x"/> <variable name="hpage"/> <variable name="name"/> <variable name="mbox"/> <variable name="blurb"/> </head> SPARQL Result Format 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 7
  8. 8. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● For each SPARQL Query result exists a <result> element <?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="x"/> ... </head> <results> <result> <binding name="x"> ... </binding> <binding name="hpage"> ... </binding> </result> <result> ... </result> ... </results> </sparql> single SPARQL query result SPARQL Result Format 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 8
  9. 9. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Within a <binding> element a <head> variable is bound to a result <result> <binding name="x"> <bnode>r2</bnode> </binding> <binding name="hpage"> <uri>http://work.example.org/bob/</uri> </binding> <binding name="name"> <literal xml:lang="en">Bob</literal> </binding> <binding name="age"> <literal datatype="http://www.w3.org/2001/XMLSchema#integer"> 30 </literal> </binding> <binding name="mbox"> <uri>mailto:bob@work.example.org</uri> </binding> </result> variable bound to result SPARQL Result Format 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 9
  10. 10. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● SPARQL Protocol and RDF Query Language is ○ a Query Language for RDF graph traversal (SPARQL Query Language Specification) ○ a Protocol Layer, to use SPARQL via http (SPARQL Protocol for RDF Specification) ○ an XML Output Format Specification for SPARQL queries (SPARQL Query XML Results Format) SPARQL - A Query Language for RDF(S) 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 10
  11. 11. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Method to query/respond for SPARQL queries via http ● A SPARQL URI consists out of 3 parts: (1) URL of a SPARQL endpoint (e.g. http://example.org/sparql) (2) RDF Graph(s) to be queried (optional, part of the query string, e.g. named-graph-uri=http://example.org/testrdf.rdf) (3) SPARQL query (part of the query string, e.g. query=SELECT...) http://example.org/sparql?named-graph-uri=http%3A%2F%2Fexample.org%2Ftestrdf& query=SELECT+%3Freview_graph+WHERE+%7B%0D%0A++GRAPH+%3Frev iew_graph+%7B%0D%0A+++++%3Freview+rev%3Arating+10+.%0D%0A++%7D%0D%0A %7D SPARQL Protocol 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 11
  12. 12. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Simple SPARQL query PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dbo: <http://dbpedia.org/ontology/> SELECT ?author ?work WHERE { ?author rdf:type dbo:Writer ; dbo:notableWork ?work . } LIMIT 100 ● HTTP Trace of the SPARQL query GET http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=PREFIX+rdf%3A+%3Ch ttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0D%0APREFIX+dbo%3A+%3C http%3A%2F%2Fdbpedia.org%2Fontology%2F%3E%0D%0ASELECT+%3Fauthor++%3Fwork%0D%0AWH ERE+%7B%0D%0A+++++++%3Fauthor+rdf%3Atype+dbo%3AWriter+%3B%0D%0A+++++++++++++++dbo %3AnotableWork+%3Fwork+.%0D%0A%7D+LIMIT+100%0D%0A Host: dbpedia.org User-agent: Mozilla/5.0 … Accept:text/html,application/xhtml+xml,application/xml SPARQL Protocol Example 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 12
  13. 13. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● HTTP Trace of the SPARQL response HTTP/1.1 200 OK Date: Tue, 18 Aug 2015 09:55:07 GMT Content-Type: application/sparql-results+xml; charset=UTF-8 Content-Length: 21055 Connection: keep-alive Server: Virtuoso/07.20.3214 (Linux) x86_64-redhat-linux-gnu VDB X-SPARQL-default-graph: http://dbpedia.org ... <sparql xmlns="http://www.w3.org/2005/sparql-results#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/sw/DataAccess/rf1/result2.xsd"> <head> <variable name="author"/> <variable name="work"/> </head> <results distinct="false" ordered="true"> <result> <binding name="author"><uri>http://dbpedia.org/resource/Ding_Ling</uri></binding> <binding name="work"><uri>http://dbpedia.org/resource/Miss_Sophia's_Diary</uri></binding> </result> … </results> </sparql> SPARQL Protocol Example 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 13
  14. 14. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology SPARQL Protocol Example - Hands On 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL ● Goto DBpedia SPARQL endpoint http://dbpedia.org/sparql ● and write a simple SPARQL Query ● On SPARQL result screen copy URI from Browser ● Retrieve SPARQL query in terminal window via ○ curl -i "URI" 14 curl -i "http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&quX+rdf%3A+%3Chttp%3A% 2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0D%0APREFIX+dbo%3A+%3Chttp%3A%2F%2Fdbpe dia.org%2Fontology%2F%3E%0D%0ASELECT+%3Fauthor++%3Fwork%0D%0AWHERE+%7B%0D%0A+++++++%3Fauthor +rdf%3Atype+dbo%3AWriter+%3B%0D%0A+++++++++++++++dbo%3AnotableWork+%3Fwork+.%0D%0A%7D+LIMIT+ 100&format=application%2Fxml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=30000&deb ug=o" application/xml causes the SPARQL endpoint to deliver the result formatted according to the SPARQL Query XML Results format
  15. 15. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● SPARQL Protocol and RDF Query Language is ○ a Query Language for RDF graph traversal (SPARQL Query Language Specification) ○ a Protocol Layer, to use SPARQL via http (SPARQL Protocol for RDF Specification) ○ an XML Output Format Specification for SPARQL queries (SPARQL Query XML Results Format) SPARQL - A Query Language for RDF(S) 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 15
  16. 16. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Example: Filter results only for English labels PREFIX : <http://dbpedia.org/resource/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dbo: <http://dbpedia.org/ontology/> SELECT ?author_name ?title ?pages FROM <http://dbpedia.org/> WHERE { ?author rdf:type dbo:Writer . ?author rdfs:label ?author_name FILTER (LANG(?author_name)="en"). ?author dbo:notableWork ?work . ?work dbo:numberOfPages ?pages . FILTER (?pages > 500) ?work rdfs:label ?title . FILTER (LANG(?title)="en") } LIMIT 100 query SPARQL endpoint SPARQL Filter Constraints 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 16
  17. 17. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Logical connectives && (AND) and || (OR) for xsd:boolean ● Comparison operators =, !=, <, >, <=, and >= for numeric datatypes, xsd:dateTime, xsd:string, and xsd:boolean ● Comparison operators = and != for other datatypes ● Arithmetic operators +, -, *, and / for numeric datatypes ● and in addition: ○ REGEX(String,Pattern) or REGEX(String,Pattern,Flags) ○ sameTERM(A,B) ○ langMATCHES(A,B) More SPARQL Operators 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 17
  18. 18. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Example: Book titles that contain the word “love” PREFIX : <http://dbpedia.org/resource/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dbo: <http://dbpedia.org/ontology/> SELECT ?author_name ?title FROM <http://dbpedia.org/> WHERE { ?author rdf:type dbo:Writer . ?author rdfs:label ?author_name . FILTER (LANG(?author_name)="en") ?author dbo:notableWork ?work . ?work rdfs:label ?title . FILTER (LANG(?title)="en") FILTER REGEX (?title, "love", "i") } LIMIT 100 string regular expression flags query SPARQL endpoint SPARQL Filter Constraints 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 18
  19. 19. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Example: Retrieve also the German book title, if available PREFIX : <http://dbpedia.org/resource/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dbo: <http://dbpedia.org/ontology/> SELECT ?author_name ?en_title ?de_title FROM <http://dbpedia.org/> WHERE { ?author rdf:type dbo:Writer . ?author rdfs:label ?author_name . FILTER (LANG(?author_name)="en") ?author dbo:notableWork ?work . ?work rdfs:label ?en_title . FILTER (LANG(?en_title)="en") OPTIONAL { ?work rdfs:label ?de_title . FILTER (LANG(?de_title)="de") } } LIMIT 100 optional constraint ● The keyword OPTIONAL selects optional elements from the RDF graph ● complies to a Left Outer Join query SPARQL endpoint SPARQL Optional Queries 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 19
  20. 20. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Example: Retrieve all influencers of and people influenced by Miguel_de_Cervantes PREFIX : <http://dbpedia.org/resource/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dbo: <http://dbpedia.org/ontology/> SELECT ?influencer ?influenced FROM <http://dbpedia.org/> WHERE { { :Miguel_de_Cervantes dbo:influenced ?influenced . } UNION { :Miguel_de_Cervantes dbo:influencedBy ?influencer . } } logical disjunction ● The keyword UNION allows for alternatives (logical disjunction) query SPARQL endpoint SPARQL Alternative Results via UNION 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 20
  21. 21. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Example: Retrieve authors that don‘t have an entry for “notable work” PREFIX : <http://dbpedia.org/resource/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dbo: <http://dbpedia.org/ontology/> SELECT ?author FROM <http://dbpedia.org/> WHERE { ?author rdf:type dbo:Writer . FILTER NOT EXISTS {?author dbo:notableWork ?work .} } LIMIT 100 filter query result for existency SPARQL Negation 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL query SPARQL endpoint ● SPARQL 1.1 offers several variants for negation: ○ FILTER NOT EXISTS ○ MINUS ○ !BOUND() 21
  22. 22. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● SPARQL enables federated queries over several RDF datasets or SPARQL endpoints via the SERVICE objective PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX dbr: <http://dbpedia.org/resource/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT ?item ?childName WHERE { SERVICE <http://dbpedia.org/sparql> { ?item dbo:occupation dbr:Poet ; owl:sameAs ?wdItem FILTER regex (?wdItem, "wikidata.org") . } SERVICE <https://query.wikidata.org/sparql> { ?wdItem wdt:P40 ?child . ?child rdfs:label ?childName FILTER (LANG(?childName)="en"). } } ORDER BY ?item ● Example: connect the DBpedia with Wikidata ● only possible, if SPARQL endpoints permit federation SPARQL Federated Queries 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 22
  23. 23. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology 1. Download Blazegraph Triplestore for local SPARQL query processing via https://www.blazegraph.com/ 2. Install Blazegraph .jar file 3. Run blazegraph server on your local computer: java -server -Xmx4g -jar blazegraph.jar 4. Open blazegraph SPARQL endpoint in your browser: http://localhost:9999/blazegraph/ 5. Use federated query example in local blazegraph SPARQL endpoint SPARQL Federated Queries - Hand On 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 23
  24. 24. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology SPARQL Federated Queries - Hand On 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 24
  25. 25. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Example: Select all authors with their notable works and date of publication PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX dbp: <http://dbpedia.org/property/> SELECT ?author ?work ?date FROM <http://dbpedia.org/> WHERE { ?author rdf:type dbo:Writer . ?author dbo:notableWork ?work . ?work dbp:releaseDate ?date . } ORDER BY DESC(?date) LIMIT 100 query SPARQL endpoint SPARQL Variable Assignment 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 25
  26. 26. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology 26
  27. 27. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Example: Select all authors with their notable works and year of publication PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX dbp: <http://dbpedia.org/property/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?author ?work xsd:date(?date) AS ?year FROM <http://dbpedia.org/> WHERE { ?author rdf:type dbo:Writer . ?author dbo:notableWork ?work . ?work dbp:releaseDate ?date . } ORDER BY DESC(?year) LIMIT 100 A new variable assignment query SPARQL endpoint SPARQL Variable Assignment 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 27
  28. 28. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology 28
  29. 29. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Example: How many authors are there in DBpedia? PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dbo: <http://dbpedia.org/ontology/> SELECT COUNT(?author) AS ?num FROM <http://dbpedia.org/> WHERE { ?author rdf:type dbo:Writer . } aggregate function query SPARQL endpoint SPARQL Aggregate Functions 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 29
  30. 30. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Example: How many distinct authors are there in DBpedia who have entries for notable works? PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dbo: <http://dbpedia.org/ontology/> SELECT COUNT(DISTINCT(?author)) AS ?num FROM <http://dbpedia.org/> WHERE { ?author rdf:type dbo:Writer ; dbo:notableWork ?work . } aggregate function query SPARQL endpoint SPARQL Variable Assignment 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 30
  31. 31. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Example: Which author wrote how many notable works? PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dbo: <http://dbpedia.org/ontology/> SELECT ?author COUNT(?work) AS ?num_works FROM <http://dbpedia.org/> WHERE { ?author rdf:type dbo:Writer ; dbo:notableWork ?work . } GROUP BY ?author ORDER BY DESC (?num_works) aggregate function query SPARQL endpoint SPARQL Variable Assignment 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 31
  32. 32. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology 32
  33. 33. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● SPARQL 1.1 provides more aggregate functions ○ SUM ○ AVG ○ MIN ○ MAX ○ SAMPLE – „pick“ one non-deterministically ○ GROUP_CONCAT – concatenate values with a designated string separator SPARQL Variable Assignment 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 33
  34. 34. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● More SPARQL query functions ○ ASK - Check whether there is at least one result ○ CONSTRUCT - construct an RDF graph from a template, ○ DESCRIBE - return all facts (RDF triples) for resources ● More sophisticated SELECT queries with ○ Subqueries ○ Property paths ● SPARQL UPDATE ○ INSERT / DELETE RDF triples ○ CREATE / DROP / COPY / MOVE RDF graph ● SPARQL RDF(S)/OWL entailment More SPARQL 3. Linked Data Engineering / 3.7 Querying RDF(S) with SPARQL 34
  35. 35. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology Information Service Engineering Lecture 8: Linked Data Engineering - 3 3.1 Knowledge Representations and Ontologies 3.2 Semantic Web and the Web of Data 3.3 Linked Data Principles 3.4 How to name Things - URIs 3.5 Resource Description Framework (RDF) as simple Data Model 3.6 Creating new Models with RDFS 3.7 Querying RDF(S) with SPARQL 3.8 More Expressivity with Web Ontology Language (OWL) 3.9 Wikipedia, DBpedia, and Wikidata 3.10 Linked Data Programming 35
  36. 36. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology Web Ontology Language (OWL)
  37. 37. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● OWL is a semantic fragment of First Order Logic (FOL) ● OWL also exists in different flavors ○ OWL EL, OWL RL, OWL QL ⊆ OWL2 DL ⊆ OWL2 Full 37 Web Ontology Language OWL - OWL Flavors 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  38. 38. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology OWL2 is based on the Description Logic SROIQ(D) Class Expressions ● Class names A,B ● Conjunction C⊓D ● Disjunction C⊔D ● Negation ¬C ● Exist. property restriction ∃R.C ● Univ. property restriction ∀R.C ● Self ∃S.Self ● Greater-than ≥n S.C ● Less-than ≤n S.C ● Enumerated classes {a} Properties ● Property names R,S,T ● Simple properties S,T ● Inverse properties R- ● Universal property U Tbox (Class axioms) ● Inclusion C⊑D ● Equivalence C≣D Rbox (Property Axioms) ● Inclusion R1 ⊑ R2 ● General Inclusion R(-) 1 ∘ R (-) 2 ∘ ... ∘ R (-) n ⊑ R ● Transitivity ● Symmetry ● Reflexivity ● Irreflexivity ● Disjunctiveness Abox (Facts) ● Class membership C(a) ● Property relation R(a,b) ● Negated property relation ¬S(a,b) ● Equality a=b ● Inequality a≠b 38 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  39. 39. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● OWL namespace: @prefix owl: <http://www.w3.org/2002/07/owl#> ● There is a Turtle Syntax for OWL ● OWL axioms consist of the following three building blocks: ○ Classes ■ comparable with classes in RDFS ○ Individuals ■ comparable with class instances in RDFS ○ Properties ■ comparable with properties in RDFS 39 OWL Basic Building Blocks 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  40. 40. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology equivalent expression in description logics● there exist two predefined classes ○ owl:Thing (class that contains all individuals) ⊤ ≡ C⊔¬C ○ owl:Nothing (empty class) ⊥ ≡ C⊓¬C ● Definition of a class ○ :Book a owl:Class . 40 OWL Classes 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL) This is OWL in RDF/Turtle serialization
  41. 41. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Definition of individuals via class membership ○ :NineteenEightyfour a :Book . Book(NineteenEightyfour) ● Individuals can also be defined without class membership as named individuals ○ :HaraldSack a owl:NamedIndividual . 41 OWL Individuals 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  42. 42. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● there exist two property variants: ○ object properties ○ datatype properties ● Object properties have classes as range ○ :author a owl:ObjectProperty . ● Domain and Range of object properties ○ :author a owl:ObjectProperty ; rdfs:domain :Book ; rdfs:range :Writer . ∃author.⊤ ⊑ Book ⊤ ⊑ ∀author.Writer 42 OWL Object Properties 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  43. 43. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Datatype properties have datatypes as range ○ :publicationYear a owl:DatatypeProperty . ● Domain and Range of datatype properties ○ :publicationYear a owl:DatatypeProperty ; rdfs:domain :Book ; rdfs:range xsd:integer . ∃publicationYear.⊤ ⊑ Book ⊤ ⊑ ∀publicationYear.Integer 43 OWL Datatype Properties 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  44. 44. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology :Book a owl:Class . :Writer a owl:Class . :author a owl:ObjectProperty ; rdfs:domain :Book ; rdfs:range :Writer . :publicationYear a owl:DatatypeProperty ; rdfs:domain :Book ; rdfs:range xsd:integer . :GeorgeOrwell a Writer . :NineteenEightyFour a :Book ; :author :GeorgeOrwell ; :publicationYear 1948 . 44 OWL Properties and Individuals 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  45. 45. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology :Novel a owl:Class ; rdfs:subClassOf :Book . :Book a owl:Class ; rdfs:subClassOf :Work . :Work a owl:Class . ○ via inference it can be entailed that :Novel is also a subclass of :Work Novel ⊑ Book Book ⊑ Work 45 OWL Class Hierarchies 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  46. 46. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology :Book a owl:Class . :Writer a owl:Class . :Novel a owl:Class ; rdfs:subClassOf :Book . :Poet a owl:Class ; rdfs:subClassOf :Writer . :Book owl:disjointWith :Writer . ○ via inference it can be entailed that :Novel and :Poet are also disjoint classes Novel ⊑ Book Poet ⊑ Writer Book ⊓ Writer ⊑ ⊥ 46 OWL Class Hierarchies and Disjunctiveness 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  47. 47. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology :Writer a owl:Class . :Author a owl:Class . :Poet a owl:Class ; rdfs:subClassOf :Writer . :Writer owl:equivalentClass :Author . ○ via inference it can be entailed that :Poet is also an :Author Poet ⊑ Writer Writer ≡ Author 47 OWL Class Hierarchies and Equivalence 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  48. 48. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology :NineteenEightyfour a :Novel ; :author :GeorgeOrwell ; :publicationYear 1948 ; owl:sameAs :ARX012345 . :Novel a owl:Class ; rdfs:subClassOf :Book . :Book a owl:Class. ○ via inference it can be entailed that :ARX012345 is a :Book ○ difference of Individuals via owl:differentFrom :ARX012345 a :Novel ; owl:differentFrom :ARX012346 . 48 OWL Individuals - Identity and Distinctiveness 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  49. 49. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology :Novel a owl:Class . :AnimalFarm a :Novel . :NineteenEightyfour a :Novel . :NovelsInStore a owl:Class ; owl:oneOf ( :AnimalFarm :NineteenEightyfour ) . ○ There are only two novels available in the store. NovelsInStore ⊑ {AnimalFarm, NineteenEightyfour} OWL Complex Classes - Nominals 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  50. 50. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ○ logical AND (conjunction): owl:intersectionOf ⊓ ○ logical OR (disjunction): owl:unionOf ⊔ ○ logical negation: owl:complementOf ¬ ○ Logical constructors are applied to create complex class descriptions from atomic classes. OWL Logical Class Constructors 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  51. 51. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ○ The class :BooksInStore results from the intersection of all individuals of the classes :ThingsInStore and :Book :Book a owl:Class . :ThingsInStore a owl:Class . :BooksInStore a owl:Class ; owl:intersectionOf (:ThingsInStore :Book) . BooksInStore ≣ ThingsInStore ⊓ Books OWL Logical Class Constructors 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  52. 52. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ○ Novels, poetry, and non-fiction are also books :Book a owl:Class ; owl:equivalentClass [ owl:unionOf ( :Novel :Poetry :NonFiction ) ] . Book ≣ Novel ⊔ Poetry ⊔ NonFiction OWL Logical Class Constructors 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  53. 53. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ○ OWL property restrictions are used to describe complex classes via properties ○ restrictions on values: ○ owl:hasValue ○ owl:allValuesFrom ○ owl:someValuesFrom ○ restrictions on cardinality: ○ owl:cardinality ○ owl:minCardinality ○ owl:maxCardinality OWL Property Restrictions 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  54. 54. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● Class :OrwellsBooks is described via fixed value assignment (=constant) of the individual :GeorgeOrwell to the property :author :OrwellsBooks a owl:Class ; rdfs:subClassOf [ a owl:Restriction ; owl:onProperty :author ; owl:hasValue :GeorgeOrwell ] . OrwellsBooks ⊑ author.(GeorgeOrwell) OWL Property Restrictions with Constants 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  55. 55. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● owl:allValuesFrom fixes all instances of a specific class C as allowed range for a property p (strict binding) ∀p.C :Poetry a owl:Class ; rdfs:subClassOf [ a owl:Restriction ; owl:onProperty :author ; owl:allValuesFrom :Poet ] . Poetry ⊑ ∀author.Poet OWL Propertys Restriction with Strict Binding 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  56. 56. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology ● owl:someValuesFrom describes that there must exist an individual for p and fixes its range to class C (loose binding) ∃p.C :Reader a owl:Class ; rdfs:subClassOf [ a owl:Restriction ; owl:onProperty :reads ; owl:someValuesFrom :Book ] . Reader ⊑ ∃reads.Book OWL Property Restriction with Loose Binding 3. Linked Data Engineering / 3.8 More Expressivity with Web Ontology Language (OWL)
  57. 57. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology Information Service Engineering Next Lecture: Linked Data Engineering - 4 3.1 Knowledge Representations and Ontologies 3.2 Semantic Web and the Web of Data 3.3 Linked Data Principles 3.4 How to name Things - URIs 3.5 Resource Description Framework (RDF) as simple Data Model 3.6 Creating new Models with RDFS 3.7 Querying RDF(S) with SPARQL 3.8 More Expressivity with Web Ontology Language (OWL) 3.9 Wikipedia, DBpedia, and Wikidata 3.10 Linked Data Programming 57
  58. 58. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology 3. Linked Data Engineering - 3 Bibliography ● S. Harris, A. Seabourne (eds.) SPARQL 1.1 Query Language, W3C Recommendation, 21 March 2013, https://www.w3.org/TR/sparql11-query/ ● P. Hitzler, M. Krötzsch, B. Parsia, P. F. Patel-Schneider, S. Rudolph, OWL 2 Web Ontology Language , Primer (Second Edition), W3C Recommendation, 11 December 2012, https://www.w3.org/TR/2012/REC-owl2-primer-20121211/ ● S. Hitzler, S. Rudolph, Foundations of Semantic Web Technologies, Chapman / Hall, 2009. 58
  59. 59. Information Service Engineering , Prof. Dr. Harald Sack, FIZ Karlsruhe - Leibniz Institute for Information Infrastructure & AIFB - Karlsruhe Institute of Technology 3. Linked Data Engineering - 3 Syllabus Questions ● Explain the communication with a SPARQL endpoint via the SPARQL Protocol ● How can Regular Expressions be used in SPARQL queries? ● What is the use of a SPARQL optional query? ● How can conjunctive and disjunctive queries be expressed in SPARQL? ● What is a federated query? ● Why is OWL semantically more expressive than RDFS? ● What is the difference between OWL datatype properties and OWL object properties? ● How can OWL complex classes be created from simple classes? 59

×