Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
class_py.py and literal.py implemented with tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
pedropaulofb committed Dec 3, 2023
1 parent 63145dd commit ac42bdf
Show file tree
Hide file tree
Showing 44 changed files with 806 additions and 445 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Classes

:ivar _in_package: Reference to the Package instance this element is contained in. This is a private attribute.
:vartype _in_package: Optional[Package]
:cvar model_config: Configuration settings for the Pydantic model.
:vartype model_config: Dict[str, Any]

.. py:property:: in_package
:type: Optional[Package]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

.. py:module:: ontouml_py.classes.abstract_classes.relation
.. autoapi-nested-parse::

This module provides the `Relation` class, a subclass of `Classifier`, representing relations in an ontological model.
It supports various relation stereotypes as defined in the `RelationStereotype` enumeration.

The `Relation` class is an abstract base class and is intended to be subclassed by specific types of relations,
such as `BinaryRelation` and `NaryRelation`. It includes validation for these subclasses and allows for the
configuration of Pydantic model settings.



Module Contents
---------------
Expand All @@ -22,16 +32,15 @@ Classes
Bases: :py:obj:`ontouml_py.classes.abstract_classes.classifier.Classifier`

Abstract base class for classifiers in an OntoUML model.
Abstract base class for representing different types of relations in an ontological model.

Classifier represents a general concept in an OntoUML model. It extends Decoratable and Packageable, inheriting
their features. This class maintains a list of properties and an 'is_abstract' flag, defining whether the classifier
is abstract.
This class extends `Classifier` and adds support for relation stereotypes. It is designed to be subclassed
by more specific relation types, such as binary and n-ary relations.

:ivar _properties: A list of Property instances associated with this classifier.
:vartype _properties: list[Property]
:ivar is_abstract: Indicates whether the classifier is abstract.
:vartype is_abstract: bool
:ivar stereotype: The stereotype of the relation, defining its ontological nature.
:vartype stereotype: Optional[RelationStereotype]
:cvar model_config: Configuration settings for the Pydantic model.
:vartype model_config: Dict[str, Any]

.. py:attribute:: stereotype
:type: Optional[ontouml_py.classes.enumerations.relationstereotype.RelationStereotype]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Classes
Bases: :py:obj:`ontouml_py.classes.abstract_classes.modelelement.ModelElement`

Represents an anchor in an OntoUML model.
Represent an anchor in an OntoUML model.

An anchor is a specialized model element that links a note (note) to another model element (target). It
extends the ModelElement class, inheriting its attributes and methods, and adds specific relationships to both a
Expand All @@ -59,9 +59,6 @@ Classes
:ivar target: The model element that is being described or commented on by the note.
:vartype target: ModelElement

:param data: Fields to be set on the model instance, including 'note' and 'target'.
:type data: dict[str, Any]

.. py:attribute:: note
:type: ontouml_py.classes.concrete_classes.note.Note

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@

.. py:module:: ontouml_py.classes.concrete_classes.binaryrelation
.. autoapi-nested-parse::

This module provides the `BinaryRelation` class, a specific implementation of the `Relation` class for representing
binary relations in an ontological model. A binary relation is a relation that involves exactly two distinct entities.

The `BinaryRelation` class inherits from `Relation` and maintains the same configuration settings, allowing for
customization and validation of attributes specific to binary relations.



Module Contents
---------------
Expand All @@ -22,16 +31,13 @@ Classes
Bases: :py:obj:`ontouml_py.classes.abstract_classes.relation.Relation`

Abstract base class for classifiers in an OntoUML model.
Represent a binary relation in an ontological model.

Classifier represents a general concept in an OntoUML model. It extends Decoratable and Packageable, inheriting
their features. This class maintains a list of properties and an 'is_abstract' flag, defining whether the classifier
is abstract.
A binary relation is a type of relation that involves exactly two distinct entities. This class extends the
`Relation` class and inherits its properties and methods.

:ivar _properties: A list of Property instances associated with this classifier.
:vartype _properties: list[Property]
:ivar is_abstract: Indicates whether the classifier is abstract.
:vartype is_abstract: bool
:cvar model_config: Configuration settings for the Pydantic model.
:vartype model_config: Dict[str, Any]

.. py:attribute:: model_config
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
:py:mod:`ontouml_py.classes.concrete_classes.class_py`
======================================================

.. py:module:: ontouml_py.classes.concrete_classes.class_py
.. autoapi-nested-parse::

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
~~~~~~~

.. autoapisummary::

ontouml_py.classes.concrete_classes.class_py.Class




.. py:class:: Class(**data)
Bases: :py:obj:`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
ontological classes. It supports operations like adding and removing literals, provided the class
conforms to certain constraints based on its stereotype.

:ivar is_powertype: Indicates if the class is a powertype.
:vartype is_powertype: bool
:ivar order: Represents the order of the class.
:vartype order: str
:ivar restricted_to: A set of ontological natures that the class is restricted to.
:vartype restricted_to: set[OntologicalNature]
:ivar stereotype: The stereotype of the class.
:vartype stereotype: ClassStereotype
:ivar literals: A set of literals associated with the class.
:vartype literals: set[Literal]

.. py:property:: literals
:type: 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.

:return: A set of Literal objects that are part of the class.
:rtype: set[Literal]


.. py:attribute:: _literals
:type: set[ontouml_py.classes.concrete_classes.literal.Literal]



.. py:attribute:: is_powertype
:type: bool



.. py:attribute:: order
:type: str



.. py:attribute:: restricted_to
:type: set[ontouml_py.classes.enumerations.ontologicalnature.OntologicalNature]



.. py:attribute:: stereotype
:type: ontouml_py.classes.enumerations.classstereotype.ClassStereotype



.. py:attribute:: model_config
.. py:method:: 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.

:raises ValueError: If the class has literals but does not have an Enumeration stereotype.


.. py:method:: 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.

:param new_literal: The Literal to be added.
:type new_literal: Literal
:raises TypeError: If the provided new_literal is not an instance of Literal or if a class attempts to add itself.


.. py:method:: 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.

:param old_literal: The Literal content to be removed.
:type old_literal: Literal
:raises TypeError: If the content is not a valid Literal.
:raises ValueError: If the content is not part of the class.



Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Submodules

anchor/index.rst
binaryrelation/index.rst
class/index.rst
class_py/index.rst
generalization/index.rst
generalizationset/index.rst
literal/index.rst
Expand Down
Loading

0 comments on commit ac42bdf

Please sign in to comment.