Skip to content

Ontology Pruning

OntologyPruner(onto)

Class for in-place ontology pruning.

Attributes:

Name Type Description
onto Ontology

The input ontology to be pruned. Note that the pruning process is in-place.

Parameters:

Name Type Description Default
onto Ontology

The input ontology to be pruned. Note that the pruning process is in-place.

required
Source code in src/deeponto/onto/pruning.py
33
34
35
36
37
38
39
40
def __init__(self, onto: Ontology):
    """Initialise an ontology pruner.

    Args:
        onto (Ontology): The input ontology to be pruned. Note that the pruning process is in-place.
    """
    self.onto = onto
    self._pruning_applied = None

save_onto(save_path)

Save the pruned ontology file to the given path.

Source code in src/deeponto/onto/pruning.py
42
43
44
45
46
def save_onto(self, save_path: str):
    """Save the pruned ontology file to the given path."""
    logging.info(f"{self._pruning_applied} pruning algorithm has been applied.")
    logging.info(f"Save the pruned ontology file to {save_path}.")
    return self.onto.save_onto(save_path)

prune(class_iris_to_be_removed)

Apply ontology pruning while preserving the relevant hierarchy.

paper

This refers to the ontology pruning algorithm introduced in the paper: Machine Learning-Friendly Biomedical Datasets for Equivalence and Subsumption Ontology Matching (ISWC 2022).

For each class \(c\) to be pruned, subsumption axioms will be created between \(c\)'s parents and children so as to preserve the relevant hierarchy.

Parameters:

Name Type Description Default
class_iris_to_be_removed list[str]

Classes with IRIs in this list will be pruned and the relevant hierarchy will be repaired.

required
Source code in src/deeponto/onto/pruning.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def prune(self, class_iris_to_be_removed: List[str]):
    r"""Apply ontology pruning while preserving the relevant hierarchy.

    !!! credit "paper"

        This refers to the ontology pruning algorithm introduced in the paper:
        [*Machine Learning-Friendly Biomedical Datasets for Equivalence and Subsumption Ontology Matching (ISWC 2022)*](https://link.springer.com/chapter/10.1007/978-3-031-19433-7_33).

    For each class $c$ to be pruned, subsumption axioms will be created between $c$'s parents and children so as to preserve the
    relevant hierarchy.

    Args:
        class_iris_to_be_removed (list[str]): Classes with IRIs in this list will be pruned and the relevant hierarchy will be repaired.
    """

    # create the subsumption axioms first
    for cl_iri in class_iris_to_be_removed:
        cl = self.onto.get_owl_object(cl_iri)
        cl_parents = self.onto.get_asserted_parents(cl)
        cl_children = self.onto.get_asserted_children(cl)
        for parent, child in itertools.product(cl_parents, cl_children):
            sub_axiom = self.onto.owl_data_factory.getOWLSubClassOfAxiom(child, parent)
            self.onto.add_axiom(sub_axiom)

    # apply pruning
    class_remover = OWLEntityRemover(Collections.singleton(self.onto.owl_onto))
    for cl_iri in class_iris_to_be_removed:
        cl = self.onto.get_owl_object(cl_iri)
        cl.accept(class_remover)
    self.onto.owl_manager.applyChanges(class_remover.getChanges())

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