Lecture 7: Mappings

In this lecture, we will look at mapping languages, how they can be used for mapping languages from one format into another format and what one needs to think about when making mappings.

Slides

Relevant Wiki-pages

Exercises

1. Direct mappings

Given the following tables:

store.customer:

 id | name  
----+-------
  1 | Kari
  2 | Peter

store.product:

 pid |  name  | price 
-----+--------+-------
   1 | Milk   |   0.8
   2 | Apple  |   2.1
   3 | Laptop | 120.9

store.orders:

 customer | product 
----------+---------
        1 |       2
        1 |       3
        2 |       2

where id is the primary key for store.customer, pid is the primary key for store.product, store.orders(customer) references store.customer(id) and store.orders(product) references store.product(pid).

For primary keys with more than one column (such as store.orders), simply introduce a blank node in place of an URI.

Write down the RDF graph resulting from using the direct mapping technique on the above tables.

2. Direct mappings with Triplelore

Here you can download the Lore-script making the database in the previous exercise. Use Triplelore, as described in the lecture, to add direct mappings to RDF of the relations. Remember to also add primary and foreign keys to the corresponding mappings-tables.

Use the base-IRI <http://example.org/> with prefix ex.

3. R2RML and Ontop

Make R2RML or Ontop-mappings that map the database from the previous exercises to RDF, such that the result is the following RDF-graph:

(Note: For R2RML when mapping store.orders, you will need to repeat the IRI-template for the customer.)

@prefix store: <http://mystore.com/> .
@prefix store-o: <http://mystore.com/ont/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

store:product1 rdf:type store-o:Product ;
               rdfs:label "Milk" ;
               store-o:price 0.8 .

store:product2 rdf:type store-o:Product ;
               rdfs:label "Apple" ;
               store-o:price 2.1 .

store:product3 rdf:type store-o:Product ;
               rdfs:label "Laptop" ;
               store-o:price 120.9 .

store:customer1 rdf:type store-o:Customer ;
                rdfs:label "Kari" ;
                store-o:orders store:product2, store:product3 .

store:customer2 rdf:type store-o:Customer ;
                rdfs:label "Peter" ;
                store-o:orders store:product2 .

More exercises on bOTTR and tabOTTR

There are lots of exercises in the OTTR primer (pOTTR), (used last week as well) on mappings.

The relevant parts for this week are the following:

Solution

The solution to the non-OTTR exercises is available here.