-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generalization.py implemented with tests.
- Loading branch information
1 parent
ac42bdf
commit 62b179e
Showing
10 changed files
with
224 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,61 @@ | ||
from ontouml_py.classes.abstract_classes.namedelement import NamedElement | ||
"""This module defines the `Generalization` class, a component of the ontouml_py library. The `Generalization` class | ||
represents a generalization relationship in an ontological model, linking two classifiers in a hierarchy where one | ||
(classifier) is a generalization of the other. This module includes the necessary validations to ensure the integrity | ||
of the generalization relationship, such as preventing a classifier from being a generalization of itself. | ||
""" | ||
from typing import Any | ||
|
||
from pydantic import Field, model_validator | ||
|
||
class Generalization(NamedElement): | ||
# Configuration settings for the Project model using Pydantic. | ||
from ontouml_py.classes.abstract_classes.classifier import Classifier | ||
from ontouml_py.classes.abstract_classes.modelelement import ModelElement | ||
|
||
|
||
class Generalization(ModelElement): | ||
"""Represent a generalization relationship between two classifiers in an ontological model. | ||
This class extends `ModelElement` and is used to define a generalization, where one classifier (the general) is | ||
a generalization of another classifier (the specific). | ||
:ivar general: The general classifier in the generalization relationship. | ||
:vartype general: Classifier | ||
:ivar specific: The specific classifier in the generalization relationship. | ||
:vartype specific: Classifier | ||
:cvar model_config: Configuration settings for the Pydantic model. | ||
:vartype model_config: Dict[str, Any] | ||
""" | ||
|
||
general: Classifier = Field() | ||
specific: Classifier = Field() | ||
|
||
# Pydantic's configuration settings for the class. | ||
model_config = { # noqa (vulture) | ||
"arbitrary_types_allowed": True, | ||
"validate_assignment": True, | ||
"validate_default": True, | ||
"extra": "forbid", | ||
"str_strip_whitespace": True, | ||
"validate_default": True, | ||
} | ||
|
||
@model_validator(mode="after") | ||
def ensure_irreflexive(self): | ||
"""Validate that the generalization relationship is irreflexive. | ||
Ensures that the 'general' and 'specific' classifiers are not the same, as a classifier cannot generalize itself. | ||
:raises ValueError: If 'general' and 'specific' classifiers are the same. | ||
""" | ||
if self.general == self.specific: | ||
raise ValueError("A generalization must relate different 'general' and 'specific' Classifiers.") | ||
|
||
def __init__(self, **data: dict[str, Any]) -> None: | ||
"""Initialize a new instance of the Generalization class. | ||
This constructor initializes a Generalization instance with specified attributes. It ensures that the | ||
generalization relationship is correctly established between the 'general' and 'specific' classifiers. | ||
:param data: A dictionary containing the data to initialize the Generalization instance. Expected keys are | ||
'general' and 'specific', corresponding to the classifiers involved in the generalization. | ||
:type data: dict[str, Any] | ||
""" | ||
super().__init__(**data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.