Ontology Modularization

OntoLearner Logo

Ontologizer is a foundational module within OntoLearner that transforms ontologies into programmatically accessible Python objects, enabling seamless loading, inspection, and reuse across diverse domains. It supports multiple ontology formats (OWL, RDF, XML, TTL) and integrates metadata management, automated metric evaluation, and documentation generation to ensure ontologies are FAIR-compliant and traceable. By allowing users to import ontologies directly from web sources or HuggingFace repositories without manual file handling, Ontologizer simplifies ontology modularization and promotes scalable, cross-domain ontology enrichment. Its design supports version control and collaborative updates, while optimizing performance for large ontologies through multiprocessing, ultimately providing a flexible, user-friendly foundation for ontology-driven workflows and research.

Programmatic Import

OntoLearner provides a convenient interface to load and interact with popular ontologies directly from Hugging Face, making it easy to kickstart ontology-based learning tasks.

from ontolearner import Wine

ontology = Wine()

ontology.load()  # Automatically downloads and prepares ontology

data = ontology.extract()  # Returns learning tasks data

This will automatically download the ontology file and pre-processed datasets from the appropriate Hugging Face repository.

Use this method when the ontology file is stored on your local system:

ontology.from_local(path="path/to/ontology/file")

This method allows loading the ontology directly from the Hugging Face repository. No additional input (e.g., path) is required, as it uses the metadata defined in the Ontologizer to locate and retrieve the ontology automatically:

ontology.from_huggingface()

You can also access and work with domain-specific ontologies using intuitive import patterns, here are more examples:

from ontolearner import ENVO, ChEBI, MGED, AFO

# 🌱 Environmental science ontology
ontology = ENVO()

# ⚗️ Chemistry ontology (Chemical Entities of Biological Interest)
ontology = ChEBI()

# 🧬 Gene expression and microarray ontology
ontology = MGED()

# 🚜 Agriculture ontology (Agricultural Field Ontology)
ontology = AFO()

Each of these ontologies is tied to a specific domain repository on Hugging Face and includes both raw files and structured datasets, ready for training, evaluation, or integration into downstream pipelines.

Inspecting Metadata

Once an ontology is loaded, you can inspect its metadata by simply printing the ontology object. This outputs essential information encoded during modularization—capturing attributes that ensure traceability, version control, and alignment with FAIR principles. These metadata fields not only describe the ontology’s origin and scope but also support filtering, documentation, and automated validation during training or inference workflows.

from ontolearner import AgrO

ontology = AgrO()

Which will results in:

ontology_id: AgrO
ontology_full_name: Agronomy Ontology (AgrO)
domain: Agriculture
category: Agronomy
version: 1.0
last_updated: 2022-11-02
creator: The Crop Ontology Consortium
license: Creative Commons 4.0
format: RDF
download_url: https://agroportal.lirmm.fr/ontologies/AGRO?p=summary

This metadata snapshot allows users to quickly verify the ontology’s provenance, licensing, and format before usage. It also aids in reproducibility and collaboration by making ontology versioning and source links transparent within the OntoLearner ecosystem.

Automatic Usage

For flexible and dynamic loading of ontologies without hardcoding class names, use the AutoOntology interface. This is particularly useful when handling multiple ontologies programmatically or when ontology IDs are provided at runtime.

from ontolearner import AutoOntology

ontology = AutoOntology("AgrO")

This command automatically resolves and loads the specified ontology (in this case, the AgrO) by referencing its ontology_id. Behind the scenes, AutoOntology maps the identifier to its corresponding modularized class and metadata, streamlining workflows that require scalable, ontology-agnostic operations.

Hint

Each ontology listed on the Benchmarked Ontologies is accompanied by detailed documentation such as:

  • Short description on the ontology

  • Metadata table followed by ontology metrics.

  • Code snippets showing how to import the ontologies

For example, see the Chemical Entities of Biological Interest (ChEBI) ontology page.