Source code for owlapy.class_expression.nary_boolean_expression

"""OWL nary boolean expressions"""

from typing import Final, Iterable, Sequence

from ..meta_classes import HasOperands
from .class_expression import OWLBooleanClassExpression, OWLClassExpression


[docs] class OWLNaryBooleanClassExpression( OWLBooleanClassExpression, HasOperands[OWLClassExpression] ): """OWLNaryBooleanClassExpression.""" __slots__ = () _operands: Sequence[OWLClassExpression] def __init__(self, operands: Iterable[OWLClassExpression]): """ Args: operands: Class expressions. """ self._operands = tuple(operands) assert ( len(self._operands) > 1 ), "OWLNaryBooleanClassExpression requires at least two operands." for i, op in enumerate(self._operands): if not isinstance(op, OWLClassExpression): raise TypeError( f"Expected all operands to be instances of OWLClassExpression, got {type(op).__name__} instead ({op!r}) at index {i}." )
[docs] def operands(self) -> Iterable[OWLClassExpression]: # documented in parent yield from self._operands
[docs] def __repr__(self): return f"{type(self).__name__}({repr(self._operands)})"
[docs] def __eq__(self, other): if type(other) is type(self): return set(self._operands) == set(other._operands) and len(self._operands) == len(other._operands) return False
[docs] def __hash__(self): return hash((type(self).__name__, frozenset(self._operands), len(self._operands)))
[docs] class OWLObjectUnionOf(OWLNaryBooleanClassExpression): """A union class expression ObjectUnionOf( CE1 ... CEn ) contains all individuals that are instances of at least one class expression CEi for 1 ≤ i ≤ n. (https://www.w3.org/TR/owl2-syntax/#Union_of_Class_Expressions) """ __slots__ = "_operands" type_index: Final = 3002 _operands: Sequence[OWLClassExpression]
[docs] class OWLObjectIntersectionOf(OWLNaryBooleanClassExpression): """An intersection class expression ObjectIntersectionOf( CE1 ... CEn ) contains all individuals that are instances of all class expressions CEi for 1 ≤ i ≤ n. (https://www.w3.org/TR/owl2-syntax/#Intersection_of_Class_Expressions) """ __slots__ = "_operands" type_index: Final = 3001 _operands: Sequence[OWLClassExpression]