mowl.ontology
Ontology creation
- mowl.ontology.create.create_from_triples(triples_file, out_file, relation_name=None, bidirectional=False, head_prefix='', tail_prefix='')[source]
Method to create an ontology from a .tsv file with triples.
- Parameters:
triples_file (str) – Path for the file containing the triples. This file must be a .tsv file and each row must be of the form (head, relation, tail). It is also supported .tsv files with rows of the form (head, tail); in that case the field relation_name must be specified.
out_file (str) – Path for the output ontology file.
relation_name (str, optional) – Name for relation in case the .tsv input file has only two columns. Defaults to
None.bidirectional (bool, optional) – If True, the triples will be considered undirected. Defaults to
Falsehead_prefix (str, optional) – Prefix to be assigned to the head of each triple. Default is
"".tail_prefix (str, optional) – Prefix to be assigned to the tail of each triple. Default is
"".
Ontology extension
- mowl.ontology.extend.insert_annotations(ontology_file, annotations, out_file=None, verbose=False)[source]
Method to build dataset given an ontology file and the annotations to be inserted to the ontology. Annotation files must be in .tsv format, with no header. Per each row, the first element is the annotated entity and the rest of the elements are the annotating entities (which are the entities in the ontology).
- Parameters:
ontology_file (str) – Ontology file in .owl format
annotations (List of (str, str, bool) corresponding to (annotation file path, relation name, directed or undirected graph)) – Annotations to be included in the ontology. There can be more than one annotation file.
out_file (str, optional) – Path for the new ontology. Defaults to
ontology_fileverbose (bool) – If true, information is shown.”
EL Normalization
- mowl.ontology.normalize.AUXILIARY_IRI_BASE = 'http://mowl.borg/aux/'
Base of the IRIs of the fresh classes (and object properties) that the normaliser introduces to flatten nested class expressions. An auxiliary entity has the IRI
http://mowl.borg/aux/<tag>#<jcel name>, e.g.http://mowl.borg/aux/3f2a9c01be#AuxiliaryEntity42, where<tag>is the first 10 hex characters of the SHA-1 of the sorted string forms of the TBox axioms that were normalised. The same ontology therefore always yields the same names, and auxiliary entities of different ontologies (e.g. training and testing sets) never coincide.
- mowl.ontology.normalize.is_auxiliary_iri(iri)[source]
Returns
Trueifirinames an auxiliary entity introduced byELNormalizer.
- mowl.ontology.normalize.auxiliary_iri_prefix(axioms)[source]
Returns the auxiliary IRI prefix
http://mowl.borg/aux/<tag>#for a collection of OWL axioms.- Parameters:
axioms (iterable of
org.semanticweb.owlapi.model.OWLAxiom) – Axioms that are normalised- Return type:
- mowl.ontology.normalize.UNSUPPORTED_CONSTRUCT_MARKERS = ('UnionOf', 'MinCardinality', 'ComplementOf', 'AllValuesFrom', 'MaxCardinality', 'ExactCardinality', 'Annotation', 'ObjectHasSelf', 'urn:swrl', 'EquivalentObjectProperties', 'SymmetricObjectProperty', 'AsymmetricObjectProperty', 'ObjectOneOf', 'ObjectHasValue', 'DataSomeValuesFrom', 'DataAllValuesFrom', 'DataHasValue', 'DataPropertyRange', 'DataPropertyDomain', 'FunctionalDataProperty', 'DisjointUnion', 'HasKey', 'ObjectInverseOf')
Substrings of the string form of a TBox axiom that mark constructs the normaliser does not support; such axioms are dropped by
ELNormalizer.preprocess_ontology().ObjectInverseOfis among them because jcel would represent an inverse role by an auxiliary object property, which carries no link to the original role in the GCIs.
- class mowl.ontology.normalize.ELNormalizer[source]
Bases:
objectThis class wraps the normalization functionality found in the Java library
Jcel. The normalization process transforms an ontology into 7 normal forms in the description logic EL language.- num_dropped_axioms
Number of TBox axioms dropped by the last call to
preprocess_ontology()because they use unsupported constructs.
- normalize(ontology, load=False, ontology_path=None, use_cache=True)[source]
Performs the normalization. :param ontology: Input ontology :type ontology:
org.semanticweb.owlapi.model.OWLOntology:param load: Load the GCIs if the ontology is already normalized. Default is False. :type load: bool, optional :param ontology_path: Path to the original ontology file. If provided and use_cache is True, the normalized ontology will be cached to avoid re-normalization on subsequent calls. The cache file will be named<ontology_path>_mowl_el_normalized_v2.owl. :type ontology_path: str, optional :param use_cache: Whether to use caching. Default is True. If False, the ontology will be re-normalized even if a cache file exists. :type use_cache: bool, optional- Return type:
Dictionary where the keys are labels for each normal form and the values are a list of axioms of each normal form.
- mowl.ontology.normalize.abox_assertions(abox)[source]
The class assertions \(A(a)\) (
Aa named class) and object property assertions \(r(a, b)\) ofabox, as the"class_assertion"and"object_property_assertion"entries of the normalised axiom dictionary.Assertions about anonymous individuals (RDF blank nodes,
_:genid...) are left out, with a warning: a blank node has no identity outside the document it was parsed from (the same node gets a different identifier in every parse, and training and test files cannot refer to it), and OWLAPI’sgetIndividualsInSignature– from which mOWL’s individual index is built – lists named individuals only. Such an assertion therefore cannot be embedded and would break the index lookup.- Parameters:
abox – ABox axioms (e.g.
ontology.getABoxAxioms(Imports.INCLUDED)).- Return type:
- class mowl.ontology.normalize.Axiom(axiom)[source]
Bases:
objectBase class for all axioms in the \(\mathcal{EL}\) language
- property owl_axiom
Returns the axiom
- Return type:
org.semanticweb.owlapi.model.OWLAxiom
- class mowl.ontology.normalize.GCI(axiom)[source]
Bases:
AxiomBase class for all GCI types in the \(\mathcal{EL}\) language
- property owl_subclass
Returns the subclass of the GCI
- Return type:
org.semanticweb.owlapi.model.OWLClassExpression
- property owl_superclass
Returns the superclass of the GCI
- Return type:
org.semanticweb.owlapi.model.OWLClassExpression
- class mowl.ontology.normalize.ClassAssertion(axiom)[source]
Bases:
AxiomClass assertion axiom of the form \(A(a)\) :param axiom: Axiom of the form \(A(a)\) :type axiom:
org.semanticweb.owlapi.model.OWLAxiom- property class_
Returns the class of the class assertion
- Return type:
org.semanticweb.owlapi.model.OWLClass
- property individual
Returns the individual of the class assertion
- Return type:
org.semanticweb.owlapi.model.OWLNamedIndividual
- class mowl.ontology.normalize.ObjectPropertyAssertion(axiom)[source]
Bases:
AxiomObject property assertion axiom of the form \(R(a,b)\) :param axiom: Axiom of the form \(R(a,b)\) :type axiom:
org.semanticweb.owlapi.model.OWLAxiom- property object_property
Returns the object property of the object property assertion
- Return type:
org.semanticweb.owlapi.model.OWLObjectProperty
- property subject
Returns the subject of the object property assertion
- Return type:
org.semanticweb.owlapi.model.OWLNamedIndividual
- property object_
Returns the object of the object property assertion
- Return type:
org.semanticweb.owlapi.model.OWLNamedIndividual
- class mowl.ontology.normalize.GCI0(axiom)[source]
Bases:
GCIGCI of the form \(C \sqsubseteq D\)
- Parameters:
axiom (
org.semanticweb.owlapi.model.OWLAxiom) – Axiom of the form \(C \sqsubseteq D\)
- property subclass
Returns the subclass of the GCI: \(C\)
- Return type:
org.semanticweb.owlapi.model.OWLClass
- property superclass
” Returns the superclass of the GCI: \(D\) or \(\bot\)
- Return type:
org.semanticweb.owlapi.model.OWLClass
- class mowl.ontology.normalize.GCI0_BOT(axiom)[source]
Bases:
GCI0GCI of the form \(C \sqsubseteq \bot\)
- Parameters:
axiom (
org.semanticweb.owlapi.model.OWLAxiom) – Axiom of the form \(C \sqsubseteq \bot\)
- class mowl.ontology.normalize.GCI1(axiom)[source]
Bases:
GCIGCI of the form \(C \sqcap D \sqsubseteq E\)
- Parameters:
axiom (
org.semanticweb.owlapi.model.OWLAxiom) – Axiom of the form \(C \sqcap D \sqsubseteq E\)
- property left_subclass
” Returns the left operand of the subclass of the GCI: \(C\)
- Return type:
org.semanticweb.owlapi.model.OWLClass
- property right_subclass
Returns the right operand of the subclass of the GCI: \(D\)
- Return type:
org.semanticweb.owlapi.model.OWLClass
- property superclass
Returns the superclass of the GCI: \(E\) or \(\bot\)
- Return type:
org.semanticweb.owlapi.model.OWLClass
- class mowl.ontology.normalize.GCI1_BOT(axiom)[source]
Bases:
GCI1GCI of the form \(C \sqcap D \sqsubseteq \bot\)
- Parameters:
axiom (
org.semanticweb.owlapi.model.OWLAxiom) – Axiom of the form \(C \sqcap D \sqsubseteq \bot\)
- class mowl.ontology.normalize.GCI2(axiom)[source]
Bases:
GCIGCI of the form \(C \sqsubseteq \exists R.D\)
- Parameters:
axiom (
org.semanticweb.owlapi.model.OWLAxiom) – Axiom of the form \(C \sqsubseteq \exists R.D\)
- property subclass
Returns the subclass of the GCI: \(C\)
- Return type:
org.semanticweb.owlapi.model.OWLClass
- property object_property
Returns the object property of the GCI: \(R\)
- Return type:
org.semanticweb.owlapi.model.OWLObjectProperty
- property filler
Returns the filler of the GCI: \(D\)
- Return type:
org.semanticweb.owlapi.model.OWLClass
- class mowl.ontology.normalize.GCI3(axiom)[source]
Bases:
GCIGCI of the form \(\exists R.C \sqsubseteq D\)
- Parameters:
axiom (
org.semanticweb.owlapi.model.OWLAxiom) – Axiom of the form \(\exists R.C \sqsubseteq D\)
- property object_property
Returns the object property of the GCI: \(R\)
- Return type:
org.semanticweb.owlapi.model.OWLObjectProperty
- property filler
Returns the filler of the GCI: \(C\)
- Return type:
org.semanticweb.owlapi.model.OWLClass
- property superclass
Returns the superclass of the GCI: \(D\) or \(\bot\)
- Return type:
org.semanticweb.owlapi.model.OWLClass
- class mowl.ontology.normalize.GCI3_BOT(axiom)[source]
Bases:
GCI3GCI of the form \(\exists R.C \sqsubseteq \bot\)
- Parameters:
axiom (
org.semanticweb.owlapi.model.OWLAxiom) – Axiom of the form \(\exists R.C \sqsubseteq \bot\)
- class mowl.ontology.normalize.RoleInclusion(axiom)[source]
Bases:
AxiomRole inclusion axiom of the form \(R \sqsubseteq S\) (part of the \(\mathcal{EL}^{++}\) language).
- Parameters:
axiom (
org.semanticweb.owlapi.model.OWLAxiom) – Axiom of the form \(R \sqsubseteq S\)
- class mowl.ontology.normalize.RoleChain(axiom)[source]
Bases:
AxiomRole chain axiom of the form \(R \circ T \sqsubseteq S\) (part of the \(\mathcal{EL}^{++}\) language). Transitive property declarations are represented as \(R \circ R \sqsubseteq R\).
- Parameters:
axiom (
org.semanticweb.owlapi.model.OWLAxiom) – Axiom of the form \(R \circ T \sqsubseteq S\) or a transitive property declaration.
- mowl.ontology.normalize.extract_role_axioms(ontology)[source]
Extracts the role inclusion and role chain axioms from an ontology.
These axioms are not \(\mathcal{EL}\) GCIs and are therefore not returned by
ELNormalizer.normalize(). This function scans all the axioms of the ontology and returns the ones corresponding to role inclusions (\(R \sqsubseteq S\)), role chains (\(R \circ T \sqsubseteq S\)) and transitive property declarations.