Skip to content

Verbalise Ontology Concepts

Verbalising concept expressions is very useful for models that take textual inputs. While the named concepts can be verbalised simply using their names (or labels), complex concepts that involve logical operators require a more sophisticated algorithm. In \(\textsf{DeepOnto}\), we have implemented the recursive concept verbaliser originally proposed in the OntoLAMA paper to address the need.

Citation

@inproceedings{he2023language,
    title={Language Model Analysis for Ontology Subsumption Inference},
    author={He, Yuan and Chen, Jiaoyan and Jimenez-Ruiz, Ernesto and Dong, Hang and Horrocks, Ian},
    booktitle={Findings of the Association for Computational Linguistics: ACL 2023},
    pages={3439--3453},
    year={2023}
}

This rule-based verbaliser (found in OntologyVerbaliser) first parses a complex concept expression into a sub-formula tree (with OntologySyntaxParser). Each intermediate node within the tree represents the decomposition of a specific logical operator, while the leaf nodes are named concepts or properties. The verbaliser then recursively merges the verbalisations in a bottom-to-top manner, creating the overall textual representation of the complex concept. An example of this process is shown in the following figure:


verbalisation

Figure 1. Verbalising a complex concept recursively.


To use the verbaliser, do the following:

from deeponto.onto import Ontology, OntologyVerbaliser

# load an ontology and init the verbaliser
onto = Ontology("some_ontology_file.owl")
verbaliser = OntologyVerbaliser(onto)

To verbalise a complex concept expression:

# 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])

To verbaliser a class subsumption axiom:

# get subsumption axioms from the ontology
subsumption_axioms = onto.get_subsumption_axioms(entity_type="Classes")

# verbalise the first subsumption axiom
v_sub, v_super = verbaliser.verbalise_class_subsumption_axiom(subsumption_axioms[0])

Tip

The concept verbaliser is under development to incorporate the parsing of various axiom types. Please check the existing functions of OntologyVerbaliser for specific usage.

Notice that the verbalised result is a CfgNode object which keeps track of the recursive process. Users can access the final verbalisation by:

result.verbal

Users can also manually update the vocabulary for named entities by:

verbaliser.update_entity_name(entity_iri, entity_name)

This is useful when the entity labels are not naturally fitted into the verbalised sentence.

Moreover, users can see the parsed sub-formula tree using:

tree = verbaliser.parser.parse(str(subsumption_axioms[0]))
tree.render_image()

Note that rendering the image requires graphiviz to be installed. Check this link for installing graphiviz.

See an example with image at OntologySyntaxParser.


Last update: March 18, 2024
Created: January 28, 2023
GitHub: @Lawhy   Personal Page: yuanhe.wiki