ico

Module: Ontop

You are here: Home » Training programme » Module: Ontop

Ontop

Introduction

Ontop is a platform to query databases as Virtual RDF Graphs using SPARQL.

Ontop is here demonstrated with the help of the ontology editor and knowledge management system Protégé – as an extension to it.

The demonstration shall be using:

  • a database, the Northwind data base;
  • an ontology, the Northwind ontology; and
  • a mapping between database and ontology.

In the first part of the demonstration we shall set up the involved objects, display the mappings, and test them using SQL and SPARQL.
In the second part we shall create a new mapping, and test it.

Prepare demonstration

SQL database

Protégé/ontop

Import ontology, connect to  data base, import mappings, and test.

Start Protégé

Open Ontology: File>>Open… < northwind-ontology-M2T1.ttl >

Display tabs:  Window>>Tabs>>ontop Mappings

Connect data source

Tick off ontop Mappings tab: (Window>>Tabs>>ontop Mappings) ontop Mappings >> Datasource manager, fill in, and Save (Make sure the H2 Northwind data base is NOT running.)

DatasourceManager01

Make sure your connection URL and username is according to local installation.

In case Test Connection fails, check if jdbc driver is added in File>>Preferences>>JDBC Drivers:

jdbcDriver01

Import mappings: Ontop>>Import R2RML mappings…  <northwind-mapping-M2T2.ttl >

Test SQL Query

Test existing mapping

Select Ontop Mappings>>Mapping manager

Insert “MeatPoultry” into Search-field, and tick off Enable filter.

MeatPoultry

Double-click on “MeatPoultry”- mapping

MappingTest01

Test SPARQL query

Chose and Start Reasoner (After adding new mappings the reasoner needs to be stopped and restarted.)

  • Reasoner >> tick off Ontop 1.18.0
  • Reasoner >> Start reasoner

Tick off ontop SPARQL tab (Window>>Tabs>>ontop SPARQL)

Attach Prefixes: ontop SPARQL>>Attach Prefixes( Check off “:” and “nw:”), then Accept

Prefixes01 Add Prefixes and execute a SPARQL query

e.g.

SELECT ?x ?i ?n WHERE { ?x a nw:MeatPoultry; nw:product-productid ?i; nw:product-productname ?n.}

Execute, and compare the result to the SQL query

SPARQLquery01

Create a new mapping and test

Add Data property “order-totalorderprice”. Assign Domain: Order, Range: decimal, and suitable Annotations.

TotalOrderPrice

Add mapping: Ontop Mappings >> Mapping manager >> Create.

Target (Triplets Template):
nw:order-{ORDERID} nw:order-totalorderprice {TOTAL_ORDER_PRICE}^^xsd:decimal .
Source (SQL Query):
SELECT       O.ORDERID,
                     SUM( (OD.UNITPRICE * OD.QUANTITY) – OD.DISCOUNT) AS TOTAL_ORDER_PRICE
FROM           NORTHWIND.ORDERS AS O,
                      NORTHWIND.ORDERDETAILS AS OD
WHERE        O.ORDERID=OD.ORDERID
GROUP  BY O.ORDERID

TotalOrderPrice_mapping01

Test SPARQL query: ontop SPARQL:

SELECT ?x ?i ?t WHERE { ?x a nw:Order; nw:order-orderid ?i; nw:order-totalorderprice ?t.}

SPARQLquery02

 

Mapping

Mapping of data is the process of creating data element mappings between two distinct models of data. Here between a relational model expressed in SQL, and an RDF-ontology model expressed in RDF/OWL.

Mapping between a data base table and (part of) the ontology.

Mapping01

Blue arrows depict mapping of object properties – green of data properties.

From the above mapping virtual triplets based on the following templates are instantiated, and presented through SPARQL:

 

Subject

Property

Object

nw:Order rdf:type owl:Class (from ontology)
nw:order-{ORDERID} rdf:type nw:Order
nw:order-{ORDERID} nw:order-orderid <order-orderid>^^xsd:integer
nw:order-{ORDERID} nw:order-orderedby nw:Customer
nw:order-{ORDERID} nw:order-managedby nw:Employee
nw:order-{ORDERID} nw:order-orderdate <order-orderdate>^^xsd:dateTime
nw:order-{ORDERID} nw:order-requireddate <order-requireddate>^^xsd:dateTime
nw:order-{ORDERID} nw:order-shippeddate <order-shippeddate>^^xsd:dateTime
nw:order-{ORDERID} nw:order-shippedvia nw:Shipper
nw:order-{ORDERID} nw:order-freight <order-freight>^^xsd:decimal
nw:order-{ORDERID} nw:order-shipname <order-shipname>^^xsd:string
nw:order-{ORDERID} nw:order-shippedto nw:Location

Except for the shipping address the entire table is mapped to the resource Order (OWL class). The shipping address is mapped to the resource Location (OWL class), also identified by ORDERID.

Resources

Resource: Ontop Website

This website gives a comprehensive insight into Ontop, and also includes an introductory demo.

Resource: Mapping, Ontology, and Query Design Tips

This site also features links to tips concerning SPARQL, OWL, Ontop, Protege, Troubleshooting, etc. See table of content on the right.

Resource: Protégé Website

This is the official Protégé website.

Resource: RDB to RDF Mapping Language

This is a link to W3C (World Wide Web Consortium) description of R2RML.

Show Comments