Ontology and Database Systems Labs 2013/2014

Lab 6. Learning to use Ontop from Protege with the Books example

  1. Download Protege 4.3 bundled with -ontopPro- (you will need to register).
    Run Protege 4.3 (run.bat file on Windows, and sh run.sh command from terminal on Linux/Mac). Note that only Java 7 is supported.

  2. Create and save an ontology (about books): specify an URI, for instance:

    Create two concepts, e.g., Book and Writer, an object property, e.g., writtenBy, and two data properties, e.g., bookTitle and personName.

  3. Add tabs ontop Mappings and ontop SPARQL in the menu Window -> Tabs -> ..
    Go to the ontop Mappings tab and add a new data source by pressing the button Create New ...

    Fill the fields as follows:

    Connection URL: jdbc:postgresql://alcor.inf.unibz.it/odbs
    Database Username: odbsstudent or your unibz account
    Database Password: odbs1314 or your unibz password (note, the password is stored uncrypted)
    Driver class: org.postgresql.Driver

    Add a JDBC driver for Postgres databases in Preferences -> JDBS Drivers. Now you can test connection.

    You can test connection to the university postgres database server by connecting via ssh to russel.inf.unibz.it using you unibz credentials (may be you first need to ask the technicians to enable access to russel for you by creating a ticket), and then running this command: psql -h alcor.inf.unibz.it -U odbsstudent odbs. You should be in the university network and use the default dns server to be able to access these servers. If you are outside the university, you can configure the university VPN.
    Alternatively, you can download a pre-bundled H2 server and run it in your memory. If you installed your own database server, create a books database and populate it using the SQL scripts from here. Refer to this page for more information on how to configure a data source (you will need a different Connection URL and a different Driver class for database systems different from Postgres).

  4. The relational schema of the books database is as follows:

  5. Switch to the Mapping manager tab, select the datasource you added, and create the following mapping:

    Note that here, : denotes the default prefix (the URI of your ontology), a is a predefined alias for the predicate rdf:type, Book is a concept name in our ontology (hence :Book is the URI of that concept). The triple :book{bk_code} a :Book asserts that the individuals identified by the string :book{bk_code} are instances of the concept Book. Moreover, :bookTitle is a data property in our ontology. More information about the mapping syntax can be found here.

  6. Now you can test your mapping. Switch to the ontop SPARQL tab, create a new query and call it Booktitles. In the Query Editor field write the query:
    PREFIX : <http://my.org/books#>
    SELECT * WHERE {?book a :Book; :bookTitle ?title}
    Then click on Save Changes, select the Quest reasoner and start it. Finally, execute your query. The result should look as follows:

    Pay attention to your prefix. You can attach your default prefix by clicking on Attach Prefixes.

  7. You can now extend your ontology and add other mappings so that you can reason about books, authors, book genres, editors, and ask complex queries, for instance, retrieve all authors and publication date of books with genre Horror.

You can find various information about Ontop on the official website. A tutorial on books from the developers can be found here. You can also have a look at another tutorial here.