ontolearn.abstracts

The main abstract classes.

Attributes

logger

Classes

EncodedLearningProblem

Encoded Abstract learning problem for use in Scorers.

EncodedPosNegLPStandardKind

Encoded Abstract learning problem following pos-neg lp standard.

AbstractScorer

An abstract class for quality functions.

AbstractHeuristic

Abstract base class for heuristic functions.

AbstractFitness

Abstract base class for fitness functions.

AbstractNode

Abstract search tree node.

AbstractOEHeuristicNode

Abstract Node for the CELOEHeuristic heuristic function.

AbstractConceptNode

Abstract search tree node which has a concept.

AbstractKnowledgeBase

Abstract knowledge base.

BaseRefinement

Base class for Refinement Operators.

AbstractLearningProblem

Abstract learning problem.

LBLSearchTree

Abstract search tree for the Length based learner.

DRILLAbstractTree

Abstract Tree for DRILL.

Module Contents

ontolearn.abstracts.logger
class ontolearn.abstracts.EncodedLearningProblem[source]

Encoded Abstract learning problem for use in Scorers.

__slots__ = ()
class ontolearn.abstracts.EncodedPosNegLPStandardKind[source]

Bases: EncodedLearningProblem

Encoded Abstract learning problem following pos-neg lp standard.

__slots__ = ()
class ontolearn.abstracts.AbstractScorer(*args, **kwargs)[source]

Bases: Generic[_N]

An abstract class for quality functions.

__slots__ = ()
name: ClassVar[str]
score_elp(instances: set, learning_problem: EncodedLearningProblem) Tuple[bool, float | None][source]

Quality score for a set of instances with regard to the learning problem.

Parameters:
  • instances (set) – Instances to calculate a quality score for.

  • learning_problem – Underlying learning problem to compare the quality to.

Returns:

Tuple, first position indicating if the function could be applied, second position the quality value

in the range 0.0–1.0.

abstract score2(tp: int, fn: int, fp: int, tn: int) Tuple[bool, float | None][source]

Quality score for a coverage count.

Parameters:
  • tp – True positive count.

  • fn – False negative count.

  • fp – False positive count.

  • tn – True negative count.

Returns:

Tuple, first position indicating if the function could be applied, second position the quality value

in the range 0.0–1.0.

apply(node: AbstractNode, instances, learning_problem: EncodedLearningProblem) bool[source]

Apply the quality function to a search tree node after calculating the quality score on the given instances.

Parameters:
  • node – search tree node to set the quality on.

  • instances (set) – Instances to calculate the quality for.

  • learning_problem – Underlying learning problem to compare the quality to.

Returns:

True if the quality function was applied successfully

class ontolearn.abstracts.AbstractHeuristic[source]

Bases: Generic[_N]

Abstract base class for heuristic functions.

Heuristic functions can guide the search process.

__slots__ = ()
abstract apply(node: _N, instances, learning_problem: EncodedLearningProblem)[source]

Apply the heuristic on a search tree node and set its heuristic property to the calculated value.

Parameters:
  • node – Node to set the heuristic on.

  • instances (set, optional) – Set of instances covered by this node.

  • learning_problem – Underlying learning problem to compare the heuristic to.

class ontolearn.abstracts.AbstractFitness[source]

Abstract base class for fitness functions.

Fitness functions guide the evolutionary process.

__slots__ = ()
name: ClassVar[str]
abstract apply(individual)[source]

Apply the fitness function on an individual and set its fitness attribute to the calculated value.

Parameters:

individual – Individual to set the fitness on.

class ontolearn.abstracts.AbstractNode[source]

Abstract search tree node.

__slots__ = ()
__str__()[source]

String representation of node, by default its internal memory address.

__repr__()[source]
class ontolearn.abstracts.AbstractOEHeuristicNode[source]

Abstract Node for the CELOEHeuristic heuristic function.

This node must support quality, horizontal expansion (h_exp), is_root, parent_node and refinement_count.

