RDBMS module
We now provide the definition of a data source type for relational data sources to exemplify the procedure for the definition of specific types of data sources modules. The XML Schema that implements this module can be found here:
- XML Schema for RDBMS data sources
RDBMS data source-type URI
Relational data sources are indicated with the following namespace:http://www.inf.unibz.it/obda/dig11/datasource-types/rdbms
From now on we will use the
prefix rdbms: to refer to this name space.
Data source parameters
Associated to this name space there are the following mandatory source parameter URIs:
- http://www.inf.unibz.it/obda/dig11/datasource-types/rdbms#username Specifies the user name that will be used to connect to the given database. For example: user1
- http://www.inf.unibz.it/obda/dig11/datasource-types/rdbms#dbname Specifies the name of the data base. For example: testdb
- http://www.inf.unibz.it/obda/dig11/datasource-types/rdbms#password Specifies the password to be used when connecting to the given database. For example: password
- http://www.inf.unibz.it/obda/dig11/datasource-types/rdbms#url Specifies the URL of the data base to be used. For example: jdbc:mysql://localhost/
- http://www.inf.unibz.it/obda/dig11/datasource-types/rdbms#driver Specifies the Driver name to be used to connect to the database. For example: com.mysql.jdbc.Driver
Example: A fully specified RDBMS data source:
<DataSource uri="http://www.inf.unibz.it/obda/dbs/mysql#testdb"
typeURI="http://www.inf.unibz.it/obda/dig11/datasource-types/rdbms">
<DataSourceParameter
uri=”http://www.inf.unibz.it/obda/dig11/datasource-types/rdbms#username”
value=”user1”/>
<DataSourceParameter
uri=”http://www.inf.unibz.it/obda/dig11/datasource-types/rdbms#dbname”
value=”testdb”/>
<DataSourceParameter
uri=”http://www.inf.unibz.it/obda/dig11/datasource-types/rdbms#password”
value=”password”/>
<DataSourceParameter
uri=”http://www.inf.unibz.it/obda/dig11/datasource-types/rdbms#url”
value=”jdbc:mysql://localhost/” />
<DataSourceParameter
uri=”http://www.inf.unibz.it/obda/dig11/datasource-types/rdbms#driver”
value=”com.mysql.jdbc.Driver” />
</DataSource>
Mapping axioms for RDBMS sources
Mapping axioms for data sources of the http://www.inf.unibz.it/obda/dig11/datasource-types/rdbms namespace can formed with a retrieve element as the query over the ontology and a SQLQuery element as the query over the source. Note that the id attribute of the retrieve element is not used for mappings. The semantics of these queries are not fixed and implementors must specify them when using this namespace as data source type.
The semantics of these mappings are not fixed and OBDA reasoner implementors must specify them.
The variables in the head of the ontology query must refer to variables in the SELECT of the SQL query.
The following is the specification of the queries that are used in the mappings. For full examples of RDBMS mappings as defined here, see the last part of this section.
Query elements
SQLQuery element
The SQLQuery element is an element with no children and a single string valued attribute, query.The query attribute hold the string for a valid SQL query which can be evaluated by the source. The semantics are fixed and are the traditinoal SQL semantics.Example. A SQLQuery element.
<SQLQuery query="select * from stockbooklist">
The Retrieve element
The Retrieve element allows you to describe UCQ’s over ontologies. It is taken from [1], where a full description can be found. We introduce a small change aimed at solving the impedance missmatch [2] problem when mapping data sources to ontologies.
The change consists in modify the definition of cqatom and rqatom elements to allow for an extra term type: funcind. This new term represents a skolem function with 1 or more variable terms in the for of indvar children. The funcind element can only appear in a possition where an object is expected, that is, in the only term in a cqatom, in the first term of a rqatom where the property is a datatype property (attribute), or in the first/second terms of a rqatom where the property is an object property. For more information about using skolem terms in source-ontology mappings we refer to [2].
Example. A skolem term “getStockBook” that returns individuals built with values from the stockbooklist.date variable.
<indfunc name="getBookObj">
<indvar name="stockbooklist.date"/>
</indfunc>
Example: An object property (role) query atom of the form objectproperty(function1(var1), function2(var2, var3)) in for a rdbms mapping:
<retrieve>
<head>
<indvar name="var1"/>
<indvar name="var2"/>
<indvar name="var3"/>
</head>
<body>
<qand>
<rqatom>
<indfunc name="function1">
<indvar name="var1"/>
</indfunc>
<indfunc name="function2">
<indvar name="var2"/>
<indvar name="var3"/>
</indfunc>
<ratom name="objectproperty"/>
</rqatom>
</qand>
</body>
</retrieve>
Mapping example
Now we provide a couple of exmples that exemplify the expression of mappings for RDBMS sources using the RDBMS module. Note that these are only synctactically correct rdbms mappings as defined by this module, the specific meaning of the mappings depends on the semantics implemented by the OBDA Enabled reasoner.Example 1. A simple concept mapping.
<MappingAxiom dataSourceURI="RandBStockExchange" enabled="true" id="mapping-transactionsdate">
<retrieve>
<head>
<indvar name="transaction.id"/>
</head>
<body>
<qand>
<cqatom>
<indfunc name="getTransactionObj">
<indvar name="transaction.id"/>
</indfunc>
<catom name="Transaction"/>
</cqatom>
</qand>
</body>
</retrieve>
<SQLQuery query="select id from transaction"/>
</MappingAxiom>
Example 2. A simple role (object property) mapping.
<MappingAxiom dataSourceURI="datasource1" id="role-mapping">
<retrieve>
<head>
<indvar name="worksfor.brokerid"/>
<indvar name="worksfor.clientid"/>
</head>
<body>
<qand>
<rqatom>
<indfunc name="getPersonObj">
<indvar name="brokerworksfor.brokerid"/>
</indfunc>
<indfunc name="getPersonObj">
<indvar name="brokerworksfor.clientid"/>
</indfunc>
<ratom name="WorksFor"/>
</rqatom>
</qand>
</body>
</retrieve>
<SQLQuery query="SELECT brokerid, clientid FROM brokerworksfor WHERE clientid IS NOT NULL"/>
</MappingAxiom>
Example 3. A simple attribute (datatype poperty) mapping.
<MappingAxiom dataSourceURI="RandBStockExchange" enabled="true" id="mapping-transactionsdate">
<retrieve>
<head>
<indvar name="transaction.id"/>
<indvar name="transaction.date"/>
</head>
<body>
<qand>
<rqatom>
<indfunc name="getTransactionObj">
<indvar name="transaction.id"/>
</indfunc>
<indvar name="transaction.date"/>
<ratom name="transactionDate"/>
</rqatom>
</qand>
</body>
</retrieve>
<SQLQuery query="select * from transaction"/>
</MappingAxiom>
Example 4. A compound mapping involving a concept and and two attributes (data type properties).
<MappingAxiom dataSourceURI="RandBStockExchange" enabled="true" id="mapping-stocks">
<retrieve>
<head>
<indvar name="stockinformation.id">
<indvar name="stockinformation.numberofshares"/>
<indvar name="stockinformation.sharetype"/>
</head>
<body>
<qand>
<cqatom>
<indfunc name="getStockObj">
<indvar name="stockinformation.id"/>
</indfunc>
<catom name="Stock"/>
</cqatom>
<rqatom>
<indfunc name="getStockObj">
<indvar name="stockinformation.id"/>
</indfunc>
<indvar name="stockinformation.id"/>
<ratom name="financialInstrumentID"/>
</rqatom>
<rqatom>
<indfunc name="getStockObj">
<indvar name="stockinformation.id"/>
</indfunc>
<indvar name="stockinformation.numberofshares"/>
<ratom name="amountOfShares"/>
</rqatom>
<rqatom>
<indfunc name="getStockObj">
<indvar name="stockinformation.id"/>
</indfunc>
<indvar name="stockinformation.sharetype"/>
<ratom name="typeOfShares"/>
</rqatom>
</qand>
</body>
</retrieve>
<SQLQuery query="select * from stockinformation"/>
</MappingAxiom>