Skip to content

Commit

Permalink
Fixing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
alkidbaci committed Aug 9, 2023
1 parent af14fbb commit 6a87e73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions owlapy/owlready2/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,14 @@ def all_data_property_values(self, pe: OWLDataProperty, direct: bool = True) ->
for _, val in relations:
yield OWLLiteral(val)

def object_property_values(self, ind: OWLNamedIndividual, pe: OWLObjectPropertyExpression, direct: bool = True) \
def object_property_values(self, ind: OWLNamedIndividual, pe: OWLObjectPropertyExpression, direct: bool = False) \
-> Iterable[OWLNamedIndividual]:
if isinstance(pe, OWLObjectProperty):
i: owlready2.Thing = self._world[ind.get_iri().as_str()]
p: owlready2.ObjectPropertyClass = self._world[pe.get_iri().as_str()]
# should always get indirect values because _get_values_for_individual does not give consistent result
# Recommended to use direct=False because _get_values_for_individual does not give consistent result
# for the case when there are equivalent object properties. At least until this is fixed on owlready2.
retieval_func = p._get_indirect_values_for_individual
retieval_func = p._get_values_for_individual if direct else p._get_indirect_values_for_individual
for val in retieval_func(i):
yield OWLNamedIndividual(IRI.create(val.iri))
elif isinstance(pe, OWLObjectInverseOf):
Expand Down
23 changes: 15 additions & 8 deletions tests/test_owlapy_owlready2.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ def test_add_remove_axiom(self):
sister = OWLClass(IRI(ns, 'sister'))
person = OWLClass(IRI(ns, 'person'))
person_sibling = OWLClass(IRI(ns, 'PersonWithASibling'))
animal = OWLClass(IRI(ns, 'animal'))
aerial_animal = OWLClass(IRI(ns, 'aerialAnimal'))

self.assertNotIn(sister, list(onto.classes_in_signature()))
mgr.add_axiom(onto, OWLClassAssertionAxiom(anna, sister))
Expand Down Expand Up @@ -462,9 +464,14 @@ def test_add_remove_axiom(self):
self.assertNotIn(OWLLiteral(31), list(reasoner.data_property_values(anna, age)))

self.assertNotIn(brother, list(onto.classes_in_signature()))
self.assertNotIn(animal, list(onto.classes_in_signature()))
self.assertNotIn(aerial_animal, list(onto.classes_in_signature()))
mgr.add_axiom(onto, OWLSubClassOfAxiom(brother, male))
mgr.add_axiom(onto, OWLSubClassOfAxiom(aerial_animal, animal))
self.assertIn(brother, list(reasoner.sub_classes(male)))
self.assertIn(aerial_animal, list(reasoner.sub_classes(animal)))
self.assertIn(male, list(reasoner.super_classes(brother)))
self.assertIn(animal, list(reasoner.super_classes(aerial_animal)))
mgr.remove_axiom(onto, OWLSubClassOfAxiom(brother, male))
self.assertNotIn(brother, list(reasoner.sub_classes(male)))
self.assertNotIn(male, list(reasoner.super_classes(brother)))
Expand Down Expand Up @@ -528,15 +535,15 @@ def test_add_remove_axiom(self):
self.assertFalse(set(reasoner.same_individuals(markus)))

self.assertFalse(list(reasoner.disjoint_classes(brother)))
self.assertFalse(list(reasoner.disjoint_classes(sister)))
mgr.add_axiom(onto, OWLDisjointClassesAxiom([brother, male]))
mgr.add_axiom(onto, OWLDisjointClassesAxiom([brother, sister, person]))
self.assertEqual(set([male, sister, person]), set(reasoner.disjoint_classes(brother)))
self.assertEqual(set([brother, person]), set(reasoner.disjoint_classes(sister)))
mgr.remove_axiom(onto, OWLDisjointClassesAxiom([brother, male]))
mgr.remove_axiom(onto, OWLDisjointClassesAxiom([brother, sister, person]))
self.assertFalse(list(reasoner.disjoint_classes(person)))
mgr.add_axiom(onto, OWLDisjointClassesAxiom([brother, sister, aerial_animal]))
self.assertEqual(set([sister, aerial_animal]), set(reasoner.disjoint_classes(brother)))
mgr.remove_axiom(onto, OWLDisjointClassesAxiom([brother, sister, aerial_animal]))
self.assertFalse(set(reasoner.disjoint_classes(brother)))
self.assertFalse(set(reasoner.disjoint_classes(sister)))
mgr.add_axiom(onto, OWLDisjointClassesAxiom([person, animal]))
self.assertEqual(set([animal, aerial_animal]), set(reasoner.disjoint_classes(person)))
mgr.remove_axiom(onto, OWLDisjointClassesAxiom([person, animal]))
self.assertFalse(set(reasoner.disjoint_classes(person)))

self.assertFalse(list(reasoner.disjoint_object_properties(has_sibling)))
self.assertFalse(list(reasoner.disjoint_object_properties(has_child)))
Expand Down

0 comments on commit 6a87e73

Please sign in to comment.