fuzzy_dl_owl2.fuzzydl.concept.weighted_sum_concept
A weighted sum concept aggregates multiple sub-concepts using specific numerical weights to form a composite linear combination within a fuzzy description logic framework.
Description
The software defines a composite entity that represents a linear mixture of other concepts, where each component contributes proportionally based on an assigned floating-point weight. During initialization, strict validation ensures that the number of weights matches the number of constituent concepts and that the total weight sum does not exceed 1.0, maintaining logical consistency within the fuzzy logic model. By inheriting from a base concept class and implementing a specific interface, the entity integrates seamlessly into a larger hierarchy, enabling it to participate in complex logical expressions such as negation, conjunction, and disjunction. Structural manipulation capabilities allow for the traversal of the concept hierarchy to retrieve atomic components or roles, while a cloning mechanism ensures that modifications to the internal structure can be performed without affecting the original instance.
Classes
This entity models a composite concept formed by aggregating a collection of sub-concepts using specific numerical weights, effectively representing a linear combination or mixture. To utilize this class, instantiate it with two parallel lists: one containing floating-point weights and another containing the corresponding Concept objects. It is crucial that the number of weights matches the number of concepts and that the total sum of the weights does not exceed 1.0, as exceeding this limit is considered invalid for the model's logic. Upon initialization, the object automatically generates a string representation of its structure. Additionally, this class supports logical operations such as negation, conjunction, and disjunction through standard Python operators, and provides methods for traversing or modifying the underlying concept hierarchy, such as replacing specific sub-concepts or retrieving atomic components. |
Module Contents
UML Class Diagram for WeightedSumConcept
- class WeightedSumConcept(weights: list[float], concepts: list[fuzzy_dl_owl2.fuzzydl.concept.concept.Concept])
Bases:
fuzzy_dl_owl2.fuzzydl.concept.concept.Concept,fuzzy_dl_owl2.fuzzydl.concept.interface.has_weighted_concepts_interface.HasWeightedConceptsInterface
This entity models a composite concept formed by aggregating a collection of sub-concepts using specific numerical weights, effectively representing a linear combination or mixture. To utilize this class, instantiate it with two parallel lists: one containing floating-point weights and another containing the corresponding Concept objects. It is crucial that the number of weights matches the number of concepts and that the total sum of the weights does not exceed 1.0, as exceeding this limit is considered invalid for the model’s logic. Upon initialization, the object automatically generates a string representation of its structure. Additionally, this class supports logical operations such as negation, conjunction, and disjunction through standard Python operators, and provides methods for traversing or modifying the underlying concept hierarchy, such as replacing specific sub-concepts or retrieving atomic components.
- Parameters:
name (Any) – Automatically generated string representation of the weighted sum concept in the format (w-sum (w1 C1) (w2 C2) …).
- __and__(value: Self) Self
Performs a logical conjunction or combination operation between the current instance and another instance of the same type, enabling the use of the & operator. This method delegates the core logic to the and_ static method defined in OperatorConcept, ensuring that the operation adheres to the specific algebraic rules defined for the concept. It returns a new instance representing the result of the operation, leaving the original operands unmodified.
- Parameters:
value (Self) – The right-hand operand of the AND operation.
- Returns:
The result of the AND operation between the instance and the provided value.
- Return type:
Self
- __hash__() int
Return a hash value for this object, computed from its string representation. This approach ensures that the hash value reflects the structural identity of the object without relying on cached values or additional methods. The hash is derived from the output of the __str__ method, which provides a consistent and unique representation of the concept’s structure. This implementation does not utilize any internal caching mechanism and directly computes the hash each time it is called.
- Returns:
An integer hash value representing the structural identity of this object.
- Return type:
int
- __neg__() fuzzy_dl_owl2.fuzzydl.concept.concept.Concept
Implements the unary negation operator to return the logical negation of the current concept. This method delegates the creation of the negated object to OperatorConcept.not_, ensuring that the operation returns a new Concept instance rather than modifying the existing one in place. Consequently, applying the minus sign to a WeightedSumConcept effectively treats it as a logical NOT operation.
- Returns:
A Concept representing the logical negation of this concept.
- Return type:
- __or__(value: Self) Self
Implements the bitwise OR operator (|) to perform a logical disjunction between the current concept and another WeightedSumConcept. This method delegates the construction of the resulting concept to OperatorConcept.or_, returning a new instance that represents the union of the two operands without modifying the original objects. The operation requires the provided value to be of the same type as the current instance.
- Parameters:
value (Self) – The other operand to combine with the current instance using the OR operation.
- Returns:
A new instance representing the result of the OR operation between the current instance and the provided value.
- Return type:
Self
- clone() Self
Returns a shallow copy of the current WeightedSumConcept instance. The method instantiates a new object using independent copies of the internal weights and concepts lists, ensuring that structural modifications to these lists in the clone do not affect the original object. However, because the copy is shallow, the new instance retains references to the same underlying concept objects; therefore, mutations to the concept objects themselves will be reflected in both the original and the clone.
- Returns:
A new instance of the class with copies of the weights and concepts lists.
- Return type:
Self
- compute_atomic_concepts() set[fuzzy_dl_owl2.fuzzydl.concept.concept.Concept]
Computes and returns the set of all atomic concepts underlying this weighted sum concept. This method iterates over the internal collection of concepts, recursively invoking their compute_atomic_concepts methods and aggregating the results into a single set to ensure uniqueness. The returned set represents the base-level concepts that compose this composite structure.
- Returns:
A set of all atomic concepts derived from the concepts associated with this object.
- Return type:
set[Concept]
- compute_name() str
Generates a string representation of the weighted sum concept by iterating over the internal lists of concepts and weights. The returned string follows a specific parenthesized syntax, starting with “(w-sum” and appending space-separated tuples containing the weight and the corresponding concept. This method is read-only and does not modify the object’s state; however, if the lists of concepts and weights have mismatched lengths, the zip function will truncate the output to the length of the shorter list, ignoring any excess elements.
- Returns:
A string representation of the weighted sum of concepts and their corresponding weights, formatted as “(w-sum (weight concept) …)”.
- Return type:
str
- get_roles() set[str]
Retrieves the union of roles associated with the underlying concepts that constitute this weighted sum. It iterates over the collection of concepts stored in the instance, aggregates the roles returned by each sub-concept, and returns them as a unique set of strings. If there are no underlying concepts, an empty set is returned. Since the result is a set, duplicate roles found across different sub-concepts are automatically removed. This operation does not modify the state of the object or its sub-concepts.
- Returns:
A set of unique roles derived from the object’s concepts.
- Return type:
set[str]
- replace( ) fuzzy_dl_owl2.fuzzydl.concept.concept.Concept
Replaces all occurrences of a specific concept with another concept within the internal list of component concepts by recursively delegating the replacement operation to each sub-concept. A new instance is constructed using the original weights and the updated list of concepts, and the method returns the logical negation of this new object. This ensures the substitution propagates through nested structures while preserving the original weighting scheme.
- name = '(w-sum )'