Skip to content

base

BaseModel

Bases: ABC

Base class for all recnexteval components.

Provides common properties like name and universal IS_BASE flag.

Source code in src/recnexteval/models/base.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class BaseModel(ABC):
    """Base class for all recnexteval components.

    Provides common properties like name and universal IS_BASE flag.
    """

    IS_BASE: bool = True

    @property
    def name(self) -> str:
        """Name of the object's class.

        :return: Name of the object's class
        :rtype: str
        """
        return self.__class__.__name__

IS_BASE = True class-attribute instance-attribute

name property

Name of the object's class.

:return: Name of the object's class :rtype: str

ParamMixin

Bases: ABC

Mixin class for all recnexteval components with parameters.

Provides common properties like name, params, and identifier.

Source code in src/recnexteval/models/base.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class ParamMixin(ABC):
    """Mixin class for all recnexteval components with parameters.

    Provides common properties like name, params, and identifier.
    """

    @property
    def name(self) -> str:
        """Name of the object's class.

        :return: Name of the object's class
        :rtype: str
        """
        return self.__class__.__name__

    @abstractmethod
    def get_params(self) -> dict[str, Any]:
        """Get the parameters of the object.

        :return: Parameters of the object
        :rtype: dict
        """
        ...

    @property
    def params(self) -> dict[str, Any]:
        """Parameters of the object.

        :return: Parameters of the object
        :rtype: dict
        """
        return self.get_params()

    @property
    def identifier(self) -> str:
        """Identifier of the object.

        Identifier is made by combining the class name with the parameters
        passed at construction time.

        Constructed by recreating the initialisation call.
        Example: `Algorithm(param_1=value)`

        :return: Identifier of the object
        """
        paramstring = ",".join((f"{k}={v}" for k, v in self.get_params().items()))
        return self.name + "(" + paramstring + ")"

name property

Name of the object's class.

:return: Name of the object's class :rtype: str

params property

Parameters of the object.

:return: Parameters of the object :rtype: dict

identifier property

Identifier of the object.

Identifier is made by combining the class name with the parameters passed at construction time.

Constructed by recreating the initialisation call. Example: Algorithm(param_1=value)

:return: Identifier of the object

get_params() abstractmethod

Get the parameters of the object.

:return: Parameters of the object :rtype: dict

Source code in src/recnexteval/models/base.py
38
39
40
41
42
43
44
45
@abstractmethod
def get_params(self) -> dict[str, Any]:
    """Get the parameters of the object.

    :return: Parameters of the object
    :rtype: dict
    """
    ...