mirror of https://github.com/doccano/doccano.git
pythondatasetsactive-learningtext-annotationdatasetnatural-language-processingdata-labelingmachine-learningannotation-tool
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
24 lines
602 B
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 = []
|
|
for label in self.labels:
|
|
try:
|
|
label = label.replace(mapping)
|
|
labels.append(label)
|
|
except KeyError:
|
|
pass
|
|
return Labels(labels)
|
|
|
|
def dict(self) -> List[dict]:
|
|
return [label.dict() for label in self.labels]
|