ontolearn.search

Node representation.

Classes

Node

Simple node.

OENode

OENode search tree node.

EvoLearnerNode

EvoLearner search tree node.

NCESNode

EvoLearner search tree node.

RL_State

Abstract search tree node.

LBLNode

LBL search tree node.

LengthOrderedNode

Abstract base class for generic types.

HeuristicOrderedNode

A comparator that orders the Nodes based on Heuristic, then OrderedOWLObject of the concept

QualityOrderedNode

QualityOrderedNode search tree node.

SearchTreePriorityQueue

Search tree based on priority queue.

TreeNode

Simple search tree node.

DRILLSearchTreePriorityQueue

#@TODO Move to learners/drill.py

EvaluatedConcept

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

SuperProp

Super wrapper which allows property setting & deletion. Super can't be subclassed with empty __init__ arguments.

Module Contents

class ontolearn.search.Node(concept: owlapy.class_expression.OWLClassExpression, length: int)[source]

Bases: _NodeConcept, _NodeLen, _NodeIndividualsCount, ontolearn.abstracts.AbstractNode

Simple node.

__slots__ = ('_concept', '_len', '_individuals_count')
__str__()[source]

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

class ontolearn.search.OENode(concept: owlapy.class_expression.OWLClassExpression, length: int, parent_node: OENode | None = None, is_root: bool = False)[source]

Bases: _NodeConcept, _NodeLen, _NodeIndividualsCount, _NodeQuality, _NodeHeuristic, _NodeParentRef[OENode], ontolearn.abstracts.AbstractNode, ontolearn.abstracts.AbstractConceptNode, ontolearn.abstracts.AbstractOEHeuristicNode

OENode search tree node.

