Coverage for src\cognitivefactory\interactive_clustering\constraints\factory.py: 100.00%
8 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-17 13:31 +0100
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-17 13:31 +0100
1# -*- coding: utf-8 -*-
3"""
4* Name: cognitivefactory.interactive_clustering.constraints.factory
5* Description: The factory method used to easily initialize a constraints manager.
6* Author: Erwan SCHILD
7* Created: 17/03/2021
8* Licence: CeCILL-C License v1.0 (https://cecill.info/licences.fr.html)
9"""
11# ==============================================================================
12# IMPORTS :
13# =============================================================================
15from typing import List
17from cognitivefactory.interactive_clustering.constraints.abstract import AbstractConstraintsManager
18from cognitivefactory.interactive_clustering.constraints.binary import BinaryConstraintsManager
21# ==============================================================================
22# MANAGING FACTORY :
23# ==============================================================================
24def managing_factory(list_of_data_IDs: List[str], manager: str = "binary", **kargs) -> AbstractConstraintsManager:
25 """
26 A factory to create a new instance of a constraints manager.
28 Args:
29 list_of_data_IDs (List[str]): The list of data IDs to manage.
30 manager (str, optional): The identification of constraints manager to instantiate. Can be "binary". Defaults to `"binary"`.
31 **kargs (dict): Other parameters that can be used in the instantiation.
33 Raises:
34 ValueError: if `manager` is not implemented.
36 Returns:
37 AbstractConstraintsManager : An instance of constraints manager.
39 Example:
40 ```python
41 # Import.
42 from cognitivefactory.interactive_clustering.constraints.factory import managing_factory
44 # Create an instance of binary constraints manager.
45 constraints_manager = managing_factory(
46 list_of_data_IDs=["0", "1", "2", "3", "4"],
47 manager="binary",
48 )
49 ```
50 """
52 # Check that the requested algorithm is implemented.
53 if manager != "binary": # TODO use `not in {"binary"}`.
54 raise ValueError("The `manager` '" + str(manager) + "' is not implemented.")
56 # Case of Binary Constraints Manager
57 ## if manager=="binary":
59 return BinaryConstraintsManager(list_of_data_IDs=list_of_data_IDs, **kargs)