Thursday, September 19, 2013

URI Templates for properties and classes

Since v1.9 ontop supports mappings with URI templates or variables in property or class locations. This means now you can write mappings like:

:person/{ID} rdf:type :Person{OCCUPATION}
SELECT ID, OCCUPATION FROM tbl_person

or like:

:person/{id} <{attribute}> {value}
SELECT id, attribute, value FROM tbl_data

This kind of mappings are very useful when some of the vocabulary of the ontology is in the DB.

Semantics

The new mappings are just syntactic sugar for normal mappings. What the ontop does internally is that, during initialisation time, it will transform these mappings into traditional mappings with fixed predicates/classes by inspecting the values in the DB. This is done at initialistation time, and changes to the DB in columns related to these mappings will not be taken into account by the system. For example, suppose the table tbl_person is as follows:


ID OCCUPATION
1 Researcher
2 Researcher
3 Doctor
4 Driver
5 Driver

If your mappings looks like:

:person/{ID} rdf:type :{OCCUPATION}
SELECT ID, OCCUPATION FROM tbl_person

ontop will translate it into the following 3 mappings (one for each distinct value of OCCUPATION):

:person/{ID} rdf:type :Researcher
SELECT ID, OCCUPATION FROM tbl_person WHERE OCCUPATION="Researcher"

:person/{ID} rdf:type :Doctor
SELECT ID, OCCUPATION FROM tbl_person WHERE OCCUPATION="Doctor"

:person/{ID} rdf:type :Driver
SELECT ID, OCCUPATION FROM tbl_person WHERE OCCUPATION="Driver"

If a new row is inserted in tbl_person in which a new occupation is introduced, e.g., (6,"Singer"), the system will not update itself. You need to restart it.

Limitations and Performance

The code that implements this is not very robust and the system may fail to create the real mappings if the original SQL query is not a simple SELECT-PROJECT-JOIN query. 

Also, each mapping of these form requires that ontop queries the database to find out the values of the DB. This could be expensive, depending on the database.

Give it a try and let us know how it goes!

No comments:

Post a Comment