__slots__ = ()
property quality: float | None
Abstractmethod:

Get the quality of the node.

Returns:

Quality of the node.

property h_exp: int
Abstractmethod:

Get horizontal expansion.

Returns:

Horizontal expansion.

property is_root: bool
Abstractmethod:

Is this the root node?

Returns:

True if this is the root node, otherwise False.

property parent_node: _N | None
Abstractmethod:

Get the parent node.

Returns:

Parent node.

property refinement_count: int
Abstractmethod:

Get the refinement count for this node.

Returns:

Refinement count.

property heuristic: float | None
Abstractmethod:

Get the heuristic value.

Returns:

Heuristic value.

class ontolearn.abstracts.AbstractConceptNode[source]

Abstract search tree node which has a concept.

__slots__ = ()
property concept: owlapy.class_expression.OWLClassExpression
Abstractmethod:

Get the concept representing this node.

Returns:

The concept representing this node.

class ontolearn.abstracts.AbstractKnowledgeBase[source]

Abstract knowledge base.

__slots__ = ()
ontology() owlapy.abstracts.AbstractOWLOntology[source]

The base ontology of this knowledge base.

describe() None[source]

Print a short description of the Knowledge Base to the info logger output.

abstract individuals_count() int[source]

Total number of individuals in this knowledge base.

abstract individuals_set(*args, **kwargs) Set[source]

Encode an individual, an iterable of individuals or the individuals that are instances of a given concept into a set.

Parameters:
  • arg (OWLClassExpression) – Individual to encode.

  • arg – Individuals to encode.

  • arg – Encode individuals that are instances of this concept.

Returns:

Encoded set representation of individual(s).

abstract individuals(concept: owlapy.class_expression.OWLClassExpression | None = None, named_individuals: bool = False) Iterable[owlapy.owl_individual.OWLNamedIndividual][source]
abstract abox(*args, **kwargs)[source]
abstract tbox(*args, **kwargs)[source]
abstract triples(*args, **kwargs)[source]
abstract most_general_object_properties(*args, **kwargs)[source]
abstract data_properties_for_domain(*args, **kwargs)[source]
abstract least_general_named_concepts(*args, **kwargs)[source]
abstract most_general_classes(*args, **kwargs)[source]
abstract get_object_property_domains(*args, **kwargs)[source]
abstract get_object_property_ranges(*args, **kwargs)[source]
abstract get_data_property_domains(*args, **kwargs)[source]
abstract get_data_property_ranges(*args, **kwargs)[source]
abstract most_general_data_properties(*args, **kwargs)[source]
abstract most_general_boolean_data_properties(*args, **kwargs)[source]
abstract most_general_numeric_data_properties(*args, **kwargs)[source]
abstract most_general_time_data_properties(*args, **kwargs)[source]
abstract most_general_existential_restrictions(*args, **kwargs)[source]
abstract most_general_universal_restrictions(*args, **kwargs)[source]
abstract most_general_existential_restrictions_inverse(*args, **kwargs)[source]
abstract most_general_universal_restrictions_inverse(*args, **kwargs)[source]
abstract get_direct_parents(*args, **kwargs)[source]
abstract get_all_direct_sub_concepts(*args, **kwargs)[source]
abstract get_all_sub_concepts(*args, **kwargs)[source]
abstract get_concepts(*args, **kwargs)[source]
abstract property concepts
abstract property object_properties
abstract property data_properties
abstract get_object_properties(*args, **kwargs)[source]
abstract get_data_properties(*args, **kwargs)[source]
abstract get_boolean_data_properties(*args, **kwargs)[source]
abstract get_numeric_data_properties(*args, **kwargs)[source]
abstract get_double_data_properties(*args, **kwargs)[source]
abstract get_time_data_properties(*args, **kwargs)[source]
abstract get_types(*args, **kwargs)[source]
abstract get_object_properties_for_ind(*args, **kwargs)[source]
abstract get_data_properties_for_ind(*args, **kwargs)[source]
abstract get_object_property_values(*args, **kwargs)[source]
abstract get_data_property_values(*args, **kwargs)[source]
abstract contains_class(*args, **kwargs)[source]
abstract are_owl_concept_disjoint(*args, **kwargs)[source]
class ontolearn.abstracts.BaseRefinement(knowledge_base: AbstractKnowledgeBase)[source]

