Ontology and Database Systems Labs 2014/2015

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

  1. Run Protege 5 (run.bat file on Windows, and sh run.sh command from terminal on Linux/Mac).

  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. Start a database server. In this lab, we use a pre-bundled h2 database.

    On Mac or Linux:

    	  $ ./h2.sh 
    	
    On Windows:
    	  h2.bat  
    	
    A window will popup from the Web browser. You can login as follows:

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

  5. Configure JDBC driver for Protege. Open Menu "Preferences" -> "JDBC Drivers", and add JDBC driver:

  6. 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:

    NOTE: 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).

  7. 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.

  8. 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://www.example.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.

  9. 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.