-
Notifications
You must be signed in to change notification settings - Fork 0
/
LabelUtilities.py
36 lines (24 loc) · 899 Bytes
/
LabelUtilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from abc import ABC, abstractmethod
class LabelMaker:
def __init__(self, names: [str]):
self.__names = names
self.__labels = {}
for name in self.__names:
self.__labels[name] = False
def toggle(self, name: str):
self.__labels[name] = not self.__labels[name]
@property
def label(self) -> dict:
return self.__labels.copy()
class LabelFormatterInterface(ABC):
@abstractmethod
def getFormattedLabel(self, label: dict) -> str:
pass
class ListPositionalLabelFormatter(LabelFormatterInterface):
def __init__(self, positionedNames: [str]):
self.__positionedNames = positionedNames
def getFormattedLabel(self, label: dict) -> str:
formattedLabel = []
for name in self.__positionedNames:
formattedLabel.append(1 if label[name] else 0)
return str(formattedLabel)