ontolearn.tentris

Tentris representations.

Module Contents

Classes

EncodedPosNegLPStandardTentris

Encoded Abstract learning problem following pos-neg lp standard.

TentrisOntology

Represents an OWL 2 Ontology in the OWL 2 specification.

TentrisReasoner

Extra convenience methods for OWL Reasoners

EvaluatedConceptTentris

Explicitly declare the attributes that should be returned by the evaluate_concept method of a KnowledgeBase.

TentrisKnowledgeBase

Representation of an OWL knowledge base in Ontolearn.

Attributes

logger

ontolearn.tentris.logger
class ontolearn.tentris.EncodedPosNegLPStandardTentris(id)

Bases: ontolearn.abstracts.EncodedPosNegLPStandardKind

Encoded Abstract learning problem following pos-neg lp standard.

__slots__ = 'id'
__repr__()

Return repr(self).

class ontolearn.tentris.TentrisOntology(path: str, endpoint_url: str, timeout: float)

Bases: owlapy.owl_ontology.OWLOntology

Represents an OWL 2 Ontology in the OWL 2 specification.

An OWLOntology consists of a possibly empty set of OWLAxioms and a possibly empty set of OWLAnnotations. An ontology can have an ontology IRI which can be used to identify the ontology. If it has an ontology IRI then it may also have an ontology version IRI. Since OWL 2, an ontology need not have an ontology IRI. (See the OWL 2 Structural Specification).

An ontology cannot be modified directly. Changes must be applied via its OWLOntologyManager.

__slots__ = ('_path', '_endpoint_url', '_backing_mgr', '_backing_onto', '_endpoint_timeout')
classes_in_signature() Iterable[owlapy.class_expression.OWLClass]

Gets the classes in the signature of this object.

Returns:

Classes in the signature of this object.

data_properties_in_signature() Iterable[owlapy.owl_property.OWLDataProperty]

Get the data properties that are in the signature of this object.

Returns:

Data properties that are in the signature of this object.

object_properties_in_signature() Iterable[owlapy.owl_property.OWLObjectProperty]

A convenience method that obtains the object properties that are in the signature of this object.

Returns:

Object properties that are in the signature of this object.

individuals_in_signature() Iterable[owlapy.owl_individual.OWLNamedIndividual]

A convenience method that obtains the individuals that are in the signature of this object.

Returns:

Individuals that are in the signature of this object.

abstract data_property_range_axioms(property: owlapy.owl_property.OWLDataProperty) Iterable[owlapy.owl_axiom.OWLDataPropertyRangeAxiom]

Gets the OWLDataPropertyRangeAxiom objects where the property is equal to the specified property.

Parameters:

property – The property which is equal to the property of the retrieved axioms.

Returns:

The axioms matching the search.

data_property_domain_axioms(property: owlapy.owl_property.OWLDataProperty) Iterable[owlapy.owl_axiom.OWLDataPropertyDomainAxiom]

Gets the OWLDataPropertyDomainAxiom objects where the property is equal to the specified property.

Parameters:

property – The property which is equal to the property of the retrieved axioms.

Returns:

The axioms matching the search.

object_property_domain_axioms(property: owlapy.owl_property.OWLObjectProperty) Iterable[owlapy.owl_axiom.OWLObjectPropertyDomainAxiom]

Gets the OWLObjectPropertyDomainAxiom objects where the property is equal to the specified property.

Parameters:

property – The property which is equal to the property of the retrieved axioms.

Returns:

The axioms matching the search.

object_property_range_axioms(property: owlapy.owl_property.OWLObjectProperty) Iterable[owlapy.owl_axiom.OWLObjectPropertyRangeAxiom]

Gets the OWLObjectPropertyRangeAxiom objects where the property is equal to the specified property.

Parameters:

property – The property which is equal to the property of the retrieved axioms.

Returns:

The axioms matching the search.

abstract get_owl_ontology_manager() owlapy.owl_ontology._M

Gets the manager that manages this ontology.

abstract get_ontology_id() owlapy.owl_ontology.OWLOntologyID

Gets the OWLOntologyID belonging to this object.

Returns:

The OWLOntologyID.

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__repr__()

Return repr(self).

class ontolearn.tentris.TentrisReasoner(ontology: TentrisOntology)

Bases: ontolearn.base.ext.OWLReasonerEx

Extra convenience methods for OWL Reasoners

(Not part of OWLAPI)

