pyowl2.data_range.data_one_of
An implementation of the OWL DataOneOf data range that restricts property values to an explicit, finite enumeration of sorted literals.
Description
Designed to represent a closed set of specific values within an ontology, this component restricts data membership to a finite, explicitly defined list of literals. By inheriting from the abstract OWLDataRange base, it integrates into the broader type system while enforcing that the provided collection of OWLLiteral objects is non-empty. A key design choice involves automatically sorting the internal collection of literals upon initialization and modification, which guarantees a canonical representation and simplifies comparison operations. The resulting structure supports string serialization in functional syntax, allowing the enumerated data range to be easily rendered or debugged as a human-readable expression.
Classes
This class models a data range defined by an explicit enumeration of specific literal values, effectively restricting data membership to a finite, closed set. It is utilized within ontologies to define properties that can only take on one of the pre-defined values, such as a specific set of integers or strings. Upon instantiation, the class requires a non-empty list of OWLLiteral objects and automatically maintains these literals in a sorted order to ensure consistency. |
Module Contents
UML Class Diagram for OWLDataOneOf
- class OWLDataOneOf(literals: list[pyowl2.literal.literal.OWLLiteral])[source]
Bases:
pyowl2.abstracts.data_range.OWLDataRange
This class models a data range defined by an explicit enumeration of specific literal values, effectively restricting data membership to a finite, closed set. It is utilized within ontologies to define properties that can only take on one of the pre-defined values, such as a specific set of integers or strings. Upon instantiation, the class requires a non-empty list of OWLLiteral objects and automatically maintains these literals in a sorted order to ensure consistency.
- Parameters:
literals (list[OWLLiteral]) – The sorted list of literal values explicitly enumerated in this data range, guaranteed to be non-empty.
- __str__() str[source]
Returns a human-readable string representation of the data one-of expression using a functional syntax format. The output string begins with “DataOneOf” followed by the string representations of the literals contained within the object, joined by spaces and enclosed in parentheses. This method is typically invoked implicitly when the object is passed to the print function or converted to a string.
- Returns:
A string representation of the object, formatted as ‘DataOneOf(…)’ containing the space-separated string values of the internal literals.
- Return type:
str
- _literals: list[pyowl2.literal.literal.OWLLiteral]
- property literals: list[pyowl2.literal.literal.OWLLiteral]
Updates the collection of literal values that define this data range by assigning the provided list of OWLLiteral objects. The method enforces a specific ordering by sorting the input list before storing it internally, which ensures a canonical representation but may alter the original sequence of the provided arguments. This operation overwrites the existing internal state and requires that all elements in the input list be comparable to avoid raising a TypeError during the sorting process.
- Parameters:
value (list[OWLLiteral]) – A list of OWL literals to be assigned to the object.