RDF and SPARQL

40
RDF and SPARQL Madalina Croitoru

description

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:. - PowerPoint PPT Presentation

Transcript of RDF and SPARQL

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:

• Conceptual Graphs• Database Model• RDF(S)

Generally speaking

Facts: Conjunction of positive atoms

{p(x, y), q(y, z, t), p(z, A), q(z, t, B)}

Generally speaking

Facts: Conjunction of positive atoms {p(x, y), q(y, z, t), p(z, A), q(z, t, B)}

x y

z A

y z t

z t B

x

z

y

t

BA

p

q

q

p

1

2

1

2

3

Conceptual Graphs - Databases

BoyId GirlId

1 2

BoyId Name

1 John

GirlId Name

2 Eva

Conceptual Graphs - Databases

BoyId GirlId

1 2

BoyId Name

1 John

GirlId Name

2 Eva

RDF(S)???

Representing Knowledge

• Conceptual Graphs• Database Model• RDF(S)• OWL 2…• …

What good to represent knowledge?

• Querying!• What type of queries?– Conjunctive queries– Ontological queries

Ontological Conjuctive Query AnsweringFacts

Ontology╞ Conjunctive

QueryFacts: Conjunction of positive atoms

Query: Conjunction of positive atoms

Ontological Conjuctive Query Answering

Facts

Ontology╞ Conjunctive

QueryΦ

Facts ╞ Conjunctive Query

Simple RDF entailment

Database Conjunctive Query Answering

Deduction in the conjunctive, positive, existential fragment of FOL

Ontological Conjuctive Query Answering

Facts

Ontology╞ Conjunctive

QueryType HierarchyEvery 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

Ontology╞ Conjunctive

QueryRulesFor 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

Codd’s Relational Model

Codd’s Relational Model

RDF

RDFThe "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:Description rdf: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 1Data:<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:[email protected]> ._:b foaf:name "Peter Goodguy" . _:b foaf:mbox <mailto:[email protected]> . _:c foaf:mbox <mailto:[email protected]> .

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:

name mbox "Johnny Lee Outlaw“ <mailto:[email protected]> "Peter Goodguy" <mailto:[email protected]>

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?