ontolearn.abstracts

The main abstract classes.

Module Contents

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.

BaseRefinement

Base class for Refinement Operators.

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.

AbstractLearningProblem

Abstract learning problem.

LBLSearchTree

Abstract search tree for the Length based learner.

DepthAbstractDrill

Abstract class for Convolutional DQL concept learning.

DRILLAbstractTree

Abstract Tree for DRILL.

Attributes

logger

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.BaseRefinement(knowledge_base: _KB)[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: _KB
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.AbstractNode[source]

Abstract search tree node.

__slots__ = ()
__str__()[source]

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

__repr__()[source]

Return repr(self).

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.

abstract property quality: float | None

Get the quality of the node.

Returns:

Quality of the node.

abstract property h_exp: int

Get horizontal expansion.

Returns:

Horizontal expansion.

abstract property is_root: bool

Is this the root node?

Returns:

True if this is the root node, otherwise False.

abstract property parent_node: _N | None

Get the parent node.

Returns:

Parent node.

abstract property refinement_count: int

Get the refinement count for this node.

Returns:

Refinement count.

abstract property heuristic: float | None

Get the heuristic value.

Returns:

Heuristic value.

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

Abstract search tree node which has a concept.

abstract property concept: owlapy.class_expression.OWLClassExpression

Get the concept representing this node.

Returns:

The concept representing this node.

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

Abstract knowledge base.

__slots__ = ()
ontology() owlapy.owl_ontology.OWLOntology[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 clean() None[source]

This method should reset any caches and statistics in the knowledge base.

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 concept_len(ce: owlapy.class_expression.OWLClassExpression) int[source]

Calculate the length of a concept.

Parameters:

ce – The concept to measure the length for.

Returns:

Length of concept.

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.DepthAbstractDrill(path_of_embeddings, reward_func, learning_rate=None, num_episode=None, num_episodes_per_replay=None, epsilon=None, num_of_sequential_actions=None, max_len_replay_memory=None, representation_mode=None, batch_size=None, epsilon_decay=None, epsilon_min=None, num_epochs_per_replay=None, num_workers=None, verbose=0)[source]

Abstract class for Convolutional DQL concept learning.

attributes_sanity_checking_rl()[source]
abstract init_training(*args, **kwargs)[source]

Initialize training for a given E+,E- and K.

abstract terminate_training()[source]

Save weights and training data after training phase.

class ontolearn.abstracts.DRILLAbstractTree[source]

Abstract Tree for DRILL.

property nodes
__len__()[source]
__getitem__(item)[source]
__setitem__(k, v)[source]
__iter__()[source]
get_top_n_nodes(n: int, key='quality')[source]
redundancy_check(n)[source]
abstract add(*args, **kwargs)[source]
sort_search_tree_by_decreasing_order(*, key: str)[source]
best_hypotheses(n=10) List[source]
show_search_tree(th, top_n=10)[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]