Ontology to graph

In this module we provide different methods for projecting an ontology into a graph: The methods we provide are:

Ontology Projection

class mowl.projection.base.ProjectionModel

Bases: object

Abstract class for Ontology projection into a graph

Parameters

ontology (org.semanticweb.owlapi.model.OWLOntology) – The ontology to be processed.

project(ontology)

Performs the ontology parsing.

Returns

A list of triples where each triple is of the form \((head, relation, tail)\)

Return type

List of mowl.graph.edge.Edge

class mowl.projection.base.Graph(edges)

Bases: object

Stores a graph in the form of an edgelist in which each edge is an instance of the class mowl.graph.edge.Edge

Parameters

edges (mowl.graph.edge.Edge) – A list of edges

All the methods will return a list of edges corresponding to the Edge class:

Edge

class mowl.projection.edge.Edge(src, rel, dst, weight=1)

Bases: object

src()

Getter method for _src attribute

Return type

str

rel()

Getter method for _rel attribute

Return type

str

dst()

Getter method for _dst attribute

Return type

str

weight()

Getter method for _weight attribute

Return type

str

static getEntitiesAndRelations(edges)
Parameters

edges (Edge) – list of edges

Returns

Returns a 2-tuple containing the list of entities (heads and tails) and the list of relations

Return type

(Set of str, Set of str)

Subclass Hierarchy

class mowl.projection.taxonomy.model.TaxonomyProjector(bidirectional_taxonomy: bool = False)

Bases: ProjectionModel

This class will project the ontology considering only the axioms of the form \(A \sqsubseteq B\) where A and B are ontology classes.

Parameters
  • ontology – The ontology to be processed.

  • bidirectional_taxonomy – If true then per each SubClass edge one SuperClass edge will be generated.

project(ontology)

Performs the ontology parsing.

Returns

A list of triples where each triple is of the form \((head, relation, tail)\)

Return type

List of mowl.graph.edge.Edge

Subclass Hierarchy With Relations

class mowl.projection.taxonomyRels.model.TaxonomyWithRelsProjector(taxonomy=False, bidirectional_taxonomy: bool = False, relations=None)

Bases: ProjectionModel

This class will project the ontology considering the following axioms:

  • \(A \sqsubseteq B\) will generate the triple \(\langle A, subClassOf, B \rangle\)

  • \(A \sqsubseteq \exists R. B\) will generate the triple \(\left\langle A, R, B \right\rangle\)

Parameters
  • ontology – The ontology to be processed.

  • bidirectional_taxonomy – If true then per each SubClass edge one SuperClass edge will be generated.

project(ontology)

Performs the ontology parsing.

Returns

A list of triples where each triple is of the form \((head, relation, tail)\)

Return type

List of mowl.graph.edge.Edge

DL2Vec Graph

The DL2Vec graph follows the rules described in the paper Predicting candidate genes from phenotypes, functions, and anatomical site of expression (2020). The parsing rules are shown in the table below:

Condition 1

Condition 2

Triple(s)

\(A \sqsubseteq Q R_{0} \ldots Q R_{m} D\)

\(D := B_{1} \sqcup \ldots \sqcup B_{n} | B_{1} \sqcap \ldots \sqcap B_{n}\)

\(\left\langle A, (R_{0}...R_{m}), B_i \right\rangle\) for \(i \in 1 \ldots n\)

\(A \equiv Q R_{0} \ldots Q R_{m} D\)

\(A \sqsubseteq B\)

\(\left\langle A, SubClassOf, B \right\rangle\)

\(A \equiv B\)

\(\left\langle A, EquivalentTo, B \right\rangle\)

class mowl.projection.dl2vec.model.DL2VecProjector(bidirectional_taxonomy: bool = False)

Bases: ProjectionModel

Parameters
  • ontology – The ontology to be processed.

  • bidirectional_taxonomy – If true then per each SubClass edge one SuperClass edge will be generated.

project(ontology)

Performs the ontology parsing.

Returns

A list of triples where each triple is of the form \((head, relation, tail)\)

Return type

List of mowl.graph.edge.Edge

OWL2Vec* Graph

The OWL2Vec* graph follows the rules described in the paper OWL2Vec*: embedding of OWL ontologies (2021). The parsing rules are shown in the table below:

Axiom of condition 1

Axiom or triple(s) of condition 2

Projected triple(s)

\(A \sqsubseteq \square r . D\)

\(D \equiv B\left|B_{1} \sqcup \ldots \sqcup B_{n}\right| B_{1} \sqcap \ldots \sqcap B_{n}\)

\(\langle A, r, B\rangle\)

or

\(\square r . D \sqsubseteq A\)

\(\exists r . \top \sqsubseteq A\) (domain)

\(\top \sqsubseteq \forall r . B\) (range)

\(\langle A, r, B_{i}\rangle\) for \(i \in 1, \ldots, n\)

\(A \sqsubseteq \exists r .\{b\}\)

\(B(b)\)

\(r \sqsubseteq r^{\prime}\)

\(\left\langle A, r^{\prime}, B\right\rangle\) has been projected

\(r^{\prime} \equiv r^{-}\)

\(\left\langle B, r^{\prime}, A\right\rangle\) has been projected

\(s_{1} \circ \ldots \circ s_{n} \sqsubseteq r\)

\(\langle A, s_1, C_1\rangle \ldots \langle C_n, s_n, B\rangle\) have been projected

\(B \sqsubseteq A\)

\(-\)

\(\langle B, r d f s: s u b C l a s s O f, A\rangle\)

\(\left\langle A, rdfs:subClassOf^{-}, B\right\rangle\)

\(A(a)\)

\(-\)

\(\langle a, r d f: t y p e, A\rangle\)

\(\left\langle A, r d f: t y p e^{-}, a\right\rangle\)

\(r(a, b)\)

\(-\)

\(\langle a, r, b\rangle\)

class mowl.projection.owl2vec_star.model.OWL2VecStarProjector(bidirectional_taxonomy=False, only_taxonomy=False, include_literals=False)

Bases: ProjectionModel

Parameters
  • ontology (org.semanticweb.owlapi.model.OWLOntology) – The ontology to be processed.

  • bidirectional_taxonomy (bool) – If true then per each SubClass edge one SuperClass edge will be generated. Default is False.

  • include_literals (bool) – If true the graph will also include triples involving data property assertions and annotations. Default is False.

  • only_taxonomy (bool) – If true, the projection will only include subClass edges

project(ontology)

Performs the ontology parsing.

Returns

A list of triples where each triple is of the form \((head, relation, tail)\)

Return type

List of mowl.graph.edge.Edge