You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
602 B

3 years ago
3 years ago
  1. from typing import Dict, List, Optional
  2. from .label import Label
  3. class Labels:
  4. def __init__(self, labels: List[Label]):
  5. self.labels = labels
  6. def replace_label(self, mapping: Optional[Dict[str, int]] = None):
  7. if not mapping:
  8. return self
  9. labels = []
  10. for label in self.labels:
  11. try:
  12. label = label.replace(mapping)
  13. labels.append(label)
  14. except KeyError:
  15. pass
  16. return Labels(labels)
  17. def dict(self) -> List[dict]:
  18. return [label.dict() for label in self.labels]