Skip to content

Ontology Projection

OntologyProjector(bidirectional_taxonomy=False, only_taxonomy=False, include_literals=False)

Class for ontology projection -- transforming ontology axioms into triples.

Credit

The code of this class originates from the mOWL library.

Attributes:

Name Type Description
bidirectional_taxonomy bool

If True then per each SubClass edge one SuperClass edge will be generated. Defaults to False.

only_taxonomy bool

If True, then projection will only include subClass edges. Defaults to False.

include_literals bool

If True the projection will also include triples involving data property assertions and annotations. Defaults to False.

Parameters:

Name Type Description Default
bidirectional_taxonomy bool

description. If True then per each SubClass edge one SuperClass edge will be generated. Defaults to False.

False
only_taxonomy bool

If True, then projection will only include subClass edges. Defaults to False.

False
include_literals bool

description. If True the projection will also include triples involving data property assertions and annotations. Defaults to False.

False
Source code in src/deeponto/onto/projection.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
def __init__(self, bidirectional_taxonomy: bool=False, only_taxonomy: bool=False, include_literals: bool=False):
    """Initialise an ontology projector.

    Args:
        bidirectional_taxonomy (bool, optional): _description_. If `True` then per each `SubClass` edge one `SuperClass` edge will
            be generated. Defaults to `False`.
        only_taxonomy (bool, optional): If `True`, then projection will only include `subClass` edges. Defaults to `False`.
        include_literals (bool, optional): _description_. If `True` the projection will also include triples involving data property
            assertions and annotations. Defaults to `False`.
    """
    self.bidirectional_taxonomy = bidirectional_taxonomy
    self.include_literals = include_literals
    self.only_taxonomy = only_taxonomy
    self.projector = Projector(self.bidirectional_taxonomy, self.only_taxonomy,
                               self.include_literals)

project(ontology)

The projection algorithm implemented in OWL2Vec*.

Parameters:

Name Type Description Default
ontology Ontology

An ontology to be processed.

required

Returns:

Type Description
set

Set of triples after projection.

Source code in src/deeponto/onto/projection.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
def project(self, ontology: Ontology):
    """The projection algorithm implemented in OWL2Vec*.

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

    Returns:
        (set): Set of triples after projection.
    """
    ontology = ontology.owl_onto
    if not isinstance(ontology, OWLOntology):
        raise TypeError(
            "Input ontology must be of type `org.semanticweb.owlapi.model.OWLOntology`.")
    edges = self.projector.project(ontology)
    triples = []
    for e in edges:
        s, r, o = str(e.src()), str(e.rel()), str(e.dst())
        if o != "":
            if r == "http://subclassof":
                r = str(RDFS.subClassOf)
            triples.append((s, r, o))
    return set(triples)

Last update: June 25, 2023
Created: June 25, 2023
GitHub: @Lawhy   Personal Page: yuanhe.wiki