400 likes | 536 Views
RDF and SPARQL. Madalina Croitoru. Representing Knowledge. What type of knowledge. Novels and short stories are books A book is a document Every book has an author A document has a title A title is a String Hugo is the author of Notre Dame de Paris. How to represent this using:.
E N D
RDF and SPARQL MadalinaCroitoru
What type of knowledge • Novels and short stories are books • A book is a document • Every book has an author • A document has a title • A title is a String • Hugo is the author of Notre Dame de Paris
How to represent this using: • Conceptual Graphs • Database Model • RDF(S)
Generally speaking {p(x, y), q(y, z, t), p(z, A), q(z, t, B)} Facts: Conjunction of positive atoms
Generally speaking Facts: Conjunction of positive atoms {p(x, y), q(y, z, t), p(z, A), q(z, t, B)} x 1 p 2 y A B 1 q 3 p t 2 z q
Conceptual Graphs - Databases RDF(S)???
Representing Knowledge • Conceptual Graphs • Database Model • RDF(S) • OWL 2… • …
What good to representknowledge? • Querying! • What type of queries? • Conjunctive queries • Ontological queries
Ontological Conjuctive Query Answering Facts Conjunctive Query ╞ Facts: Conjunction of positive atoms Ontology Query: Conjunction of positive atoms
Ontological Conjuctive Query Answering Facts Conjunctive Query ╞ Ontology Φ
Facts ╞ Conjunctive Query Simple RDF entailment Database Conjunctive Query Answering Deduction in the conjunctive, positive, existential fragment of FOL
Ontological Conjuctive Query Answering Facts Conjunctive Query ╞ Ontology Type Hierarchy Every cat is a vertebrate If two people are brothers then they are relatives
Facts + Type Hierarchy ╞ Conjunctive Query RDF(S) entailment Conjunctive Positive Fragment of FOL Simple Conceptual Graphs Entailment
Ontological Conjuctive Query Answering Facts Conjunctive Query ╞ Ontology Rules For every cat there exists a cat who is its mother
Facts + Rules╞ Conjunctive Query Simple Conceptual Graphs Rules DATALOG +
Conjunction of positive atoms • Conceptual Graphs • Database Model • RDF(S)
Conjunction of positive atoms • Conceptual Graphs • Database Model • RDF(S) HOW TO QUERY THIS KNOWLEDGE?!?
Conjunction of positive atoms • Conceptual Graphs – projection (labelled graph homomorphism) • Database Model • RDF(S) HOW TO QUERY THIS KNOWLEDGE?
Conjunction of positive atoms • Conceptual Graphs • Database Model - SQL • RDF(S) HOW TO QUERY THIS KNOWLEDGE
Conjunction of positive atoms • Conceptual Graphs • Database Model • RDF(S) - SPARQL HOW TO QUERY THIS KNOWLEDGE
RDF The "http://en.wikipedia.org/wiki/Tony_Benn", published by Wikipedia, has for title 'Tony Benn‘ <http://en.wikipedia.org/wiki/Tony_Benn> <http://purl.org/dc/elements/1.1/publisher> "Wikipedia" <http://en.wikipedia.org/wiki/Tony_Benn> <http://purl.org/dc/elements/1.1/title> "Tony Benn" .
RDF The "http://en.wikipedia.org/wiki/Tony_Benn", published by Wikipedia, has for title 'Tony Benn‘. <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"> <rdf:Descriptionrdf:about="http://en.wikipedia.org/wiki/Tony_Benn"> <dc:title>Tony Benn</dc:title> <dc:publisher>Wikipedia</dc:publisher> </rdf:Description> </rdf:RDF>
SQL for Databases • SELECT: • FROM (tables) • WHERE (predicate) • GROUP BY (rows) • HAVING (predicate on GROUP BY rows) • ORDER BY (columns)
Select Clause example SELECT * FROM Book WHERE price > 100.00 ORDER BY title;
SPARQL SELECT ?name ?email WHERE { ?person rdf:type foaf:Person. ?person foaf:name ?name. ?person foaf:mbox ?email. }
SPARQL PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?email WHERE { ?person rdf:type foaf:Person. ?person foaf:name ?name. ?person foaf:mbox ?email. }
SPARQL – example 1 Data: <http://example.org/book/book1> <http://purl.org/dc/elements/1.1/title> "SPARQL Tutorial" . Query: SELECT ?title WHERE { <http://example.org/book/book1> <http://purl.org/dc/elements/1.1/title> ?title . }
SPARQL – example 2 Data: @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name "Johnny Lee Outlaw" . _:a foaf:mbox <mailto:jlow@example.com> . _:b foaf:name "Peter Goodguy" . _:b foaf:mbox <mailto:peter@example.org> . _:c foaf:mbox <mailto:carol@example.org> .
SPARQL – example 2 Query: PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?mbox WHERE { ?x foaf:name ?name . ?x foaf:mbox ?mbox }
SPARQL – example 2 Result: namembox "Johnny Lee Outlaw“ <mailto:jlow@example.com> "Peter Goodguy" <mailto:peter@example.org>
Construct in SPARQL Data: @prefix org: <http://example.com/ns#> . _:a org:employeeName "Alice" . _:a org:employeeId 12345 . _:b org:employeeName "Bob" . _:b org:employeeId 67890 .
Construct in SPARQL Query: PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX org: <http://example.com/ns#> CONSTRUCT { ?x foaf:name ?name } WHERE { ?x org:employeeName ?name }
Construct in SPARQL Result: @prefix org: <http://example.com/ns#> . _:x foaf:name "Alice" . _:y foaf:name "Bob" .
Construct in SPARQL Result Serialized: <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:foaf="http://xmlns.com/foaf/0.1/" > <rdf:Description> <foaf:name>Alice</foaf:name> </rdf:Description> <rdf:Description> <foaf:name>Bob</foaf:name> </rdf:Description> </rdf:RDF>
SPARQL exercise • Use both SELECT and CONSTRUCT • What are all the country capitals of Africa?