Skip to content

Ontology Pruning

OntologyNormaliser()

Class for ontology normalisation.

Credit

The code of this class originates from the mOWL library, which utilises the normalisation functionality from the Java library Jcel.

The normalisation process transforms ontology axioms into normal forms in the Description Logic \(\mathcal{EL}\), including:

  • \(C \sqsubseteq D\)
  • \(C \sqcap C' \sqsubseteq D\)
  • \(C \sqsubseteq \exists r.D\)
  • \(\exists r.C \sqsubseteq D\)

where \(C\) and \(C'\) can be named concepts or \(\top\), \(D\) is a named concept or \(\bot\), \(r\) is a role (property).

Attributes:

Name Type Description
onto Ontology

The input ontology to be normalised.

temp_super_class_index Dict[OWLCLassExpression, OWLClass]

A dictionary in the form of {complex_sub_class: temp_super_class}, which means temp_super_class is created during the normalisation of a complex subsumption axiom that has complex_sub_class as the sub-class.

Source code in src/deeponto/onto/normalisation.py
88
89
def __init__(self):
    return

normalise(ontology)

Performs the \(\mathcal{EL}\) normalisation.

Parameters:

Name Type Description Default
ontology Ontology

An ontology to be normalised.

required

Returns:

Type Description
list[OWLAxiom]

A list of normalised TBox axioms.

Source code in src/deeponto/onto/normalisation.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def normalise(self, ontology: Ontology):
    r"""Performs the $\mathcal{EL}$ normalisation.

    Args:
        ontology (Ontology): An ontology to be normalised.

    Returns:
        (list[OWLAxiom]): A list of normalised TBox axioms.
    """

    processed_owl_onto = self.preprocess_ontology(ontology)
    root_ont = processed_owl_onto
    translator = Translator(
        processed_owl_onto.getOWLOntologyManager().getOWLDataFactory(), IntegerOntologyObjectFactoryImpl()
    )
    axioms = HashSet()
    axioms.addAll(root_ont.getAxioms())
    translator.getTranslationRepository().addAxiomEntities(root_ont)

    for ont in root_ont.getImportsClosure():
        axioms.addAll(ont.getAxioms())
        translator.getTranslationRepository().addAxiomEntities(ont)

    intAxioms = translator.translateSA(axioms)

    normaliser = OntologyNormalizer()

    factory = IntegerOntologyObjectFactoryImpl()
    normalised_ontology = normaliser.normalize(intAxioms, factory)
    self.rTranslator = ReverseAxiomTranslator(translator, processed_owl_onto)

    normalised_axioms = []
    # revert the jcel axioms to the original OWLAxioms
    for ax in normalised_ontology:
        try:
            axiom = self.rTranslator.visit(ax)
            normalised_axioms.append(axiom)
        except Exception as e:
            logging.info("Reverse translation. Ignoring axiom: %s", ax)
            logging.info(e)

    return list(set(axioms))

preprocess_ontology(ontology)

Preprocess the ontology to remove axioms that are not supported by the normalisation process.

Source code in src/deeponto/onto/normalisation.py
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
def preprocess_ontology(self, ontology: Ontology):
    """Preprocess the ontology to remove axioms that are not supported by the normalisation process."""

    tbox_axioms = ontology.owl_onto.getTBoxAxioms(Imports.fromBoolean(True))
    new_tbox_axioms = HashSet()

    for axiom in tbox_axioms:
        axiom_as_str = axiom.toString()

        if "UnionOf" in axiom_as_str:
            continue
        elif "MinCardinality" in axiom_as_str:
            continue
        elif "ComplementOf" in axiom_as_str:
            continue
        elif "AllValuesFrom" in axiom_as_str:
            continue
        elif "MaxCardinality" in axiom_as_str:
            continue
        elif "ExactCardinality" in axiom_as_str:
            continue
        elif "Annotation" in axiom_as_str:
            continue
        elif "ObjectHasSelf" in axiom_as_str:
            continue
        elif "urn:swrl" in axiom_as_str:
            continue
        elif "EquivalentObjectProperties" in axiom_as_str:
            continue
        elif "SymmetricObjectProperty" in axiom_as_str:
            continue
        elif "AsymmetricObjectProperty" in axiom_as_str:
            continue
        elif "ObjectOneOf" in axiom_as_str:
            continue
        else:
            new_tbox_axioms.add(axiom)

    processed_owl_onto = ontology.owl_manager.createOntology(new_tbox_axioms)
    # NOTE: the returned object is `owlapi.OWLOntology` not `deeponto.onto.Ontology`
    return processed_owl_onto

Last update: June 26, 2023
Created: April 19, 2023
GitHub: @Lawhy   Personal Page: yuanhe.wiki