ontolearn.search
Node representation.
Classes
Simple node. |
|
OENode search tree node. |
|
EvoLearner search tree node. |
|
EvoLearner search tree node. |
|
Abstract search tree node. |
|
LBL search tree node. |
|
Abstract base class for generic types. |
|
A comparator that orders the Nodes based on Heuristic, then OrderedOWLObject of the concept |
|
QualityOrderedNode search tree node. |
|
Search tree based on priority queue. |
|
Simple search tree node. |
|
#@TODO Move to learners/drill.py |
|
Explicitly declare the attributes that should be returned by the evaluate_concept method of a KnowledgeBase. |
|
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')
- 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.
- property refinement_count: int
Get the refinement count for this node.
- Returns:
Refinement count.
- 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
- 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')
- 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
- 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')
- property children
- 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]
- 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]
- class ontolearn.search.QualityOrderedNode(node: OENode)[source]
QualityOrderedNode search tree node.
- __slots__ = 'node'
- 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
- 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
- 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]
- 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
- get_most_promising() RL_State [source]
Gets the current most promising node from Queue.
- Returns:
node
- Return type:
A node object
- 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')