-
-

ontouml_py.classes.concrete_classes.class

+
+

ontouml_py.classes.concrete_classes.class_py

This module defines classes and functionality for representing and manipulating ontological models.

It includes the definition of the Class class, which is a key component in the ontological model, representing ontological classes with various attributes and behaviors. The module also includes definitions for handling literals associated with these classes, ensuring that operations on these classes adhere to certain ontological constraints.

+

In this library, a Class is initialized as an enumeration by providing a list of literals, which are integral to its +definition. These literals, typically dependent on their classes, represent the finite set of values for enumeration +instances. To enhance object manipulation flexibility, this library allows the creation of ‘free’ literals, +independent of any class. Users can create these literals separately and later insert them into the appropriate +classes, offering a dynamic approach to class and literal management.

+

The module is named class_py instead of class due to the fact that class is a reserved keyword in Python. +As reserved keywords cannot be used as module names, class_py was chosen to maintain clarity and consistency with the +module’s purpose, while avoiding naming conflicts within the Python language.”

Module Contents

Classes

- +

Class

Class

Represent a class in an ontological model.

-
-class ontouml_py.classes.concrete_classes.class.Class(**data)
+
+class ontouml_py.classes.concrete_classes.class_py.Class(**data)

Bases: ontouml_py.classes.abstract_classes.classifier.Classifier

Represent a class in an ontological model.

This class extends the Classifier class and includes additional properties and methods specific to @@ -123,46 +131,62 @@

Classes
  • restricted_to (set[OntologicalNature]) – A set of ontological natures that the class is restricted to.

  • stereotype (ClassStereotype) – The stereotype of the class.

  • literals (set[Literal]) – A set of literals associated with the class.

  • -
  • model_config (dict) – Pydantic’s configuration settings for the class.

  • Parameters:

    data (dict[str, Any]) –

    +
    +
    +property literals: set[ontouml_py.classes.concrete_classes.literal.Literal]
    +

    Provide a read-only view of the class’s literals.

    +

    This property is a safeguard to prevent direct modification of the ‘literals’ set. To add or remove literals, +use the ‘add_literal’ and ‘remove_literal’ methods. This design ensures that the integrity of the class’s +literals collection is maintained.

    +
    +
    Returns:
    +

    A set of Literal objects that are part of the class.

    +
    +
    Return type:
    +

    set[Literal]

    +
    +
    +
    +
    -
    -is_powertype: bool
    +
    +_literals: set[ontouml_py.classes.concrete_classes.literal.Literal]
    -
    -order: str
    +
    +is_powertype: bool
    -
    -restricted_to: set[ontouml_py.classes.enumerations.ontologicalnature.OntologicalNature]
    +
    +order: str
    -
    -stereotype: ontouml_py.classes.enumerations.classstereotype.ClassStereotype
    +
    +restricted_to: set[ontouml_py.classes.enumerations.ontologicalnature.OntologicalNature]
    -
    -literals: set[ontouml_py.classes.concrete_classes.literal.Literal]
    +
    +stereotype: ontouml_py.classes.enumerations.classstereotype.ClassStereotype
    -
    -model_config
    +
    +model_config
    -
    -validate_class()
    +
    +validate_class()

    Validate the class based on its literals and stereotype.

    This method checks if the class conforms to the rules based on its stereotype. Specifically, it ensures that only classes with the Enumeration stereotype can have literals.

    @@ -177,18 +201,17 @@

    Classes

    -
    -add_literal(**data)
    -

    Add a new literal to the class.

    -

    This method creates and adds a new instance of Literal to the class’s set of literals. It first -checks if the class’s stereotype is Enumeration, as only classes with this stereotype are allowed -to have literals.

    +
    +add_literal(new_literal)
    +

    Add a new literal to the class’s collection of literals.

    +

    This method ensures that only instances of Literal or its subclasses are added to the class. It also +establishes a bidirectional relationship between the class and the literal.

    Parameters:
    -

    data (dict) – A dictionary containing the data needed to create a new Literal.

    +

    new_literal (Literal) – The Literal to be added.

    Raises:
    -

    ValueError – If the class’s stereotype is not Enumeration.

    +

    TypeError – If the provided new_literal is not an instance of Literal or if a class attempts to add itself.

    Return type:

    None

    @@ -197,17 +220,20 @@

    Classes

    -
    -remove_literal(remove_id)
    -

    Remove a literal from the class based on its ID.

    -

    This method iterates over the class’s literals and removes the one with the matching ID. -It validates that the class has an Enumeration stereotype before attempting removal.

    +
    +remove_literal(old_literal)
    +

    Remove an existing content from the class’s collection of literals.

    +

    This method ensures that the content to be removed is actually part of the class. It also updates the +content’s ‘in_class’ attribute to None, effectively breaking the bidirectional relationship.

    Parameters:
    -

    remove_id (str) – The ID of the literal to be removed.

    +

    old_literal (Literal) – The Literal content to be removed.

    Raises:
    -

    ValueError – If the class does not have an Enumeration stereotype.

    +
      +
    • TypeError – If the content is not a valid Literal.

    • +
    • ValueError – If the content is not part of the class.

    • +
    Return type:

    None

    diff --git a/docs/autoapi/ontouml_py/classes/concrete_classes/generalization/index.html b/docs/autoapi/ontouml_py/classes/concrete_classes/generalization/index.html index 13bec8d..11e985a 100644 --- a/docs/autoapi/ontouml_py/classes/concrete_classes/generalization/index.html +++ b/docs/autoapi/ontouml_py/classes/concrete_classes/generalization/index.html @@ -24,7 +24,7 @@ - + @@ -139,7 +139,7 @@

    Classes