CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1...

60
CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan [email protected]

Transcript of CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1...

Page 1: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF

Aidan Hogan

[email protected]

Page 2: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Previously …

Page 3: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Semantic Web: Data, Logic, Query, Links

* More or less

Page 4: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

The LOD Cloud

Page 5: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

RDF: Proposed model for a Web of Data

Page 6: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

RDF: Proposed model for a Web of Data

Most legacy data on the Web not in RDF!

But where should this RDF come from?

So what legacy formats are common on the Web?

Page 7: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

LAMP: Linux, Apache, MySQL, PHP

Page 8: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

3-Tier Web Applications

Page 9: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Deep Web

Surface Web

Deep Web

Page 10: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Lots of data in relational databases …

http://db-engines.com/en/ranking

Page 11: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Lots of data in relational databases …

http://db-engines.com/en/ranking

Out of top 10 databases, 7 are relational databases.

Out of 348 databases, any idea in what position

the first SPARQL engine would be?

Page 12: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Top SPARQL engine is …

Page 13: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

RDB2RDF: Relational DataBases to RDF

Page 14: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Some relational tables about planets …

Page 15: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Meanwhile on Pluto …

Page 16: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

RDB2RDF?

How might we automatically convert this table to RDF?

Page 17: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping: Automatic RDB2RDF mapping

Page 18: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com
Page 19: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping

Page 20: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping

Each table name is a type

Each row is a subject

Each attribute a predicate

Each value an object

But what about RDF terms

(IRIs/literals/blank nodes)?

Page 21: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping: Identifying Rows

How can we identify Row1?

• If the table has a primary key (pk1,…,pkn): – http://ex.org/TableName/pk1=v1;...;pkn=vn – (Base IRI http://ex.org/ given as input)

• If not: use a fresh blank node.

So Row1 would be …?

http://ex.org/Planet/name=Mercury

Page 22: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping: Identifying Tables

How can we identify the table?

http://ex.org/Planet

Page 23: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping: Identifying Columns

How can we identify the attributes?

http://ex.org/Planet#ring

http://ex.org/Planet#dist

http://ex.org/Planet#...

Page 24: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping: Identifying Values

How can we identify values?

“Mercury”

“0.39”^^xsd:float

“false”^^xsd:boolean

Page 25: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping: Final RDF

Page 26: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping: Multiple Tables

Anything missing here?

If we assume that pname is a foreign key

for Planet.name, then ...

Page 27: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping: Foreign Key References

Page 28: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping: Foreign Key References

If table T1 has a foreign key to table T2: (fk1,…,fkn):

– Link with predicate: http://ex.org/T1#ref-fk1;...;fkn

– (Base IRI http://ex.org/ given as input)

Example: http://ex.org/Moon#ref-pname

Page 29: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping

Anything else missing here?

What should we do with NULL (⊥)??

Page 30: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping: NULL (⊥)

No triples generated for NULL (⊥).

(Semantics of NULL often not clear)

Page 31: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping: Information Preservation

Page 32: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping: Query Preservation

Page 33: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Direct Mapping: Customisation?

What if we want to customise the mapping,

e.g., to create a node for people?

Page 34: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML: Custom RDB2RDF mappings

Page 35: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com
Page 36: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML: In a nutshell

RDB R2RML

Mapping

What should we use to specify this R2RML mapping?

Page 37: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML Example: The Direct Mapping

Page 38: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML Example: The Direct Mapping

Triple Mapping

Source Table

Subject Mapping

Predicate-Object

Mapping

Predicate-Object

Mapping

Page 39: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML: Selecting a Logical Table

Triple Mapping

Source Table

Subject Mapping

Predicate-Object

Mapping

Predicate-Object

Mapping

Page 40: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML: Example with SQL Query

Page 41: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML Term Maps: Creating RDF Terms

Triple Mapping

Source Table

Subject Mapping

Predicate-Object

Mapping

Predicate-Object

Mapping

Page 42: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML Term Maps: Creating RDF Terms

Page 43: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML Term Maps: Constants

Page 44: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML Term Maps: Columns

Page 45: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML Term Maps: Templates

Page 46: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML Term Maps

Page 47: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML Term Maps: Example

Page 48: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML: Subject Map

Triple Mapping

Source Table

Subject Mapping

Predicate-Object

Mapping

Predicate-Object

Mapping

Page 49: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML: Example with multiple types

Page 50: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML: Predicate–Object Map

Triple Mapping

Source Table

Subject Mapping

Predicate–Object

Mapping

Predicate–Object

Mapping

Page 51: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML: Predicate–Object Map

Triple Mapping

Source Table

Subject Mapping

Predicate–Object

Mapping

Predicate–Object

Mapping

Page 52: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML: Reference Object Map

Page 53: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML: Reference Object Map

Page 54: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML: Reference Object Map

Page 55: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Summary of Triple Map Structure

* zero or more + one or more

(otherwise, precisely one)

Page 56: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML: Graph Maps

Page 57: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

R2RML …

Page 58: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

RDB2RDF

Page 59: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

RDB2RDF: Surfacing (some of) the Deep Web

Surface Web

Deep Web

Page 60: CC7220-1 La Web de Datosaidanhogan.com/teaching/cc7220-1-2019/lectures/WdD2019-10.pdf · CC7220-1 LA WEB DE DATOS PRIMAVERA 2019 Lecture 10: RDB2RDF Aidan Hogan aidhog@gmail.com

Questions?