__slots__ = ('_ontology', '_backing_reasoner')
abstract data_property_domains(pe: owlapy.owl_property.OWLDataProperty, direct: bool = False) Iterable[owlapy.class_expression.OWLClass]
Gets the class expressions that are the direct or indirect domains of this property with respect to the

imports closure of the root ontology.

Parameters:
  • pe – The property expression whose domains are to be retrieved.

  • direct – Specifies if the direct domains should be retrieved (True), or if all domains should be retrieved (False).

Returns:

Let N = equivalent_classes(DataSomeValuesFrom(pe rdfs:Literal)). If direct is True: then if N is not empty then the return value is N, else the return value is the result of super_classes(DataSomeValuesFrom(pe rdfs:Literal), true). If direct is False: then the result of super_classes(DataSomeValuesFrom(pe rdfs:Literal), false) together with N if N is non-empty. (Note, rdfs:Literal is the top datatype).

object_property_domains(pe: owlapy.owl_property.OWLObjectProperty, direct: bool = False) Iterable[owlapy.class_expression.OWLClass]
Gets the class expressions that are the direct or indirect domains of this property with respect to the

imports closure of the root ontology.

Parameters:
  • pe – The property expression whose domains are to be retrieved.

  • direct – Specifies if the direct domains should be retrieved (True), or if all domains should be retrieved (False).

Returns:

Let N = equivalent_classes(ObjectSomeValuesFrom(pe owl:Thing)). If direct is True: then if N is not empty then the return value is N, else the return value is the result of super_classes(ObjectSomeValuesFrom(pe owl:Thing), true). If direct is False: then the result of super_classes(ObjectSomeValuesFrom(pe owl:Thing), false) together with N if N is non-empty.

object_property_ranges(pe: owlapy.owl_property.OWLObjectProperty, direct: bool = False) Iterable[owlapy.class_expression.OWLClass]
Gets the class expressions that are the direct or indirect ranges of this property with respect to the

imports closure of the root ontology.

Parameters:
  • pe – The property expression whose ranges are to be retrieved.

  • direct – Specifies if the direct ranges should be retrieved (True), or if all ranges should be retrieved (False).

Returns:

Let N = equivalent_classes(ObjectSomeValuesFrom(ObjectInverseOf(pe) owl:Thing)). If direct is True: then if N is not empty then the return value is N, else the return value is the result of super_classes(ObjectSomeValuesFrom(ObjectInverseOf(pe) owl:Thing), true). If direct is False: then the result of super_classes(ObjectSomeValuesFrom(ObjectInverseOf(pe) owl:Thing), false) together with N if N is non-empty.

abstract equivalent_classes(ce: owlapy.class_expression.OWLClassExpression, only_named: bool = True) Iterable[owlapy.class_expression.OWLClassExpression]

Gets the class expressions that are equivalent to the specified class expression with respect to the set of reasoner axioms.

Parameters:
  • ce – The class expression whose equivalent classes are to be retrieved.

  • only_named – Whether to only retrieve named equivalent classes or also complex class expressions.

Returns:

All class expressions C where the root ontology imports closure entails EquivalentClasses(ce C). If ce is not a class name (i.e. it is an anonymous class expression) and there are no such classes C then there will be no result. If ce is unsatisfiable with respect to the set of reasoner axioms then owl:Nothing, i.e. the bottom node, will be returned.

abstract data_property_values(ind: owlapy.owl_individual.OWLNamedIndividual, pe: owlapy.owl_property.OWLDataProperty) Iterable[owlapy.owl_literal.OWLLiteral]

Gets the data property values for the specified individual and data property expression.

Parameters:
  • ind – The individual that is the subject of the data property values.

  • pe – The data property expression whose values are to be retrieved for the specified individual.

  • direct – Specifies if the direct values should be retrieved (True), or if all values should be retrieved (False), so that sub properties are taken into account.

Returns:

A set of OWLLiterals containing literals such that for each literal l in the set, the set of reasoner axioms entails DataPropertyAssertion(pe ind l).

abstract object_property_values(ind: owlapy.owl_individual.OWLNamedIndividual, pe: owlapy.owl_property.OWLObjectPropertyExpression) Iterable[owlapy.owl_individual.OWLNamedIndividual]

Gets the object property values for the specified individual and object property expression.

Parameters:
  • ind – The individual that is the subject of the object property values.

  • pe – The object property expression whose values are to be retrieved for the specified individual.

  • direct – Specifies if the direct values should be retrieved (True), or if all values should be retrieved (False), so that sub properties are taken into account.

