CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... ·...

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

Transcript of CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... ·...

Page 1: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

CC7220-1LA WEB DE DATOS

PRIMAVERA 2017

Lecture 10: RDB2RDF

Aidan Hogan

[email protected]

Page 2: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Previously …

Page 3: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

RDF: Proposed model for a Web of Data

Page 4: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

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 5: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

LAMP: Linux, Apache, MySQL, PHP

Page 6: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

3-Tier Web Applications

Page 7: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Lots of data in relational databases …

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

Page 8: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Lots of data in relational databases …

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

Out of top 10 databases, 7 are relational databases.

Out of 310 databases, any idea in what position the

first SPARQL engine would be?

Page 9: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Top SPARQL engine is …

Page 10: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

RDB2RDF:Relational DataBases to RDF

Page 11: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Some relational tables about planets …

Page 12: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Meanwhile on Pluto …

Page 13: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

RDB2RDF?

How might we automatically convert this table to RDF?

Page 14: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

RDB2RDF:Direct Mapping

Page 15: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan
Page 16: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Direct Mapping

Page 17: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

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 18: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

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 19: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Direct Mapping: Identifying Tables

How can we identify the table?

http://ex.org/Planet

Page 20: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Direct Mapping: Identifying Columns

How can we identify the attributes?

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

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

Page 21: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Direct Mapping: Identifying Values

How can we identify values?

“Mercury”“0.39”^^xsd:float

“false”^^xsd:boolean

Page 22: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Direct Mapping: Final RDF

Page 23: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Direct Mapping: Multiple Tables

Anything missing here?

If we assume that pname is a foreign key

for Planet.name, then ...

Page 24: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Direct Mapping: Foreign Key References

Page 25: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

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 26: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Direct Mapping

Anything else missing here?

What should we do with NULL (⊥)??

Page 27: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Direct Mapping: NULL (⊥)

No triples generated for NULL (⊥).(Semantics of NULL often not clear)

Page 28: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Direct Mapping: Information Preservation

Page 29: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Direct Mapping: Query Preservation

Page 30: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Direct Mapping: Customisation?

What if we want to customise the mapping,

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

Page 31: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML:CUSTOM RDB2RDF MAPPINGS

Page 32: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan
Page 33: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: In a nutshell

RDBR2RMLMapping

What should we use to specify this R2RML mapping?

Page 34: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML Example: The Direct Mapping

Page 35: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML Example: The Direct Mapping

Triple Mapping

Source Table

Subject Mapping

Predicate-Object

Mapping

Predicate-Object

Mapping

Page 36: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Selecting a Logical Table

Triple Mapping

Source Table

Subject Mapping

Predicate-Object

Mapping

Predicate-Object

Mapping

Page 37: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Example with SQL Query

Page 38: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Term Maps—Creating RDF Terms

Triple Mapping

Source Table

Subject Mapping

Predicate-Object

Mapping

Predicate-Object

Mapping

Page 39: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Term Maps—Creating RDF Terms

Page 40: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Term Maps—Constants

Page 41: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Term Maps—Columns

Page 42: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Term Maps—Templates

Page 43: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Term Maps

Page 44: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Example of Term Maps

Page 45: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Subject Map

Triple Mapping

Source Table

Subject Mapping

Predicate-Object

Mapping

Predicate-Object

Mapping

Page 46: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Example with multiple types

Page 47: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Predicate–Object Map

Triple Mapping

Source Table

Subject Mapping

Predicate–Object

Mapping

Predicate–Object

Mapping

Page 48: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Predicate–Object Map

Triple Mapping

Source Table

Subject Mapping

Predicate–Object

Mapping

Predicate–Object

Mapping

Page 49: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Reference Object Map

Page 50: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Reference Object Map

Page 51: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Reference Object Map

Page 52: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Summary of Triple Map Structure

* zero or more

+ one or more

(otherwise, precisely one)

Page 53: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML: Graph Maps

Page 54: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

R2RML …

Page 55: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Recap

Page 56: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

RDB2RDF

• Lots of legacy data in Relational DataBases

– Would be nice if we could map that to RDF

• Direct Mapping: Automatic

– Automatic term generation

– Automatic links based on foreign keys

– Not customisable

• R2RML: Write custom mappings

– Logical tables (table name/SQL query)

– Term maps (S/P/O/G)

Page 57: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

End of new material!

Page 58: CC7220-1 La Web de Datos - Aidan Hoganaidanhogan.com/teaching/cc7220-1-2017/lectures/WdD2017... · 2017-10-18 · CC7220-1 LA WEB DE DATOS PRIMAVERA 2017 Lecture 10: RDB2RDF Aidan

Questions?