ontouml_py.model.ontoumlelement
This module defines the core elements of an OntoUML model, providing a robust framework for representing and managing OntoUML elements. OntoUML is a well-established modeling language used primarily in the field of ontology-driven conceptual modeling.
The module includes an abstract base class, OntoumlElement, which serves as the foundation for all other elements in an OntoUML model. This class encapsulates common features such as unique identification, creation and modification timestamps, and validation logic to ensure the integrity of these attributes.
Module Contents
Classes
Abstract base class representing a generic element within an OntoUML model. |
- class ontouml_py.model.ontoumlelement.OntoumlElement(**data)
Bases:
abc.ABC
,pydantic.BaseModel
Abstract base class representing a generic element within an OntoUML model.
This class provides foundational attributes and methods for all OntoUML elements, including unique identification and timestamps for creation and modification. It enforces constraints on certain attributes and includes validation logic to maintain their integrity.
- Variables:
id (str) – A unique identifier for the element, automatically generated upon instantiation.
created (datetime) – Timestamp when the element was created, defaults to the current time.
modified (Optional[datetime]) – Timestamp when the element was last modified, can be None if not modified.
model_config (Dict[str, Any]) – Configuration settings for the Pydantic model.
- Parameters:
data (dict[str, Any]) –
- id: str
- created: datetime.datetime
- modified: datetime.datetime | None
- model_config
- __eq__(other)
Determine if two OntoumlElement instances are equal based on their unique identifiers.
This method overrides the default equality comparison behavior. It is essential for comparing instances of OntoumlElement, particularly in collections and when ensuring uniqueness. Equality is determined solely based on the ‘id’ attribute, which is assumed to be a unique identifier for each instance.
- Parameters:
other (object) – The other object to compare with the current instance.
- Returns:
True if both instances have the same ‘id’, False otherwise. Returns NotImplemented if ‘other’ is not an instance of OntoumlElement.
- Return type:
bool
- Raises:
TypeError – If ‘other’ is not an instance of OntoumlElement and cannot be compared.
- __hash__()
Compute the hash value of an OntoumlElement instance based on its unique identifier.
This method enables OntoumlElement instances to be used in hash-based data structures like sets and dicts. The hash value is computed using the ‘id’ attribute, ensuring that each instance has a distinct hash value corresponding to its unique identifier.
- Returns:
The hash value of the instance, computed using its ‘id’.
- Return type:
int