OpenHPI 3.4 - How to Query RDF(S)? - SPARQL 1.1 (4)

1,148 views
1,073 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,148
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
87
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

OpenHPI 3.4 - How to Query RDF(S)? - SPARQL 1.1 (4)

  1. 1. Semantic Web TechnologiesLecture 3: Semantic Web - Basic Architecture II 04: SPARQL 1.1 (4) Dr. Harald Sack Hasso Plattner Institute for IT Systems Engineering University of Potsdam Spring 2013 This file is licensed under the Creative Commons Attribution-NonCommercial 3.0 (CC BY-NC 3.0)
  2. 2. 2Lecture 3: Semantic Web - Basic Architecture II Open HPI - Course: Semantic Web Technologies Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  3. 3. cie nt for (S) s uffi tat ion Is R DF pre sen ge Re b? o wl ed ntic We Kn ma Se? - SPARQL 1.1 (4) in the 04 How to query RDF(S)Open HPI - Course: SemanticHarald Sack, Hasso-Plattner-Institut, Universität Potsdam Semantic Web Technologies , Dr. Web Technologies - Lecture 3: Semantic Web Basic Architecture
  4. 4. d x an4 ta ft... syn ra s in g d ge rkin an wo r ch a cu till ) oc s ght is 2012 e mi his Nov h er se t of : T ecau (as t ion s b en tic tt an A m se SPARQL 1.1 next Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  5. 5. SPARQL 1.1 -- New Features • SPARQL 1.1 Query:5 • Assignments (e.g. BIND, SELECT expressions) • Aggregate functions (e.g. COUNT, SUM, AVG) • Subqueries • Negation (EXISTS, NOT EXISTS, MINUS) • Property paths • Basic query federation (SERVICE, BINDINGS) • SPARQL 1.1 Update: • Graph update (INSERT DATA, DELETE DATA, INSERT, DELETE, DELETE WHERE, LOAD, CLEAR) • Graph management (CREATE, DROP, COPY, MOVE, ADD) • SPARQL 1.1 Entailment for RDF, RDFS, OWL, RIF • SPARQL 1.1 Service Descriptions Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  6. 6. SPARQL 1.1 -- New Features • SPARQL 1.1 Query:5 • Assignments (e.g. BIND, SELECT expressions) • Aggregate functions (e.g. COUNT, SUM, AVG) • Subqueries • Negation (EXISTS, NOT EXISTS, MINUS) • Property paths • Basic query federation (SERVICE, BINDINGS) • SPARQL 1.1 Update: • Graph update (INSERT DATA, DELETE DATA, INSERT, DELETE, DELETE WHERE, LOAD, CLEAR) • Graph management (CREATE, DROP, COPY, MOVE, ADD) • SPARQL 1.1 Entailment for RDF, RDFS, OWL, RIF • SPARQL 1.1 Service Descriptions Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  7. 7. 6 SPARQL 1.1 -- Assignments • SPARQL 1.1 allows the creation of new values in a query PREFIX ex: <http://example.org/> SELECT ?Item (?Pr*1.1 AS ?NewP ) WHERE { ?Item ex:price ?Pr } Data @prefix ex: <http://example.org/> . Result ex:lemonade1 ex:price 3 . ex:beer1 ex:price 3. ex:wine1 ex:price 3.50 . ex:liqueur1 ex:price "n/a". Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  8. 8. 6 SPARQL 1.1 -- Assignments • SPARQL 1.1 allows the creation of new values in a query PREFIX ex: <http://example.org/> SELECT ?Item (?Pr*1.1 AS ?NewP ) WHERE { ?Item ex:price ?Pr } Data @prefix ex: <http://example.org/> . Result ?Item ?NewP ex:lemonade1 ex:price 3 . ex:beer1 ex:price 3. lemonade1 3.3 ex:wine1 ex:price 3.50 . beer1 3.3 ex:liqueur1 ex:price "n/a". wine1 3.85 liqueur1 Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  9. 9. 7 SPARQL 1.1 -- Aggregate Functions • SPARQL 1.1 allows the use of aggregate functions in queries PREFIX ex: <http://example.org/> SELECT (Count(?Item) AS ?C) WHERE { ?Item ex:price ?Pr } Data Result @prefix ex: <http://example.org/> . ex:lemonade1 ex:price 3 ; rdf:type ex:Softdrink. ex:beer1 ex:price 3; rdf:type ex:Beer. ex:wine1 ex:price 3.50 ; rdf:type ex:Wine. ex:wine2 ex:price 4 . rdf:type ex:Wine. ex:wine3 ex:price "n/a”; rdf:type ex:Wine. Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  10. 10. 7 SPARQL 1.1 -- Aggregate Functions • SPARQL 1.1 allows the use of aggregate functions in queries PREFIX ex: <http://example.org/> SELECT (Count(?Item) AS ?C) WHERE { ?Item ex:price ?Pr } Data Result @prefix ex: <http://example.org/> . ?C ex:lemonade1 ex:price 3 ; rdf:type ex:Softdrink. 5 ex:beer1 ex:price 3; rdf:type ex:Beer. ex:wine1 ex:price 3.50 ; rdf:type ex:Wine. ex:wine2 ex:price 4 . rdf:type ex:Wine. ex:wine3 ex:price "n/a”; rdf:type ex:Wine. Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  11. 11. 8 SPARQL 1.1 -- Aggregate Functions • SPARQL 1.1 allows the use of aggregate functions in queries PREFIX ex: <http://example.org/> SELECT (Count(DISTINCT ?T) AS ?C) WHERE { ?Item rdf:type ?T } Data Result @prefix ex: <http://example.org/> . ex:lemonade1 ex:price 3 ; rdf:type ex:Softdrink. ex:beer1 ex:price 3; rdf:type ex:Beer. ex:wine1 ex:price 3.50 ; rdf:type ex:Wine. ex:wine2 ex:price 4 . rdf:type ex:Wine. ex:wine3 ex:price "n/a”; rdf:type ex:Wine. Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  12. 12. 8 SPARQL 1.1 -- Aggregate Functions • SPARQL 1.1 allows the use of aggregate functions in queries PREFIX ex: <http://example.org/> SELECT (Count(DISTINCT ?T) AS ?C) WHERE { ?Item rdf:type ?T } Data Result @prefix ex: <http://example.org/> . ?C ex:lemonade1 ex:price 3 ; rdf:type ex:Softdrink. 3 ex:beer1 ex:price 3; rdf:type ex:Beer. ex:wine1 ex:price 3.50 ; rdf:type ex:Wine. ex:wine2 ex:price 4 . rdf:type ex:Wine. ex:wine3 ex:price "n/a”; rdf:type ex:Wine. Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  13. 13. 9 SPARQL 1.1 -- Aggregate Functions • SPARQL 1.1 allows the use of aggregate functions in queries PREFIX ex: <http://example.org/> SELECT ?T (Count(?Item) AS ?C) WHERE { ?Item rdf:type ?T } GROUP BY ?T Data Result @prefix ex: <http://example.org/> . ex:lemonade1 ex:price 3 ; rdf:type ex:Softdrink. ex:beer1 ex:price 3; rdf:type ex:Beer. ex:wine1 ex:price 3.50 ; rdf:type ex:Wine. ex:wine2 ex:price 4 . rdf:type ex:Wine. ex:wine3 ex:price "n/a”; rdf:type ex:Wine. Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  14. 14. 9 SPARQL 1.1 -- Aggregate Functions • SPARQL 1.1 allows the use of aggregate functions in queries PREFIX ex: <http://example.org/> SELECT ?T (Count(?Item) AS ?C) WHERE { ?Item rdf:type ?T } GROUP BY ?T Data Result @prefix ex: <http://example.org/> . ?T ?C ex:lemonade1 ex:price 3 ; rdf:type ex:Softdrink. Softdrink 1 ex:beer1 ex:price 3; rdf:type ex:Beer. Beer 1 ex:wine1 ex:price 3.50 ; rdf:type ex:Wine. Wine 3 ex:wine2 ex:price 4 . rdf:type ex:Wine. ex:wine3 ex:price "n/a”; rdf:type ex:Wine. Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  15. 15. 10 SPARQL 1.1 -- Aggregate Functions • SPARQL 1.1 allows the use of aggregate functions in queries PREFIX ex: <http://example.org/> SELECT ?T (Count(?Item) AS ?C) WHERE { ?Item rdf:type ?T } GROUP BY ?T HAVING Count(?Item) > 1 Data Result @prefix ex: <http://example.org/> . ex:lemonade1 ex:price 3 ; rdf:type ex:Softdrink. ex:beer1 ex:price 3; rdf:type ex:Beer. ex:wine1 ex:price 3.50 ; rdf:type ex:Wine. ex:wine2 ex:price 4 . rdf:type ex:Wine. ex:wine3 ex:price "n/a”; rdf:type ex:Wine. Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  16. 16. 10 SPARQL 1.1 -- Aggregate Functions • SPARQL 1.1 allows the use of aggregate functions in queries PREFIX ex: <http://example.org/> SELECT ?T (Count(?Item) AS ?C) WHERE { ?Item rdf:type ?T } GROUP BY ?T HAVING Count(?Item) > 1 Data Result @prefix ex: <http://example.org/> . ?T ?C ex:lemonade1 ex:price 3 ; rdf:type ex:Softdrink. Wine 3 ex:beer1 ex:price 3; rdf:type ex:Beer. ex:wine1 ex:price 3.50 ; rdf:type ex:Wine. ex:wine2 ex:price 4 . rdf:type ex:Wine. ex:wine3 ex:price "n/a”; rdf:type ex:Wine. Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  17. 17. 11 SPARQL 1.1 -- Aggregate Functions • more aggregate functions • SUM • AVG • MIN • MAX • SAMPLE -- „pick“ one non-deterministically • GROUP_CONCAT -- concatenate values with a designated string separator Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  18. 18. SPARQL 1.1 -- Aggregate Functions12 • Example for SAMPLE, GROUP_CONCAT PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ( SAMPLE(?N) as ?Name) ( GROUP_CONCAT(?M; SEPARATOR = ", ") AS ?Nicknames ) WHERE { ?P a foaf:Person ; foaf:name ?N ; foaf:nick ?M . } GROUP BY ?P @prefix ex: <http://example.org/> . Data @prefix foaf: <http://xmlns.com/foaf/0.1/> . ex:alice a foaf:Person; foaf:name "Alice Wonderland"; foaf:nick "Alice", "The real Alice". Result ex:bob a foaf:Person; foaf:name "Robert Doe", "Robert Charles Doe", "Robert C. Doe"; foaf:nick "Bob","Bobby","RobC","BobDoe". ex:charles a foaf:Person; foaf:name "Charles Charles"; foaf:nick "Charlie" . Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  19. 19. SPARQL 1.1 -- Aggregate Functions12 • Example for SAMPLE, GROUP_CONCAT PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ( SAMPLE(?N) as ?Name) ( GROUP_CONCAT(?M; SEPARATOR = ", ") AS ?Nicknames ) WHERE { ?P a foaf:Person ; foaf:name ?N ; foaf:nick ?M . } GROUP BY ?P @prefix ex: <http://example.org/> . Data @prefix foaf: <http://xmlns.com/foaf/0.1/> . ex:alice a foaf:Person; foaf:name "Alice Wonderland"; foaf:nick "Alice", "The real Alice". Result ex:bob a foaf:Person; foaf:name "Robert Doe", "Robert Charles Doe", ?Name ?Nicknames "Robert C. Doe"; foaf:nick "Bob","Bobby","RobC","BobDoe". Alice Wonderland The real Alice, Alice ex:charles a foaf:Person; foaf:name "Charles Charles"; Charles Charles Charlie foaf:nick "Charlie" . Robert C. Doe Bob, BobDoe, RobC, Bobby Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  20. 20. SPARQL 1.1 -- Subqueries13 • Subqueries are a way to embed SPARQL queries within other queries SELECT ?T WHERE { ?D foaf:maker ?P ; rdfs:label ?T . { SELECT DISTINCT ?P WHERE { ?D foaf:maker <http://dblp.l3s.de/…/authors/Harald_Sack>, ?P . FILTER ( ?P != <http://dblp.l3s.de/…/authors/Harald_Sack> ) } LIMIT 10 } } • result is achieved by first evaluating the inner query Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  21. 21. SPARQL 1.1 -- Negation14 • Filtering of query solutions is done within a FILTER expression using NOT EXISTS and EXISTS. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?person WHERE { ?person rdf:type foaf:Person . FILTER NOT EXISTS { ?person foaf:name ?name } } Data @prefix : <http://example/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix foaf: <http://xmlns.com/foaf/0.1/> . :alice rdf:type foaf:Person . :alice foaf:name "Alice" . :bob rdf:type foaf:Person . Result Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  22. 22. SPARQL 1.1 -- Negation14 • Filtering of query solutions is done within a FILTER expression using NOT EXISTS and EXISTS. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?person WHERE { ?person rdf:type foaf:Person . FILTER NOT EXISTS { ?person foaf:name ?name } } Data @prefix : <http://example/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix foaf: <http://xmlns.com/foaf/0.1/> . :alice rdf:type foaf:Person . :alice foaf:name "Alice" . :bob rdf:type foaf:Person . Result ?person :bob Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  23. 23. SPARQL 1.1 -- Negation15 • Filtering of query solutions be removing possible solutions with MINUS. PREFIX : <http://example/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT DISTINCT ?s WHERE { ?s ?p ?o . MINUS { ?s foaf:givenName "Bob" . } } Data @prefix : <http://example/> . @prefix foaf: <http://xmlns.com/foaf/0.1/> . Result :alice foaf:givenName "Alice" ; foaf:familyName "Smith" . :bob foaf:givenName "Bob" ; foaf:familyName "Jones" . :carol foaf:givenName "Carol" ; foaf:familyName "Smith" . Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  24. 24. SPARQL 1.1 -- Negation15 • Filtering of query solutions be removing possible solutions with MINUS. PREFIX : <http://example/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT DISTINCT ?s WHERE { ?s ?p ?o . MINUS { ?s foaf:givenName "Bob" . } } Data @prefix : <http://example/> . @prefix foaf: <http://xmlns.com/foaf/0.1/> . Result :alice foaf:givenName "Alice" ; ?s foaf:familyName "Smith" . :bob foaf:givenName "Bob" ; :alice foaf:familyName "Jones" . :carol :carol foaf:givenName "Carol" ; foaf:familyName "Smith" . Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  25. 25. SPARQL 1.1 -- Property Paths • A property path is a possible route through an RDF graph16 between two graph nodes. • trivial case: property path of length 1, i.e. a triple pattern • alternatives: match one or both possibilities { :book1 dc:title|rdfs:label ?displayString } • sequence: property path of length >1 { ?x foaf:mbox <mailto:alice@example> . ?x foaf:knows/foaf:knows/foaf:name ?name . } • inverse property paths: reversing the direction of the triple { ?x foaf:mbox <mailto:alice@example> } = { <mailto:alice@example> ^foaf:mbox ?x } Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  26. 26. SPARQL 1.1 -- Property Paths17 • inverse path sequences paths { ?x foaf:knows/^foaf:knows ?y . FILTER(?x != ?y) } • arbitrary length match { ?x foaf:mbox <mailto:alice@example> . ?x foaf:knows+/foaf:name ?name . } • negated property paths { ?x !(rdf:type|^rdf:type) ?y } Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  27. 27. SPARQL 1.1 -- New Features • SPARQL 1.1 Query:18 • Assignments (e.g. BIND, SELECT expressions) • Aggregate functions (e.g. COUNT, SUM, AVG) • Subqueries • Negation (EXISTS, NOT EXISTS, MINUS) me ... • Property paths co re to • Basic query federation (SERVICE, BINDINGS) mo • SPARQL 1.1 Update: • Graph update (INSERT DATA, DELETE DATA, INSERT, DELETE, DELETE WHERE, LOAD, CLEAR) • Graph management (CREATE, DROP, COPY, MOVE, ADD) • SPARQL 1.1 Entailment for RDF, RDFS, OWL, RIF • SPARQL 1.1 Service Descriptions Semantic Web Technologies , Dr. Harald Sack, Hasso-Plattner-Institut, Universität Potsdam
  28. 28. 19 How in RDBMS RDF to store RDF Data? • RDF Graph can be represented by a set of Triples (s,p,o) • Triples can simply be stored in a relational database system • Idea: Use a specific relational schema for RDF data and benefit from 40 years of research in the DB community • 3 steps for SPARQL query processing: (1) Convert SPARQL query to SQL query (w.r.t. the schema) (2) Use RDBMS to answer SQL query (3) Generate SPARQL query result from SQL query result 05 How to store RDF(S) Data? - SPARQL 1.1 (5)Open HPI - Course: SemanticHarald Sack, Hasso-Plattner-Institut, Universität Potsdam Semantic Web Technologies , Dr. Web Technologies - Lecture 3: Semantic Web Basic Architecture

×