1414from owlapy .owl_datatype import OWLDatatype
1515from owlapy .owl_individual import OWLNamedIndividual
1616from owlapy .owl_literal import BooleanOWLDatatype , NUMERIC_DATATYPES , DoubleOWLDatatype , TIME_DATATYPES , OWLLiteral
17- from owlapy .owl_ontology import OWLOntology
18- from owlapy .owl_ontology_manager import OWLOntologyManager
1917from owlapy .owl_property import OWLObjectProperty , OWLDataProperty , OWLObjectPropertyExpression , \
2018 OWLDataPropertyExpression
21- from owlapy .owl_reasoner import OWLReasoner
2219
2320from owlapy .owl_ontology import Ontology
2421from owlapy .owl_ontology_manager import OntologyManager
25- from owlapy .owl_reasoner import FastInstanceCheckerReasoner , OntologyReasoner
22+ from owlapy .owl_reasoner import StructuralReasoner
2623
2724from owlapy .render import DLSyntaxObjectRenderer
2825from ontolearn_light .search import EvaluatedConcept
3532from .utils .static_funcs import (init_length_metric , init_hierarchy_instances ,
3633 init_named_individuals , init_individuals_from_concepts )
3734
38- from owlapy .class_expression import OWLDataMaxCardinality , OWLDataSomeValuesFrom
39- from owlapy import owl_expression_to_sparql , owl_expression_to_dl
35+ from owlapy .class_expression import OWLDataSomeValuesFrom
4036from owlapy .owl_data_ranges import OWLDataRange
4137from owlapy .class_expression import OWLDataOneOf
4238
4339logger = logging .getLogger (__name__ )
4440
4541
46- def depth_Default_ReasonerFactory (onto : OWLOntology ) -> OWLReasoner :
42+ def depth_Default_ReasonerFactory (onto : Ontology ) -> StructuralReasoner :
4743 assert isinstance (onto , Ontology )
48- base_reasoner = OntologyReasoner (ontology = onto )
49- return FastInstanceCheckerReasoner (ontology = onto , base_reasoner = base_reasoner )
44+ return StructuralReasoner (ontology = onto , class_cache = False , property_cache = False )
5045
5146
5247class KnowledgeBase (AbstractKnowledgeBase ):
@@ -89,9 +84,9 @@ class KnowledgeBase(AbstractKnowledgeBase):
8984 @overload
9085 def __init__ (self , * ,
9186 path : str ,
92- ontologymanager_factory : Callable [[], OWLOntologyManager ] = OntologyManager (
87+ ontologymanager_factory : Callable [[], OntologyManager ] = OntologyManager (
9388 world_store = None ),
94- reasoner_factory : Callable [[OWLOntology ], OWLReasoner ] = None ,
89+ reasoner_factory : Callable [[Ontology ], StructuralReasoner ] = None ,
9590 length_metric : Optional [OWLClassExpressionLengthMetric ] = None ,
9691 length_metric_factory : Optional [Callable [[], OWLClassExpressionLengthMetric ]] = None ,
9792 individuals_cache_size = 128 ,
@@ -101,8 +96,8 @@ def __init__(self, *,
10196
10297 @overload
10398 def __init__ (self , * ,
104- ontology : OWLOntology ,
105- reasoner : OWLReasoner ,
99+ ontology : Ontology ,
100+ reasoner : StructuralReasoner ,
106101 load_class_hierarchy : bool = True ,
107102 length_metric : Optional [OWLClassExpressionLengthMetric ] = None ,
108103 length_metric_factory : Optional [Callable [[], OWLClassExpressionLengthMetric ]] = None ,
@@ -112,12 +107,12 @@ def __init__(self, *,
112107 def __init__ (self , * ,
113108 path : Optional [str ] = None ,
114109
115- ontologymanager_factory : Optional [Callable [[], OWLOntologyManager ]] = None ,
116- reasoner_factory : Optional [Callable [[OWLOntology ], OWLReasoner ]] = None ,
110+ ontologymanager_factory : Optional [Callable [[], OntologyManager ]] = None ,
111+ reasoner_factory : Optional [Callable [[Ontology ], StructuralReasoner ]] = None ,
117112 length_metric_factory : Optional [Callable [[], OWLClassExpressionLengthMetric ]] = None ,
118113
119- ontology : Optional [OWLOntology ] = None ,
120- reasoner : Optional [OWLReasoner ] = None ,
114+ ontology : Optional [Ontology ] = None ,
115+ reasoner : Optional [StructuralReasoner ] = None ,
121116 length_metric : Optional [OWLClassExpressionLengthMetric ] = None ,
122117
123118 individuals_cache_size = 128 ,
@@ -152,14 +147,13 @@ def __init__(self, *,
152147 self .manager .save_world ()
153148 logger .debug ("Synced world to backend store" )
154149
155- reasoner : OWLReasoner
150+ reasoner : StructuralReasoner
156151 if reasoner is not None :
157152 self .reasoner = reasoner
158153 elif reasoner_factory is not None :
159154 self .reasoner = reasoner_factory (self .ontology )
160155 else :
161- self .reasoner = FastInstanceCheckerReasoner (ontology = self .ontology , base_reasoner = OntologyReasoner (
162- ontology = self .ontology ))
156+ self .reasoner = StructuralReasoner (ontology = self .ontology , class_cache = False , property_cache = False )
163157
164158 self .length_metric = init_length_metric (length_metric , length_metric_factory )
165159
@@ -317,7 +311,6 @@ def tbox(self, entities: Union[Iterable[OWLClass], Iterable[OWLDataProperty], It
317311 If no concept-s|propert-y/ies are given, get all tbox axioms.
318312
319313 Args:
320- @TODO: entities or namedindividuals ?!
321314 entities: Entities to obtain tbox axioms from. This can be a single
322315 OWLClass/OWLDataProperty/OWLObjectProperty object, a list of those objects or None. If you enter a list
323316 that combines classes and properties (which we don't recommend doing), only axioms for one type will be
@@ -525,8 +518,6 @@ def concept_len(self, ce: OWLClassExpression) -> int:
525518 Returns:
526519 Length of the concept.
527520 """
528- # @TODO: CD: Computing the length of a concept should be disantangled from KB
529- # @TODO: CD: Ideally, this should be a static function
530521
531522 return self .length_metric .length (ce )
532523
@@ -550,7 +541,7 @@ def cache_individuals(self, ce: OWLClassExpression) -> None:
550541 raise TypeError
551542 if ce in self .ind_cache :
552543 return
553- if isinstance (self .reasoner , FastInstanceCheckerReasoner ):
544+ if isinstance (self .reasoner , StructuralReasoner ):
554545 self .ind_cache [ce ] = self .reasoner ._find_instances (ce ) # performance hack
555546 else :
556547 temp = self .reasoner .instances (ce )
@@ -666,8 +657,6 @@ def data_properties_for_domain(self, domain: OWLClassExpression, data_properties
666657
667658 def encode_learning_problem (self , lp : PosNegLPStandard ):
668659 """
669- @TODO: A learning problem (DL concept learning problem) should not be a part of a knowledge base
670-
671660 Provides the encoded learning problem (lp), i.e. the class containing the set of OWLNamedIndividuals
672661 as follows:
673662 kb_pos --> the positive examples set,
@@ -720,8 +709,6 @@ def evaluate_concept(self, concept: OWLClassExpression, quality_func: AbstractSc
720709 encoded_learning_problem : EncodedLearningProblem ) -> EvaluatedConcept :
721710 """Evaluates a concept by using the encoded learning problem examples, in terms of Accuracy or F1-score.
722711
723- @ TODO: A knowledge base is a data structure and the context of "evaluating" a concept seems to be unrelated
724-
725712 Note:
726713 This method is useful to tell the quality (e.q) of a generated concept by the concept learners, to get
727714 the set of individuals (e.inds) that are classified by this concept and the amount of them (e.ic).
@@ -752,22 +739,16 @@ def get_leaf_concepts(self, concept: OWLClass):
752739
753740 def get_least_general_named_concepts (self ) -> Generator [OWLClass , None , None ]:
754741 """Get leaf classes.
755- @TODO: Docstring needed
756- Returns:
757742 """
758743 yield from self .class_hierarchy .leaves ()
759744
760745 def least_general_named_concepts (self ) -> Generator [OWLClass , None , None ]:
761746 """Get leaf classes.
762- @TODO: Docstring needed
763- Returns:
764747 """
765748 yield from self .class_hierarchy .leaves ()
766749
767750 def get_most_general_classes (self ) -> Generator [OWLClass , None , None ]:
768- """Get most general named concepts classes.
769- @TODO: Docstring needed
770- Returns:"""
751+ """Get most general named concepts classes."""
771752 yield from self .class_hierarchy .roots ()
772753
773754 def get_direct_sub_concepts (self , concept : OWLClass ) -> Iterable [OWLClass ]:
0 commit comments