API
- class likeness.likeness_mixin.LikenessMixin(*args, **kwargs)
A mixin class that provides a method to calculate the likeness between two objects.
- Variables:
_likeness_functions (ClassVar[dict[str, Callable]]) – A dictionary mapping attribute names to functions that calculate likeness.
- like(other: Self) float
Calculate the likeness between this object and another.
The likeness is calculated as the product of the likeness base and the likeness factors. The likeness base is 1 if there are likeness functions defined or if this object is equal to the other. The likeness factors are calculated by applying the likeness functions to corresponding attributes of the two objects.
- Parameters:
other (Self) – The other object to compare with.
- Returns:
The likeness between this object and the other.
- Return type:
float
- Raises:
ValueError – If a likeness function fails to apply.
- likeness.discount.discount(calculation: float) float
Calculate the discounted value.
- Parameters:
calculation (float) – The original value to be discounted.
- Raises:
ValueError – If the calculation is less than 0.
- Returns:
The discounted value. It is the maximum of 1 minus the calculation and 0.
- Return type:
float
- likeness.ignore.ignore(a: object, b: object) float
Ignores the input parameters and returns 1. A helper function to use in LikenessMixin if you don’t want a comparison to take place for a certain attribute.
- Parameters:
a (object) – The first input parameter. This parameter is ignored.
b (object) – The second input parameter. This parameter is ignored.
- Returns:
The function always returns 1.
- Return type:
float
- likeness.likeness.likeness(a: LikenessMixin, b: LikenessMixin) float
Calculate the likeness between two objects of type LikenessMixin.
- Parameters:
a (LikenessMixin) – The first object to compare.
b (LikenessMixin) – The second object to compare.
- Returns:
The likeness between the two objects, calculated by calling the like method of the first object with the second object as the argument.
- Return type:
float