__slots__ = ('_concept', '_len', '_individuals_count', '_quality', '_heuristic', '_parent_ref',...
renderer: ClassVar[owlapy.owl_object.OWLObjectRenderer]
property h_exp: int

Get horizontal expansion.

Returns:

Horizontal expansion.

increment_h_exp()[source]
property refinement_count: int

Get the refinement count for this node.

Returns:

Refinement count.

__str__()[source]

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

class ontolearn.search.EvoLearnerNode(concept: owlapy.class_expression.OWLClassExpression, length: int, individuals_count: int, quality: float, tree_length: int, tree_depth: int)[source]

Bases: _NodeConcept, _NodeLen, _NodeIndividualsCount, _NodeQuality, ontolearn.abstracts.AbstractNode, ontolearn.abstracts.AbstractConceptNode

EvoLearner search tree node.

__slots__ = ('_concept', '_len', '_individuals_count', '_quality', '_tree_length', '_tree_depth')
property tree_length
property tree_depth
__str__()[source]

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

class ontolearn.search.NCESNode(concept: owlapy.class_expression.OWLClassExpression, length: int, individuals_count: int, quality: float)[source]

Bases: _NodeConcept, _NodeLen, _NodeIndividualsCount, _NodeQuality, ontolearn.abstracts.AbstractNode, ontolearn.abstracts.AbstractConceptNode

EvoLearner search tree node.

__slots__ = ('_concept', '_len', '_individuals_count', '_quality')
__str__()[source]

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

class ontolearn.search.RL_State(concept: owlapy.class_expression.OWLClassExpression, parent_node: RL_State | None = None, embeddings=None, is_root: bool = False, length=None)[source]

Bases: _NodeConcept, _NodeQuality, _NodeHeuristic, ontolearn.abstracts.AbstractNode, _NodeParentRef[RL_State]

Abstract search tree node.

renderer: ClassVar[owlapy.owl_object.OWLObjectRenderer]

RL_State node.

__slots__ = ('_concept', 'embeddings', '_quality', '_heuristic', 'length', 'parent_node', 'is_root',...
parent_node
is_root
length
embeddings
__str__()[source]

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

__lt__(other)[source]
__gt__(other)[source]
class ontolearn.search.LBLNode(concept: owlapy.class_expression.OWLClassExpression, length: int, individuals, parent_node: LBLNode | None = None, is_root: bool = False)[source]

Bases: _NodeIndividuals, OENode

LBL search tree node.

__slots__ = ('_children', '_individuals')
add_child(n)[source]
remove_child(n)[source]
property children
property parent_node: LBLNode | None

Get the parent node.

Returns:

Parent node.

class ontolearn.search.LengthOrderedNode(node: _N, length: int)[source]

Bases: Generic[_N]

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default
__slots__ = ('node', 'len')
node: Final[_N]
len: Final[int]
__lt__(other)[source]
__eq__(other)[source]
class ontolearn.search.HeuristicOrderedNode(node: _N)[source]

Bases: Generic[_N]

A comparator that orders the Nodes based on Heuristic, then OrderedOWLObject of the concept

__slots__ = 'node'
node: Final[_N]
__lt__(other: _N)[source]
__eq__(other: _N)[source]
class ontolearn.search.QualityOrderedNode(node: OENode)[source]

QualityOrderedNode search tree node.

__slots__ = 'node'
node: Final[OENode]
__lt__(other)[source]
__eq__(other)[source]
class ontolearn.search.SearchTreePriorityQueue(quality_func, heuristic_func)[source]

Bases: ontolearn.abstracts.LBLSearchTree[LBLNode]

Search tree based on priority queue.

Parameters:
  • quality_func – An instance of a subclass of AbstractScorer that measures the quality of a node.

  • heuristic_func – An instance of a subclass of AbstractScorer that measures the promise of a node.

quality_func

An instance of a subclass of AbstractScorer that measures the quality of a node.

heuristic_func

An instance of a subclass of AbstractScorer that measures the promise of a node.

items_in_queue

An instance of PriorityQueue Class.

.nodes

A dictionary where keys are string representation of nodes and values are corresponding node objects.

nodes

A property method for ._nodes.

expressionTests

not being used .

str_to_obj_instance_mapping

not being used.

quality_func: AbstractScorer
heuristic_func: AbstractHeuristic
nodes: Dict[owlapy.class_expression.OWLClassExpression, LBLNode]
items_in_queue: PriorityQueue[Tuple[float, HeuristicOrderedNode[LBLNode]]]
add(n: LBLNode)[source]

Append a node into the search tree.

Parameters:

n – A Node object

Returns:

None

add_root(node, kb_learning_problem)[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.

add_node(*, node: LBLNode, parent_node: LBLNode, kb_learning_problem: EncodedLearningProblem) bool | None[source]

Add a node into the search tree after calculating heuristic value given its parent.

Parameters:
  • node – A Node object

  • parent_node – A Node object

  • kb_learning_problem – the encoded learning problem to compare the quality on

Returns:

True if node is a “goal node”, i.e. quality_metric(node)=1.0 False if node is a “weak node”, i.e. quality_metric(node)=0.0 None otherwise

Notes

node is a refinement of refined_node

get_most_promising() LBLNode[source]

Gets the current most promising node from Queue.

Returns:

A node object

Return type:

node

get_top_n(n: int, key='quality') List[LBLNode][source]

Gets the top n nodes determined by key from the search tree.

Returns:

A list of node objects

Return type:

top_n_predictions

clean()[source]

Reset the search tree state.

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.

class ontolearn.search.TreeNode(node: _N, parent_tree_node: _TN | None = None, is_root: bool = False)[source]

Bases: Generic[_N]

Simple search tree node.

__slots__ = ('children', 'node')
node: Final[_N]
children: Set[TreeNode[_N]]
class ontolearn.search.DRILLSearchTreePriorityQueue(verbose)[source]

Bases: ontolearn.abstracts.DRILLAbstractTree

#@TODO Move to learners/drill.py

Search tree based on priority queue.

Parameters:
  • quality_func (An instance of a subclass of AbstractScorer that measures the quality of a node.)

  • heuristic_func (An instance of a subclass of AbstractScorer that measures the promise of a node.)

quality_func
Type:

An instance of a subclass of AbstractScorer that measures the quality of a node.

heuristic_func
Type:

An instance of a subclass of AbstractScorer that measures the promise of a node.

items_in_queue
Type:

An instance of PriorityQueue Class.

.nodes
Type:

A dictionary where keys are string representation of nodes and values are corresponding node objects.

nodes
Type:

A property method for ._nodes.

expressionTests
Type:

not being used .

str_to_obj_instance_mapping
Type:

not being used.

verbose
items_in_queue
add(node: RL_State)[source]

Append a node into the search tree. :param node: :type node: A RL_State object

Return type:

None

show_current_search_tree(top_n=10)[source]

Show search tree.

get_most_promising() RL_State[source]

Gets the current most promising node from Queue.

Returns:

node

Return type:

A node object

get_top_n(n: int, key='quality') List[Node][source]

Gets the top n nodes determined by key from the search tree.

Returns:

top_n_predictions

Return type:

A list of node objects

clean()[source]
class ontolearn.search.EvaluatedConcept[source]

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.

__slots__ = ('q', 'inds', 'ic')
class ontolearn.search.SuperProp(super_obj)[source]

Super wrapper which allows property setting & deletion. Super can’t be subclassed with empty __init__ arguments.

__getattr__(name)[source]
__setattr__(name, value)[source]
__delattr__(name)[source]