# Quickstart

# Introduction

In this tutorial we will learn how to use Ontopic Studio a powerful Knowledge Graph design software, to extract key facts and insights from your database.

# 4 Steps to get you going

  1. Create a new project
  2. Create lenses from the database tables
  3. Map data to classes and properties
  4. Query the Knowledge Graph

# Create a new project

  1. The first step is to create a new project by clicking on the + icon or the text Get started by creating your first project.

    project list

  2. Give your project a name and add a description relevant to the project. Choose Sample DB as project type, so your new project connects to the existing sample database and click on Save.

    diagram of the mapping

After saving, you will automatically land on the dashboard of the newly created project.

Screenshot of Ontopic Studio while mapping a class to data in the relational database

# List of database tables

Having chosen a Sample DB as project type, the database connection is already set up, and you can see the list of tables by selecting the Lenses tab on the left-side navigation menu

Screenshot of Ontopic Studio while mapping a class to data in the relational database

# What we want to build

Our goal is to build a Knowledge Graph giving us information about all the lodging businesses in Bolzano.

The following diagram summarizes how we want to connect classes and properties in the Knowledge Graph to the data in the database tables:

Screenshot of Ontopic Studio while mapping a class to data in the relational database

For our tutorial, we will be using the following two tables for the sake of simplicity:

  1. source1.municipalities
  2. source1.hospitality

# Creating lenses

  1. Select Lenses from the left-side navigation menu to get a list of all tables

  2. Select the two tables source1.hospitality and source1.municipalities, by checking the checkboxes and clicking Generate mirror lens on the bottom of the page.
    Note: If you are using the Windows Desktop version select DESTINATION-DB.source1.hospitality and DESTINATION-DB.source1.municipalities .

    Screenshot of Ontopic Studio while mapping a class to data in the relational database

# Mapping data from the database to a Knowledge Graph

# Start populating your Graph (Mapping a lens to a class)

  1. Select Mapping from the left-side navigation menu, select the lens lenses.source1.hospitality, and then clicking on the c+ icon.

  2. Use the suggested template for generating the identifier for the class instances in our Knowledge Graph by selecting the first option Create a template and clicking on Create.

    diagram of the mapping

    diagram of the mapping

  3. Then create a new class voc:LodgingBusiness by clicking on Create new class and clicking on Create.

    diagram of the mapping

    diagram of the mapping

  4. Click on Save to obtain the new mapping entry for the class. The resulting mapping entry is as follows:

    diagram of the mapping

# Adding properties to the class instances (Mapping a lens to a data property)

  1. Create a property by clicking on the P+ icon, which is a new property

    diagram of the mapping

  2. Keeping the template data:source1-hospitality/{h_id} click on Create new property

    diagram of the mapping

  3. We create the property voc:name, and select the type to be data. Click on Create.

    diagram of the mapping

  4. Select name_en as the column from which we read names.

    diagram of the mapping

  5. Click on Save to add the new mapping entry for the property

    The resulting entry is as follows:

    diagram of the mapping

  6. Add a new class entry voc:Municipality

    1. Select Mapping from the left-side navigation menu, select the lens lenses.source1.municipalities, and then click on the c+ icon.

    2. Use the suggested template for generating the municipality instances in our Knowledge Graph by selecting the first option Create a template and click on Create.

    3. Then create a new class voc:Municipality by clicking on Create new class.

    4. Click on Save to obtain the new mapping entry for this class.

    5. The resulting entry should be:

      diagram of the mapping

  7. Add a new property entry voc:name to the same subject for name_en

    1. Create a property by clicking on the P+ icon, which adds a new property entry to the same subject.

    2. Keep the template data:source1-municipalities/{m_id} and select voc:name from the property dropdown.

    3. Select name_en as the column name and click on Save.

    4. The resulting entry should be:

      diagram of the mapping

Screenshot of Ontopic Studio while mapping a class to data in the relational database

# Connecting lodging businesses to municipalities (Mapping a lens to an object property)

The following mapping entry (opens new window) involves two different identifiers, one about lodging businesses and one about municipalities. We have to connect these two to get the answer to our specific question.

  1. Select Mapping from the left-side navigation menu, select the lens lenses.source1.hospitality, and create a property by clicking on the P+ icon, which is a new property entry.

    Screenshot of Ontopic Studio while mapping a class to data in the relational database

  2. Keeping the same template data:source1-hospitality/{h_id}, create a new property voc:containedIn and select the type to be object. Click on Create.

    diagram of the mapping

    diagram of the mapping

  3. Then select the object kind to be IRI/BNode (opens new window). Reuse the template data:source1-municipalities/{m_id} for the object.

    diagram of the mapping

  4. Click on Save to add the new property entry. The resulting mapping entry is:

    diagram of the mapping

Screenshot of Ontopic Studio while mapping a class to data in the relational database

# Query the Knowledge Graph

We can now extract key facts by testing the Knowledge Graph.

  1. Select Query from the left-side navigation menu.

    Screenshot of Ontopic Studio while mapping a class to data in the relational database

  2. Write the query for finding the lodging businesses and click on the play button.

    1. First we query the first 10 lodging businesses by typing:
      PREFIX voc: <http://vocabulary.example.org/>
      SELECT * WHERE {
          ?sub a voc:LodgingBusiness;
              voc:name ?name.
      }
      LIMIT 10
      

    The first 10 lodging businesses

    diagram of the mapping

    1. We can filter the result for those businesses which are in Bolzano:
      PREFIX voc: <http://vocabulary.example.org/>
      SELECT * WHERE {
          ?sub a voc:LodgingBusiness;
              voc:name ?name;
              voc:containedIn ?place.
          ?place voc:name "Bolzano/Bozen" .
      }
      LIMIT 10
      

    The first 10 located in Bolzano

    diagram of the mapping

# Materialize data into a graph database

Materialize in RDF files and load into a triplestore (starting from 2024.1).

Materialization to RDF is disabled by default (except for the Desktop version, where files are stored locally). See how to enable materialization with S3.

  1. Click on Materialize to materialize the knowledge graph into an RDF file.

    Screenshot of Ontopic Studio while mapping a class to data in the relational database

  2. Then select the RDF format

    Screenshot of Ontopic Studio while mapping a class to data in the relational database

  3. Then select the Compression format

    Screenshot of Ontopic Studio while mapping a class to data in the relational database

  4. You can materialize your KG into one file in compress or uncompress format. For simplicity, we keep the default option and materialize with zip compression.

  5. Click on Materialize, you will have all the content of KG copied to the file materialized-triples.ttl.

    Screenshot of Ontopic Studio while mapping a class to data in the relational database

  6. Now you can load this file in the triplestore of your choice, in this case, use GraphDB (opens new window). This graph database offers several ways to load files (opens new window). Here, since the file is only 200 MB, we go for the simplest option and load it directly from the UI.

  7. We can now see the list of materialized files by clicking on List files.

    Screenshot of Ontopic Studio while mapping a class to data in the relational database

  8. This will show a list of all materialized files. Each materialized file has three associated actions: "Export materialized file" or "Open directory", "Copy file location to clipboard", and "Delete materialized file".

    Screenshot of Ontopic Studio while mapping a class to data in the relational database