fuzzy_dl_owl2.fuzzydl.concrete_feature
A class representing a concrete feature characterized by a name and a specific data type such as string, boolean, integer, or real.
Description
Flexible instantiation allows the data type to be automatically inferred from the provided arguments, defaulting to a string if only a name is supplied, or explicitly setting boolean, integer, or real types based on the presence of flags or numeric bounds. Utilizing overloaded constructors and internal dispatch logic ensures that numeric features are initialized with specific lower and upper bounds, which are essential for defining ranges within the domain. State management is handled through standard accessors and mutators, enabling the modification of the feature’s type and range constraints after creation, while a cloning mechanism facilitates the creation of independent copies that preserve the original configuration. Such a structure serves as a foundational component for defining typed attributes within the broader system, ensuring that semantic constraints and data types are strictly enforced and easily retrievable.
Classes
This class models a specific attribute of an individual, characterized by a name and a data type such as string, boolean, integer, or real. The type is automatically determined during initialization based on the provided arguments: supplying only a name defaults to a string type, passing a boolean flag explicitly sets the type to boolean, and providing numeric bounds (k1 and k2) defines an integer or real range. It supports accessing and modifying the feature's type and numeric boundaries, as well as cloning the instance to create an independent copy. |
Module Contents
UML Class Diagram for ConcreteFeature
- class ConcreteFeature(name: str)[source]
- class ConcreteFeature(name: str, is_boolean: bool)
- class ConcreteFeature(name: str, k1: int, k2: int)
- class ConcreteFeature(name: str, k1: float, k2: float)
This class models a specific attribute of an individual, characterized by a name and a data type such as string, boolean, integer, or real. The type is automatically determined during initialization based on the provided arguments: supplying only a name defaults to a string type, passing a boolean flag explicitly sets the type to boolean, and providing numeric bounds (k1 and k2) defines an integer or real range. It supports accessing and modifying the feature’s type and numeric boundaries, as well as cloning the instance to create an independent copy.
- Raises:
ValueError – Raised when the arguments provided during initialization are invalid, such as having an incorrect number of arguments or types that do not match the expected signature for a boolean or numeric feature.
- __concrete_feature_init_1(name: str) None
Initializes the ConcreteFeature instance with a specific name and default configuration for range constraints and data type. This method assigns the provided string to the name attribute, sets the lower and upper bounds (k1 and k2) to None, and explicitly sets the feature type to ConcreteFeatureType.STRING. It directly mutates the instance’s state, effectively resetting any pre-existing values for the bounds and type, and is intended for use when creating features that do not initially require numeric range definitions.
- Parameters:
name (str) – The name of the concrete feature.
- __concrete_feature_init_2(name: str, is_boolean: bool) None
Initializes the feature instance by delegating the assignment of the feature’s name to the primary initialization method, __concrete_feature_init_1. This method accepts a string for the name and a boolean flag to determine the feature’s data type. If the is_boolean flag is set to True, the instance’s type attribute is explicitly set to ConcreteFeatureType.BOOLEAN; if the flag is False, the type attribute remains in whatever state it was left by the preceding initialization call. This process mutates the instance’s state in-place.
- Parameters:
name (str) – The name or identifier of the feature.
is_boolean (bool) – Flag indicating whether the feature type should be set to BOOLEAN.
- __concrete_feature_init_3(name: str, k1: int, k2: int) None
Initializes the feature as an integer type defined by a specific range between two bounds. It delegates the assignment of the feature’s name to the __concrete_feature_init_1 method, then sets the k1 attribute as the lower bound and the k2 attribute as the upper bound. This method modifies the instance’s state by setting the type attribute to ConcreteFeatureType.INTEGER, though it does not perform validation to ensure that the lower bound is less than the upper bound.
- Parameters:
name (str) – The identifier or label for the feature.
k1 (int) – The lower bound for the range.
k2 (int) – Upper bound for the range.
- __concrete_feature_init_4(name: str, k1: float, k2: float) None
Initializes a concrete feature instance representing a real-valued variable with a specified name and numerical range. The k1 and k2 parameters define the lower and upper bounds of the feature’s domain, respectively. This method explicitly sets the feature type to REAL and delegates the initialization of the name attribute to a separate internal routine.
- Parameters:
name (str) – Identifier for the feature.
k1 (float) – The lower bound for the feature’s value range.
k2 (float) – The upper bound for the range.
- __repr__() str[source]
Returns the official string representation of the instance by delegating to the object’s __str__ method. This implementation ensures that the output of repr() is identical to the informal string representation provided by str(). Because it relies on __str__, the behavior and format of the output are determined by that method, and a failure to define __str__ could lead to a recursion error.
- Returns:
A string representation of the object.
- Return type:
str
- __str__() str[source]
Returns the informal string representation of the feature instance. This implementation delegates the formatting logic to the get_name method, effectively using the feature’s name as its primary identifier when converted to a string. It is automatically invoked by the built-in str() function and print statements.
- Returns:
The name of the object.
- Return type:
str
- clone() Self[source]
Creates and returns a new instance that duplicates the current object’s configuration, ensuring the returned copy is independent of the original. The initialization logic adapts based on the feature’s underlying type: boolean features are reconstructed with a specific flag, string features are initialized solely by name, and other types are instantiated using the name along with primary and secondary key values. This method does not modify the state of the existing instance.
- Returns:
A new instance of the class that is a copy of the current object, preserving its name and type-specific attributes.
- Return type:
Self
- get_k1() float | int | None[source]
Returns the current value of the k1 attribute stored within the instance. The method provides access to a numeric parameter that may be represented as either an integer or a float, or it may return None if the value is undefined or null. Since this is a getter method, it performs no side effects or modifications to the object’s internal state.
- Returns:
The value of the k1 attribute.
- Return type:
Optional[Union[float, int]]
- get_k2() float | int | None[source]
Retrieves the current value of the k2 attribute associated with the ConcreteFeature instance. The returned value can be a numeric type, specifically an integer or a float, depending on how the attribute was originally set. If the attribute is uninitialized or explicitly set to None, the method returns None. This is a read-only accessor function that does not alter the object’s state or produce any side effects.
- Returns:
The value of the k2 attribute, which may be an integer, a float, or None.
- Return type:
Optional[Union[float, int]]
- get_name() str[source]
Returns the name of the feature instance. This method provides direct access to the internal name attribute, which serves as the identifier for the feature. It is a read-only operation that does not modify the state of the object, though it will raise an AttributeError if the underlying attribute has not been initialized.
- Returns:
The name associated with the object instance.
- Return type:
str
- get_type() fuzzy_dl_owl2.fuzzydl.util.constants.ConcreteFeatureType[source]
Returns the specific type classification associated with the feature instance. This method acts as a simple accessor for the internal type attribute, providing the ConcreteFeatureType that defines the nature of the object. It does not modify the instance state and has no side effects.
- Returns:
The concrete feature type associated with the instance.
- Return type:
- set_range(k1: float | int | None, k2: float | int | None) None[source]
Updates the range boundaries for the feature by assigning the provided values to the instance attributes. The parameters k1 and k2 can be integers, floats, or None, allowing for partial or unset range definitions. This method directly mutates the object’s state without performing validation on the relative order or magnitude of the inputs.
- Parameters:
k1 (Optional[Union[float, int]]) – The starting value or lower bound of the range. Can be a number or None to indicate an unbounded start.
k2 (Optional[Union[float, int]]) – The upper bound or end value of the range, or None to indicate no upper bound.
- set_type(new_type: fuzzy_dl_owl2.fuzzydl.util.constants.ConcreteFeatureType) None[source]
Updates the type definition of the feature instance to the specified value, replacing the existing type attribute. This method mutates the object’s state by directly assigning the provided ConcreteFeatureType to the internal type property. It does not return a value and assumes the input is a valid type definition compatible with the feature’s schema.
- Parameters:
new_type (ConcreteFeatureType) – The concrete feature type to assign to the instance.