fuzzy_dl_owl2.fuzzydl.label

Encapsulates a fuzzy concept paired with a specific degree of satisfaction to form a weighted annotation.

Description

The implementation associates a semantic category, defined by a Concept object, with a quantitative strength represented by a Degree instance. Equality comparisons are handled with strict type checking to ensure that two labels are considered identical only if their underlying concepts match and their weights are of the same class and value. A static helper method manages the comparison logic for degrees, distinguishing between numeric values that require exact matching and non-numeric types that rely on class identity. By overriding standard magic methods, the class ensures that instances behave predictably when compared for equality or converted to string representations for display.

Classes

Label

Represents a weighted fuzzy concept used to annotate individuals, pairing a specific concept with a degree of satisfaction. To use this class, instantiate it with a Concept object and a Degree value between 0 and 1, where the degree indicates the extent to which the concept applies. The class provides logic for comparing instances, ensuring that two objects are equal only if their concepts are identical and their weights share the same type and numerical value.

Module Contents

UML Class Diagram for Label

UML Class Diagram for Label

class Label(concept: fuzzy_dl_owl2.fuzzydl.concept.concept.Concept, weight: fuzzy_dl_owl2.fuzzydl.degree.degree.Degree)[source]

Represents a weighted fuzzy concept used to annotate individuals, pairing a specific concept with a degree of satisfaction. To use this class, instantiate it with a Concept object and a Degree value between 0 and 1, where the degree indicates the extent to which the concept applies. The class provides logic for comparing instances, ensuring that two objects are equal only if their concepts are identical and their weights share the same type and numerical value.

Parameters:
  • concept (Concept) – The fuzzy concept instance defining the label’s semantic category.

  • weight (Degree) – The degree to which the associated concept is satisfied for the individual, represented as a value between 0 and 1.

__eq__(cw: Self) bool[source]

Determines if the current Label instance is equal to another instance by comparing their internal state. The method first performs a strict equality check on the concept attribute; if the concepts differ, it immediately returns False. If the concepts match, the method relies on the weights_equal helper function to evaluate the equality of the weight attributes, returning the result of that comparison. This operation does not modify the state of either object.

Parameters:

cw (Self) – The other instance to compare for equality.

Returns:

True if the concepts and weights of the two instances are equal, False otherwise.

Return type:

bool

__ne__(cw: Self) bool[source]

Implements the inequality comparison for the Label object, determining whether the current instance differs from the specified Label instance (cw). It returns True if the two instances are not equal and False otherwise, effectively inverting the result of the equality check. This method has no side effects and relies entirely on the logic defined in the __eq__ method to determine equality.

Parameters:

cw (Self) – The object to compare against for inequality.

Returns:

True if the current instance is not equal to the specified object, False otherwise.

Return type:

bool

__str__() str[source]

Returns a human-readable string representation of the label instance by concatenating the concept and weight attributes with a single space. This method is implicitly invoked by the built-in str() function and print operations to provide a concise summary of the object’s state. It has no side effects and relies on the string conversion of the underlying attributes, meaning that non-string values for concept or weight will be implicitly formatted as strings.

Returns:

A human-readable string representation of the object, formatted as ‘concept weight’.

Return type:

str

static weights_equal(w1: fuzzy_dl_owl2.fuzzydl.degree.degree.Degree, w2: fuzzy_dl_owl2.fuzzydl.degree.degree.Degree) bool[source]

Determines whether two Degree instances represent equivalent weights by first verifying that they are instances of the exact same class. If the classes differ, the method returns False immediately. For instances of the same class, non-numeric degrees are considered equal, while numeric degrees are compared based on their specific numerical values. This method performs a strict type check and does not modify the input objects.

Parameters:
  • w1 (Degree) – The first Degree instance to compare.

  • w2 (Degree) – The second degree to compare against the first argument.

Returns:

True if the two Degree objects are of the same class and have equal numerical values (if numeric), otherwise False.

Return type:

bool

concept: fuzzy_dl_owl2.fuzzydl.concept.concept.Concept
weight: fuzzy_dl_owl2.fuzzydl.degree.degree.Degree