ontopOBDAModel - ConstantB/ontop-spatial GitHub Wiki

Table of Contents

OBDA Model

A central notion in -ontop- is that of OBDA model. An OBDA model is a specification of how the data in a data source is related to the vocabulary of an OWL or an RDFS ontology. An OBDA model is composed by a set of data source declarations and a set of mappings axioms.

  • A data source declaration associates an actual data source to an "identifier", i.e., a URI, and to a set of access properties that enable a system to establish a connection to the source. -ontop- currently supports JDBC data sources, and requires the usual JDBC access properties (i.e., jdbc url, username, password, jdbc driver).
  • A mapping axiom can be seen as a "rule" that indicates how to construct ABox assertions or RDF triples given the data that comes from an SQL query. Therefore, a mapping axiom is composed by a "source query", an SQL query over the data source, and a "target query", a template for ABox assertions or RDF triples that should be constructed using the rows returned by the SQL query.

The -ontop- implementation

Data source

An OBDA model must include one and only one data source. The data source is the database that holds the data of the system and over which the queries will be executed. Data sources in -ontop- are identified by a URI and are defined by means of JDBC connection properties. For example:

sourceUri=http://example.org/database/fub/Books
connectionUrl=jdbc:h2:tcp://localhost/books
username=myuser
password=mypassword
driverClass=org.h2.Driver

These parameters have the usual JDBC meaning and properties. To know more about JDBC connectivity and drivers, follow this link.

Mapping axioms

An OBDA model must also contain one or more mapping axioms. A mapping axiom consists of three fields: mappingId, source and target. The mappingId is any string identifying the axiom, the source is an arbitraty SQL query over the database, and the target is a triple template that contains placeholders that reference column names mentioned in the source query. For example, the following is a valid -ontop- mapping:

mappingId     Book collection
source        SELECT id, title FROM books
target        <http://www.example.org/library#BID_{id}> rdf:type :Book; :title {title} .

Here in the target, we have two types of placeholders: one is a literal template, i.e., {title}, and another is a URI Template, i.e., <http://www.example.org/library#BID_{id}>. The former placeholder is used to generate literal values, while the latter is used to create object URIs from the data in the database.

Note that the triples in the target are written using Turtle syntax, which allows for the usual Turtle shortcuts.
Note that the triple pattern must end with a final space and dot.

Meaning of a mapping axiom

The purpose of the mapping axioms is to convert data in the specified data sources into a set of ABox assertions/RDF triples. For the sake of this tutorial, assume that we generate RDF triples. Consider the following mapping:

mappingId     Employees
source        SELECT id, name FROM employee
target        <http://example.org/object-{id}> rdf:type :Employee; :name {name}^^xsd:string; :country "Italy" .

More specifically, a mapping axiom generates one set of RDF triples for each result row returned by the source query. The triples are created by replacing the placeholders in the target ({id} and {name}) with the values from the row. For example, if the answer to the source query were:

id name
22 John
23 Mary

Then, the given mapping would generate the following 6 RDF triples:

<http://example.org/object-22> rdf:type :Employee; 
         :name "John"^^xsd:string;
         :country "Italy".
<http://example.org/object-23> rdf:type :Employee;
         :name "Mary"^^xsd:string;
         :country "Italy".

Note that each row generates three triples, since the target in the mapping had 3 triple templates. Also note that by replacing {id} in the URI template <http://example.org/object-{id}> by the value 22, we get an actual URI <http://example.org/object-22>, and by replacing {name} in the literal template {name}^^xsd:string by the value John, we obtain an actual literal value "John"^^xsd:string.

Mapping Restrictions

Note that currently -ontop- does not allow mappings that generate TBox axioms. For that reason, RDFS or OWL vocabulary is not allowed in mappings, with the exception of rdf:type. For example, the following mapping is invalid:

?x rdfs:subClassOf ?y
SELECT x, y FROM subclass 
Since v1.9, Ontop allows to obtain the class names from the database. For example, the following is valid. See MetaMapping for more details
?x rdf:type ?y
SELECT x, y FROM table

For a full picture of the features and limitations of the mapping language, please take a look at the documentation for our reasoner Quest.

Serialization of OBDA Model

An important aspect of creating an OBDA model is being able to document, version and persist it. To do this, -ontopPro- and -ontopCore- allow you to serialize your OBDA model into .obda files, that you can later reuse with -ontopPro- or directly with Quest. For more information on the OBDA file format refer here.

Useful Links

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