Entities Relationships: Linking Entities

From version 3.1.0 in the Control Panel, Ontologies have been renamed as Entities. This does not alter any functionality, simply the nomenclature has been changed for a better understanding of the concept.

As of now, you can make relationships between ontologies through their attributes/properties. This tutorial will guide you on how to achieve this, also explaining the features this functionality involves.

Creating the links/references

Ontology relationships are defined at JSON Schema level, so there are two ways of making them:

From the creation wizard

Head to the Ontology creation wizard in the menu Development→Manage Ontologies→New→Creation Step by Step.

In this case, we are going to create an Ontology representing sales of different Firms across the globe, so this ontology will have the following properties:

The country property will be expressed as stated in ISO 3166-1 alpha-3, as this is the standard that we are using within the platform for several applications. Because of this, we already have an ontology modeling this ISO 3166-1, so let's link both properties Sales.country, with ISO3166_1.alpha3.

Click on 'Linked Data', below the properties table, and this will pop up a window to add/delete relationships between ontologies and their properties.

To make the one we are looking for, we are going to select the following values:

Source property is country, and target property alpha3 its from ISO3166_1.

NOTE: Only properties of the same type (string, number, integer, object...) can be linked.

NOTE:  Validation is optional. If you set validate to True, this means that any data related with this ontology (Sales) ingested by the platform will be involved in a validation process, where the platform will only save the data if the code in 'country' exists in ISO3166_1.alpha_3 database. The default is False.

Once all of this is selected, click on Add reference.

Now that the reference is made, you can close the window and click on Update schema.

As you can see in the generated Schema, there is an extra node named _references. This node will carry the information needed by the platform to identify and operate this relationship of properties.

You can now finish the creation process by clicking on Create.

By editing a JSON Schema

You can also make references programmatically by editing the JSON Schema.

To do this, you have to create the node '_references' from the root node. Then define 'self','target' and 'validate'.

'self' must be the absolute path to the attribute of source Ontology. Ex: Sales.country path is datos.properties.country.

'target' has the following structure: 

URL to Ontology Schema#Path to property
URL to Ontology Schema: this is always 'ontologies/schema/Ontology
#: Ontology to property separator.
Path to property: as in 'self', the absolute path to property.

'validate' set to true or false, recommended is false.

NOTE: This method may be useful to link properties embedded in objects, for example, linking a property (dni, String), with a property (dni, String) inside another property (person, object) : o1.dni → o2.person.dni

Graphical representation of the linked ontologies

Now that we have made the relationship, we can go to /controlpanel/main to see it.


As you can see in the graph, both ontologies, Sales and ISO3166_1 are linked. If you click on the 'Parent' ontology (Sales) you can see the relationship in the description. 

This description of the relationship is readable. Attributes are written straightforward, avoiding the use of property paths (this is just for defining them in the Schema).

Using QueryTool with autogenerated INNER JOINS

If you go to the QueryTool service under Tools→Query Tool, and you select an Ontology which has defined any relationship with another, a new option is available in the service: the JOIN panel. This panel is used to mount automatically SQL INNER JOINS with linked ontologies.

If you click on +, a new window will pop to select the attribute you want to query in the JOIN sentence.

Once selected source property, you may choose target in Ontology→property available for the JOIN.

Click OK and the query will be created, then you can execute it to see results (assuming there is data already in the database):

As you can see in the results, both properties, country and alpha3 have the same values (ESP).

NOTE: This example was performed with two ontologies with MongoDB as datasource, but the same will work for ontologies stores in ElasticSearch.

NOTE: You can also link ontologies with different datasources, everything will work fine apart from JOINs, but it is not possible to make JOINs between ontologies with different datasources as this is not yet implemented in the platform.

Elasticsearch example: