Skip to content

Basic Usage of Ontology

\(\textsf{DeepOnto}\) extends from the OWLAPI and implements many useful methods for ontology processing and reasoning, integrated in the base class Ontology.

This page gives typical examples of how to use Ontology. There are other more specific usages, please refer to the documentation by clicking Ontology.

Loading Ontology

Ontology can be easily loaded from a local ontology file by its path:

from deeponto.onto import Ontology

Importing Ontology will require JVM memory allocation (defaults to 8g; if nohup is used to run the program in the backend, use nohup echo "8g" | python command):

Please enter the maximum memory located to JVM: [8g]: 16g

16g maximum memory allocated to JVM.
JVM started successfully.

Loading an ontology from a local file:

onto = Ontology("path_to_ontology.owl")

It also possible to choose a reasoner to be used:

onto = Ontology("path_to_ontology.owl", "hermit")


For faster (but incomplete) reasoning over larger ontologies, choose a reasoner like "elk".

Acessing Ontology Entities

The most fundamental feature of Ontology is to access entities in the ontology such as classes (or concepts) and properties (object, data, and annotation properties). To get an entity by its IRI, do the following:

from deeponto.onto import Ontology
# e.g., load the disease ontology
doid = Ontology("doid.owl")
# class or property IRI as input

To get the asserted parents or children of a given class or property, do the following:


To obtain the literal values (as Set[str]) of an annotation property (such as \(\texttt{rdfs:label}\)) for an entity:

# note that annotations with no language tags are deemed as in English ("en")

To get the special entities related to top (\(\top\)) and bottom (\(\bot\)), for example, to get \(\texttt{owl:Thing}\):


Ontology Reasoning

Ontology has an important attribute .reasoner for conducting reasoning activities. Currently, two types of reasoners are supported, i.e., HermitT and ELK.

Inferring Super- and Sub-Entities

To get the super-entities (a super-class, or a super-propety) of an entity, do the following:

doid_class = doid.get_owl_object("")
doid.reasoner.get_inferred_super_entities(doid_class, direct=False) 

The outputs are IRIs of the corresponding super-entities. direct is a boolean value indicating whether the returned entities are parents (direct=True) or ancestors (direct=False).

To get the sub-entities, simply replace the method name with sub_entities_of.

Inferring Class Instances

To retrieve the entailed instances of a class:


Checking Entailment

The implemented reasoner also supports several entailment checks for subsumption, disjointness, and so on. For example:

doid.reasoner.check_subsumption(doid_potential_sub_entity, doid_potential_super_entity)

Feature Requests

Should you have any feature requests (such as those commonly used in the OWLAPI), please raise a ticket in the \(\textsf{DeepOnto}\) GitHub repository.

Last update: September 29, 2023
Created: November 21, 2021
GitHub: @Lawhy   Personal Page: