From c723e7f8983785836c38d553279d930a21377918 Mon Sep 17 00:00:00 2001 From: Caglar Demir Date: Wed, 30 Oct 2024 12:24:31 +0100 Subject: [PATCH] Fixes thirt issue in #90 --- owlapy/class_expression/restriction.py | 8 +++++--- tests/{test_owlapy_cnf_dnf.py => test_owlapy_cnf_dnf} | 0 tests/test_owlapy_conversions.py | 6 +++--- tests/test_owlapy_render.py | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) rename tests/{test_owlapy_cnf_dnf.py => test_owlapy_cnf_dnf} (100%) diff --git a/owlapy/class_expression/restriction.py b/owlapy/class_expression/restriction.py index 2ccc7248..076a390f 100644 --- a/owlapy/class_expression/restriction.py +++ b/owlapy/class_expression/restriction.py @@ -1,7 +1,7 @@ """OWL Restrictions""" from abc import ABCMeta, abstractmethod from ..meta_classes import HasFiller, HasCardinality, HasOperands -from typing import TypeVar, Generic, Final, Sequence, Union, Iterable +from typing import TypeVar, Generic, Final, Sequence, Union, Iterable, Set from .nary_boolean_expression import OWLObjectIntersectionOf, OWLObjectUnionOf from .class_expression import OWLAnonymousClassExpression, OWLClassExpression from ..owl_property import OWLPropertyExpression, OWLObjectPropertyExpression, OWLDataPropertyExpression @@ -393,13 +393,15 @@ class OWLObjectOneOf(OWLAnonymousClassExpression, HasOperands[OWLIndividual]): __slots__ = '_values' type_index: Final = 3004 - def __init__(self, values: Union[OWLIndividual, Iterable[OWLIndividual]]): + def __init__(self, values: OWLIndividual | Iterable[OWLIndividual]): + #assert isinstance(values, OWLIndividual) | isinstance(values, set) + # f"The input of OWLObjectOneOf must be either an OWLIndividual or a set of OWLIndividual. Currently, {type(values)}!" if isinstance(values, OWLIndividual): self._values = values, else: for _ in values: assert isinstance(_, OWLIndividual) - self._values = tuple(values) + self._values = {i for i in values} def individuals(self) -> Iterable[OWLIndividual]: """Gets the individuals that are in the oneOf. These individuals represent the exact instances (extension) diff --git a/tests/test_owlapy_cnf_dnf.py b/tests/test_owlapy_cnf_dnf similarity index 100% rename from tests/test_owlapy_cnf_dnf.py rename to tests/test_owlapy_cnf_dnf diff --git a/tests/test_owlapy_conversions.py b/tests/test_owlapy_conversions.py index 9a035065..fdb84ed3 100644 --- a/tests/test_owlapy_conversions.py +++ b/tests/test_owlapy_conversions.py @@ -46,10 +46,10 @@ def test_owlapy_to_dl_str_and_back(self): # (4) i1 = OWLNamedIndividual(IRI.create(NS, 'heinz')) i2 = OWLNamedIndividual(IRI.create(NS, 'marie')) - c = OWLObjectOneOf((i1, i2)) + c = OWLObjectOneOf({i1, i2}) rendered_c = renderer.render(c) self.assertEqual(c, parser.parse_expression(rendered_c)) - self.assertEqual(rendered_c, "{heinz ⊔ marie}") + assert rendered_c== "{heinz ⊔ marie}" or rendered_c=="{marie ⊔ heinz}" # (5) c = OWLObjectHasValue(property=has_child, individual=i1) rendered_c = renderer.render(c) @@ -110,7 +110,7 @@ def test_owlapy_to_dl_str_and_back(self): OWLNamedIndividual(IRI.create(NS, 'A')), OWLNamedIndividual(IRI.create(NS, 'B'))])) renderer_c = renderer.render(c) - self.assertEqual(renderer_c, "∃ hasChild.{A ⊔ B}") + assert renderer_c=="∃ hasChild.{A ⊔ B}" or renderer_c== "∃ hasChild.{B ⊔ A}" self.assertEqual(c, parser.parse_expression(renderer_c)) # (16) c = OWLObjectAllValuesFrom(property=has_child, filler=OWLObjectOneOf([ diff --git a/tests/test_owlapy_render.py b/tests/test_owlapy_render.py index af909602..a2cb7504 100644 --- a/tests/test_owlapy_render.py +++ b/tests/test_owlapy_render.py @@ -43,7 +43,7 @@ def test_ce_render(self): i2 = OWLNamedIndividual(IRI.create(NS, 'marie')) oneof = OWLObjectOneOf((i1, i2)) r = renderer.render(oneof) - self.assertEqual(r, "{heinz ⊔ marie}") + assert r=="{heinz ⊔ marie}" or r=="{marie ⊔ heinz}" hasvalue = OWLObjectHasValue(property=has_child, individual=i1) r = renderer.render(hasvalue)