Returns:

The named individuals such that for each individual j, the set of reasoner axioms entails ObjectPropertyAssertion(pe ind j).

abstract flush() None

Flushes any changes stored in the buffer, which causes the reasoner to take into consideration the changes the current root ontology specified by the changes.

instances(ce: owlapy.class_expression.OWLClassExpression, direct: bool = False) Iterable[owlapy.owl_individual.OWLNamedIndividual]

Gets the individuals which are instances of the specified class expression.

Parameters:
  • ce – The class expression whose instances are to be retrieved.

  • direct – Specifies if the direct instances should be retrieved (True), or if all instances should be retrieved (False).

Returns:

If direct is True, each named individual j where the set of reasoner axioms entails DirectClassAssertion(ce, j). If direct is False, each named individual j where the set of reasoner axioms entails ClassAssertion(ce, j). If ce is unsatisfiable with respect to the set of reasoner axioms then nothing returned.

sub_classes(ce: owlapy.class_expression.OWLClassExpression, direct: bool = False, only_named: bool = True) Iterable[owlapy.class_expression.OWLClassExpression]

Gets the set of named classes that are the strict (potentially direct) subclasses of the specified class expression with respect to the reasoner axioms.

Parameters:
  • ce – The class expression whose strict (direct) subclasses are to be retrieved.

  • direct – Specifies if the direct subclasses should be retrieved (True) or if the all subclasses (descendant) classes should be retrieved (False).

  • only_named – Whether to only retrieve named sub-classes or also complex class expressions.

Returns:

If direct is True, each class C where reasoner axioms entails DirectSubClassOf(C, ce). If direct is False, each class C where reasoner axioms entails StrictSubClassOf(C, ce). If ce is equivalent to owl:Nothing then nothing will be returned.

sub_data_properties(dp: owlapy.owl_property.OWLDataProperty, direct: bool = False) Iterable[owlapy.owl_property.OWLDataProperty]

Gets the set of named data properties that are the strict (potentially direct) subproperties of the specified data property expression with respect to the imports closure of the root ontology.

Parameters:
  • dp – The data property whose strict (direct) subproperties are to be retrieved.

  • direct – Specifies if the direct subproperties should be retrieved (True) or if the all subproperties (descendants) should be retrieved (False).

Returns:

If direct is True, each property P where the set of reasoner axioms entails DirectSubDataPropertyOf(P, pe). If direct is False, each property P where the set of reasoner axioms entails StrictSubDataPropertyOf(P, pe). If pe is equivalent to owl:bottomDataProperty then nothing will be returned.

sub_object_properties(op: owlapy.owl_property.OWLObjectPropertyExpression, direct: bool = False) Iterable[owlapy.owl_property.OWLObjectPropertyExpression]

Gets the stream of simplified object property expressions that are the strict (potentially direct) subproperties of the specified object property expression with respect to the imports closure of the root ontology.

Parameters:
  • op – The object property expression whose strict (direct) subproperties are to be retrieved.

  • direct – Specifies if the direct subproperties should be retrieved (True) or if the all subproperties (descendants) should be retrieved (False).

Returns:

If direct is True, simplified object property expressions, such that for each simplified object property expression, P, the set of reasoner axioms entails DirectSubObjectPropertyOf(P, pe). If direct is False, simplified object property expressions, such that for each simplified object property expression, P, the set of reasoner axioms entails StrictSubObjectPropertyOf(P, pe). If pe is equivalent to owl:bottomObjectProperty then nothing will be returned.

abstract types(ind: owlapy.owl_individual.OWLNamedIndividual, direct: bool = False) Iterable[owlapy.class_expression.OWLClass]

Gets the named classes which are (potentially direct) types of the specified named individual.

Parameters:
  • ind – The individual whose types are to be retrieved.

  • direct – Specifies if the direct types should be retrieved (True), or if all types should be retrieved (False).

Returns:

If direct is True, each named class C where the set of reasoner axioms entails DirectClassAssertion(C, ind). If direct is False, each named class C where the set of reasoner axioms entails ClassAssertion(C, ind).

get_root_ontology() TentrisOntology

Gets the “root” ontology that is loaded into this reasoner. The reasoner takes into account the axioms in this ontology and its import’s closure.

