Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alkidbaci committed Oct 31, 2024
1 parent a9ccaac commit 297f8d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/usage/reasoner.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ onto = manager.load_ontology(IRI.create("KGs/Family/father.owl"))
In our Owlapy library, we provide two main reasoner classes:


- [**StructuralReasoner**](owlapy.owl_reasoner.FastInstanceCheckerReasoner) (What used to be FastInstanceCheckerReasoner )
- [**StructuralReasoner**](owlapy.owl_reasoner.StructuralReasoner) (What used to be FastInstanceCheckerReasoner )

Structural Reasoner is the base reasoner in Owlapy. This reasoner works
under CWA/PCWA and the base library used for it is _owlready2_. The functionalities
Expand Down
8 changes: 4 additions & 4 deletions owlapy/owl_reasoner.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self, ontology: AbstractOWLOntology, *, class_cache: bool = True,
property_cache: Whether to cache property values.
negation_default: Whether to assume a missing fact means it is false ("closed world view").
sub_properties: Whether to take sub properties into account for the
:func:`OWLReasoner_FastInstanceChecker.instances` retrieval.
:func:`StructuralReasoner.instances` retrieval.
"""
super().__init__(ontology)
assert isinstance(ontology, Ontology)
Expand Down Expand Up @@ -692,7 +692,7 @@ def _find_some_values(self, pe: OWLObjectPropertyExpression, filler_inds: Set[OW
min_count: int = 1, max_count: Optional[int] = None) -> FrozenSet[OWLNamedIndividual]:
"""Get all individuals that have one of filler_inds as their object property value."""
ret = set()
if self._ontology.is_modified:
if self._ontology.is_modified and (self.class_cache or self._property_cache):
self.reset_and_disable_cache()
if self._property_cache:
self._lazy_cache_obj_prop(pe)
Expand Down Expand Up @@ -764,7 +764,7 @@ def _find_instances(self, ce: OWLClassExpression) -> FrozenSet[OWLNamedIndividua

@_find_instances.register
def _(self, c: OWLClass) -> FrozenSet[OWLNamedIndividual]:
if self._ontology.is_modified:
if self._ontology.is_modified and (self.class_cache or self._property_cache):
self.reset_and_disable_cache()
if self.class_cache:
self._lazy_cache_class(c)
Expand Down Expand Up @@ -883,7 +883,7 @@ def _(self, ce: OWLDataSomeValuesFrom) -> FrozenSet[OWLNamedIndividual]:
filler = ce.get_filler()
assert isinstance(pe, OWLDataProperty)

if self._ontology.is_modified:
if self._ontology.is_modified and (self.class_cache or self._property_cache):
self.reset_and_disable_cache()
property_cache = self._property_cache

Expand Down
6 changes: 6 additions & 0 deletions tests/test_owlapy_structural_reasoner.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ def test_sub_property_inclusion(self):

# sub_property = True
reasoner = StructuralReasoner(onto, sub_properties=True)
reasoner._ontology.is_modified = False # This is done because, for sub_properties to work as expected it needs
# _property_cache of the reasoner to be True which would normally be
# False when the ontology is modified. Info: Cache needs to be reset and
# disabled when ontolgy modification is detected because the
# cached facts may not hold anymore. Hence, setting is_modified to False
# is an excepton to check this test.

# object property
ce = OWLObjectIntersectionOf([compound, OWLObjectSomeValuesFrom(super_has_structure, benzene)])
Expand Down

0 comments on commit 297f8d9

Please sign in to comment.