MetaMapping - ConstantB/ontop-spatial GitHub Wiki

Table of Contents

Meta Mapping

Meta Mapping is a feature introduced in -ontop- 1.9. This feature allows users to put variables in the target of mapping without restriction. This implies that class and property names can be loaded from the database dynamically with meta mapping. For example, the following mapping, which was invalid before as a normal mapping, is now a valid meta mapping.

?x rdf:type ?y
SELECT x, y FROM table

Syntax of Meta Mappings

The syntax of meta mapping is the same with the normal mapping, except that there is no restriction on the usage of variables. For example, the following two mappings are valid meta mappings.

mappingId	mapping1
target	{uri} a :{value}_{code} . 
source	SELECT value, uri, code FROM table1 where code > 0
mappingId	mapping2
target	{uri} :{role}_{code} {value} . 
source	SELECT value, uri, code, role FROM table1 where code > 0

Meaning of Meta Mappings

With meta mappings, the class and property names can be constructed from the database, which is similar to the individuals in the normal mapping.

Continue with the example mappings. Suppose we have a table named table1 as follows.

uri value code role
'uri1' 'A' '1' 'P'
'uri2' 'B' '2' 'P'
'uri3' 'A' '2' 'Q'
'uri4' 'B' '2' 'Q'
Then mapping1 will generate triples:
uri1 a :A_1 . uri2 a :B_2. uri3 a :A_2 . uri4 a :B_2 .

And mapping2 will generate triples:

uri1 :P_1 A . uri2 :P_2 B . uri3 :Q_2 A . uri4 :Q_2 B . 

Implementation by Meta Mappings Expansion

The implementation of meta mappings is by meta mapping expansion, which expands a given meta mapping as a template to a set of normal mappings based on the data in the database.

For example, to expand mapping1

mappingId	mapping1
target	{uri} a :{value}_{code} . 
source	SELECT value, uri, code FROM table1 where code > 0
the expander first queries what can be replaced for value and code by the SQL query:
SELECT DISTINCT value, code FROM table1 where code > 0

There are three results:

value code
'A' '1'
'B' '2'
'A' '2'
Then mapping1 is expanded to three normal mappings by restricting value and code to these query results:
target	{uri} a :A_1 . 
source	SELECT uri  FROM table1 where code > 0 AND value = 'A' AND code = '1'
target	{uri} a :B_2 . 
source	SELECT uri  FROM table1 where code > 0 AND value = 'B' AND code = '2'
target	{uri} a :A_2 . 
source	SELECT uri  FROM table1 where code > 0 AND value = 'A' AND code = '2'

Finally, the meta mapping is replaced by the normal mappings and the original meta mapping is removed internally. Quest then handle the expanded mappings as before.

⚠️ **GitHub.com Fallback** ⚠️