abstract super_classes(ce: owlapy.class_expression.OWLClassExpression, direct: bool = False, only_named: bool = True) Iterable[owlapy.class_expression.OWLClassExpression]

Gets the stream of named classes that are the strict (potentially direct) super classes of the specified class expression with respect to the imports closure of the root ontology.

Parameters:
  • ce – The class expression whose strict (direct) super classes are to be retrieved.

  • direct – Specifies if the direct super classes should be retrieved (True) or if the all super classes (ancestors) classes should be retrieved (False).

  • only_named – Whether to only retrieve named super classes or also complex class expressions.

Returns:

If direct is True, each class C where the set of reasoner axioms entails DirectSubClassOf(ce, C). If direct is False, each class C where set of reasoner axioms entails StrictSubClassOf(ce, C). If ce is equivalent to owl:Thing then nothing will be returned.

class ontolearn.tentris.EvaluatedConceptTentris

Bases: ontolearn.search.EvaluatedConcept

Explicitly declare the attributes that should be returned by the evaluate_concept method of a KnowledgeBase.

This way, Python uses a more efficient way to store the instance attributes, which can significantly reduce the memory usage.

property inds
__slots__ = ()
class ontolearn.tentris.TentrisKnowledgeBase(path: str, *, length_metric_factory: ontolearn.utils.Factory[[], OWLClassExpressionLengthMetric] | None = None, length_metric: OWLClassExpressionLengthMetric | None = None, individuals_cache_size=128)

Bases: ontolearn.knowledge_base.KnowledgeBase

Representation of an OWL knowledge base in Ontolearn.

Parameters:
  • path – Path to an ontology file that is to be loaded.

  • ontologymanager_factory – Factory that creates an ontology manager to be used to load the file.

  • ontology – OWL ontology object.

  • reasoner_factory – Factory that creates a reasoner to reason about the ontology.

  • reasoner – reasoner Over the ontology.

  • length_metric_factory – See length_metric.

  • length_metric – Length metric that is used in calculation of class expression lengths.

  • individuals_cache_size – How many individuals of class expressions to cache.

  • backend_store – Whether to sync the world to backend store. reasoner of this object, if you enter a reasoner using :arg:`reasoner_factory` or :arg:`reasoner` argument it will override this setting.

  • include_implicit_individuals – Whether to identify and consider instances which are not set as OWL Named Individuals (does not contain this type) as individuals.

generator

Instance of concept generator.

Type:

ConceptGenerator

path

Path of the ontology file.

Type:

str

use_individuals_cache

Whether to use individuals cache to store individuals for method efficiency.

Type:

bool

__slots__ = ('endpoint_url', 'endpoint_timeout', 'async_client', 'tasks', '_total_req', '_current_req')
endpoint_url: str
endpoint_timeout: float
abstract encode_learning_problem(lp: AbstractLearningProblem)

@TODO: A learning problem (DL concept learning problem) should not be a part of a knowledge base

Provides the encoded learning problem (lp), i.e. the class containing the set of OWLNamedIndividuals as follows:

kb_pos –> the positive examples set, kb_neg –> the negative examples set, kb_all –> all lp individuals / all individuals set, kb_diff –> kb_all - (kb_pos + kb_neg).

Note

Simple access of the learning problem individuals divided in respective sets. You will need the encoded learning problem to use the method evaluate_concept of this class.

Parameters:

lp (PosNegLPStandard) – The learning problem.

Returns:

The encoded learning problem.

Return type:

EncodedPosNegLPStandard

evaluate_concept(concept: owlapy.class_expression.OWLClassExpression, quality_func: AbstractScorer, encoded_learning_problem: EncodedPosNegLPStandardTentris) EvaluatedConcept

Evaluates a concept by using the encoded learning problem examples, in terms of Accuracy or F1-score.

@ TODO: A knowledge base is a data structure and the context of “evaluating” a concept seems to be unrelated

Note

This method is useful to tell the quality (e.q) of a generated concept by the concept learners, to get the set of individuals (e.inds) that are classified by this concept and the amount of them (e.ic).

Parameters:
  • concept – The concept to be evaluated.

  • quality_func – Quality measurement in terms of Accuracy or F1-score.

  • encoded_learning_problem – The encoded learning problem.

Returns:

The evaluated concept.

async evaluate_concept_async(concept: owlapy.class_expression.OWLClassExpression, quality_func: AbstractScorer, encoded_learning_problem: EncodedPosNegLPStandardTentris) EvaluatedConcept