From afb97b5db0e941ebafdb5b61a45da9f3efb79515 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Wed, 7 Apr 2021 08:11:15 +0900 Subject: [PATCH] Add labels --- app/api/views/upload/labels.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 app/api/views/upload/labels.py diff --git a/app/api/views/upload/labels.py b/app/api/views/upload/labels.py new file mode 100644 index 00000000..37fac1cc --- /dev/null +++ b/app/api/views/upload/labels.py @@ -0,0 +1,18 @@ +from typing import Dict, List, Optional + +from .label import Label + + +class Labels: + + def __init__(self, labels: List[Label]): + self.labels = labels + + def replace_label(self, mapping: Optional[Dict[str, int]] = None): + if not mapping: + return self + labels = [label.replace(mapping) for label in self.labels] + return Labels(labels) + + def dict(self) -> List[dict]: + return [label.dict() for label in self.labels]