Bases: Generic[_N]

Base class for Refinement Operators.

Let C, D in N_c where N_c os a finite set of concepts.

  • Proposition 3.3 (Complete and Finite Refinement Operators) [1] * ρ(C) = {C ⊓ T} ∪ {D | D is not empty AND D sqset C}

    • The operator is finite,

    • The operator is complete as given a concept C, we can reach an arbitrary concept D such that D subset of C.

*) Theoretical Foundations of Refinement Operators [1].

*) Defining a top-down refimenent operator that is a proper is crutial.

4.1.3 Achieving Properness [1]

*) Figure 4.1 [1] defines of the refinement operator.

[1] Learning OWL Class Expressions.

kb

The knowledge base used by this refinement operator.

Type:

AbstractKnowledgeBase

__slots__ = 'kb'
kb: AbstractKnowledgeBase
abstract refine(*args, **kwargs) Iterable[owlapy.class_expression.OWLClassExpression][source]

Refine a given concept.

Parameters:

ce (OWLClassExpression) – Concept to refine.

Returns:

New refined concepts.

len(concept: owlapy.class_expression.OWLClassExpression) int[source]

The length of a concept.

Parameters:

concept – The concept to measure the length for.

Returns:

Length of concept according to some metric configured in the knowledge base.

class ontolearn.abstracts.AbstractLearningProblem(*args, **kwargs)[source]

Abstract learning problem.

__slots__ = ()
abstract encode_kb(knowledge_base: AbstractKnowledgeBase) EncodedLearningProblem[source]

Encode the learning problem into the knowledge base.

class ontolearn.abstracts.LBLSearchTree[source]

Bases: Generic[_N]

Abstract search tree for the Length based learner.

abstract get_most_promising() _N[source]

Find most “promising” node in the search tree that should be refined next.

Returns:

Most promising search tree node.

abstract add_node(node: _N, parent_node: _N, kb_learning_problem: EncodedLearningProblem)[source]

Add a node to the search tree.

Parameters:
  • node – Node to add.

  • parent_node – Parent of that node.

  • kb_learning_problem – Underlying learning problem to compare the quality to.

abstract clean()[source]

Reset the search tree state.

abstract get_top_n(n: int) List[_N][source]

Retrieve the best n search tree nodes.

Parameters:

n – Maximum number of nodes.

Returns:

List of top n search tree nodes.

abstract show_search_tree(root_concept: owlapy.class_expression.OWLClassExpression, heading_step: str)[source]

Debugging function to print the search tree to standard output.

Parameters:
  • root_concept – The tree is printed starting from this search tree node.

  • heading_step – Message to print at top of the output.

abstract add_root(node: _N, kb_learning_problem: EncodedLearningProblem)[source]

Add the root node to the search tree.

Parameters:
  • node – Root node to add.

  • kb_learning_problem – Underlying learning problem to compare the quality to.

class ontolearn.abstracts.DRILLAbstractTree[source]

Abstract Tree for DRILL.

__len__()[source]
__getitem__(item)[source]
__setitem__(k, v)[source]
__iter__()[source]
get_top_n_nodes(n: int, key='quality')[source]
redundancy_check(n)[source]
property nodes
abstract add(*args, **kwargs)[source]
sort_search_tree_by_decreasing_order(*, key: str)[source]
best_hypotheses(n=10) List[source]
show_search_tree(top_n=100)[source]

Show search tree.

show_best_nodes(top_n, key=None)[source]
static save_current_top_n_nodes(key=None, n=10, path=None)[source]

Save current top_n nodes.

clean()[source]