The Mapping Pattern You Always Need For Building Your Knowledge Graph
Building a Knowledge Graph is not an easy task, but it is worth the effort to integrate and access in a meaningful way the information stored in different data sources. In a previous article we already talked about the importance of using mapping to build a Knowledge Graph, and now we would like to show you how you can use mapping patterns for effective data integration.
In this series of articles, we provide examples of the implementation of mapping patterns using our mapping editor Ontopic Studio to design the mapping entries. As you will see, the use of mapping patterns simplifies the design, validation, and maintenance of mapping. Case in point, we start with a fundamental pattern: mapping a table to a class.
If you are wondering what mappings are, read our previous post.
The main data source used throughout the series is Microsoft’s AdventureWorks 2014, in our case the adaption to PostgreSQL. AdventureWorks is a well-known example of an operational database that is often used for demoing Extract-Transform-Load processes in data warehouses. It simulates the database of a made-up bicycle parts wholesaler, and includes data about employees, products, customers and sales. We use the classes and properties from schema.org. Schema.org has been built with the purpose of promoting structured data on the Web. Some commonly used types are for example Book, Movie, Recipe, Event, MedicalEntity, Organization, Person, and their type hierarchy.
The pattern: Mapping A Table To A Class
Mapping a table to a class is the first pattern you cannot do without when building a Knowledge Graph from a data source. It consists in associating a table in the relational data source to a class. This means that every single row of the table, which is uniquely identified by the primary key, represents an individual of the designated class.
Creating a lens from a table
In our Adventureworks database, we have a table production.product containing data about sold products and their manufacturing. We would like to be able to retrieve this data as entities in our Knowledge Graph, so we use Ontopic Studio to fetch this information from the data source.
In Ontopic Studio we connect to our data source and create a mirror lens of the table production.product called lenses.production.product. This lens is a virtual view over the original table production.product which allows us to visualize and edit the content without altering the original data stored in the data source. Here is a preview of the lens product providing information about bicycle parts to be sold. We can see that we have a column productid, our primary key, that identifies each product in our table.
In the following video we connect to the database, look at the data and create a lens.
Choosing the suitable class
After importing schema.org, we see that it contains a class that is well suited to represent the values stored in our table product. Product is a class representing any offered product or service, for example a pair of shoes, a concert ticket, the rental of a car or, in our case, bicycle parts.
Classes and properties from schema.org use the prefix schema. We can see their hierarchy and characteristics in Ontopic Studio before using them to build a mapping entry.
Creating the mapping entry
Let us now map the lens lenses.production.product with the class schema:Product from schema.org.
We make use of the primary key productid to identify each entity belonging to the class schema:Product. Ontopic Studio directly suggests a template for generating the entities in our Knowledge Graph using this column. To complete the mapping entry, we just have to select the class schema:Product among the classes provided by schema.org.
Note that no SQL query is needed for creating this mapping entry.
The resulting entry is the following:
Finally, we can test the mapping by making a query that shows the content of the Knowledge Graph.
We are able to obtain a resource for each individual present in the original table.
Final remarks on mapping a table to a class
Writing a mapping entry by hand is error-prone: typos in the SQL query are a frequent source of errors. As we have seen, a mapping entry for a class can be created easily in Ontopic Studio without typing any SQL.
This pattern has been presented as well in the book Designing and Building Enterprise Knowledge Graphs. The authors Juan Sequeda and Ora Lassila call it direct concept. A direct concept maps a table to a concept, where a concept corresponds to what we call a class in the present article.
A similar pattern has been presented in the article Mapping Patterns for Virtual Knowledge Graphs by Diego Calvanese et al., where mapping a table to a class can be considered part of what they call the Schema Entity pattern.
Using mapping patterns in the process of building Knowledge Graphs helps us access and integrate our data in an effective way. The pattern presented in this article allows us to obtain the first entities of our Knowledge Graph, products from the related database table, and to immediately query them. This is the first step to build a consistent and long-term maintainable enterprise Knowledge Graph. In the next article, we will see the second mapping pattern: mapping a table to data properties.
Have you ever worked with a mapping editor before? If you would like to try Ontopic Studio just register for a demo access or book a meeting.
Get a demo access of Ontopic Studio
Ready to do mapping with a no-code approach? Let us help you. Get a demo access: