Skip to content

factory

  • Name: cognitivefactory.interactive_clustering.constraints.factory
  • Description: The factory method used to easily initialize a constraints manager.
  • Author: Erwan SCHILD
  • Created: 17/03/2021
  • Licence: CeCILL-C License v1.0 (https://cecill.info/licences.fr.html)

managing_factory(list_of_data_IDs, manager='binary', **kargs)

A factory to create a new instance of a constraints manager.

Parameters:

Name Type Description Default
list_of_data_IDs List[str]

The list of data IDs to manage.

required
manager str

The identification of constraints manager to instantiate. Can be "binary". Defaults to "binary".

'binary'
**kargs dict

Other parameters that can be used in the instantiation.

{}

Raises:

Type Description
ValueError

if manager is not implemented.

Returns:

Name Type Description
AbstractConstraintsManager AbstractConstraintsManager

An instance of constraints manager.

Example
# Import.
from cognitivefactory.interactive_clustering.constraints.factory import managing_factory

# Create an instance of binary constraints manager.
constraints_manager = managing_factory(
    list_of_data_IDs=["0", "1", "2", "3", "4"],
    manager="binary",
)
Source code in src\cognitivefactory\interactive_clustering\constraints\factory.py
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
def managing_factory(list_of_data_IDs: List[str], manager: str = "binary", **kargs) -> AbstractConstraintsManager:
    """
    A factory to create a new instance of a constraints manager.

    Args:
        list_of_data_IDs (List[str]): The list of data IDs to manage.
        manager (str, optional): The identification of constraints manager to instantiate. Can be "binary". Defaults to `"binary"`.
        **kargs (dict): Other parameters that can be used in the instantiation.

    Raises:
        ValueError: if `manager` is not implemented.

    Returns:
        AbstractConstraintsManager : An instance of constraints manager.

    Example:
        ```python
        # Import.
        from cognitivefactory.interactive_clustering.constraints.factory import managing_factory

        # Create an instance of binary constraints manager.
        constraints_manager = managing_factory(
            list_of_data_IDs=["0", "1", "2", "3", "4"],
            manager="binary",
        )
        ```
    """

    # Check that the requested algorithm is implemented.
    if manager != "binary":  # TODO use `not in {"binary"}`.
        raise ValueError("The `manager` '" + str(manager) + "' is not implemented.")

    # Case of Binary Constraints Manager
    ## if manager=="binary":

    return BinaryConstraintsManager(list_of_data_IDs=list_of_data_IDs, **kargs)