DeepOnto provides a rule-based recursive verbaliser (OntologyVerbaliser) that converts complex logical concept expressions into natural language text. It works by parsing expressions into a sub-formula tree and recursively merging verbalisations from the bottom up. This is particularly useful for preparing textual inputs for language models.
To use it, initialize an OntologyVerbaliser with an Ontology instance, then use verbalise_class_expression to process complex classes.
from deeponto.onto import Ontology, OntologyVerbaliser
# Load an ontology and initialize the verbaliser
onto = Ontology("some_ontology_file.owl")
verbaliser = OntologyVerbaliser(onto)
# Get complex concepts asserted in the ontology
complex_concepts = list(onto.get_asserted_complex_classes())
# Verbalise the first complex concept
v_concept = verbaliser.verbalise_class_expression(complex_concepts[0])
# Access the final verbalised string
print(v_concept.verbal)