mirror of https://github.com/doccano/doccano.git
pythonannotation-tooldatasetsactive-learningtext-annotationdatasetnatural-language-processingdata-labelingmachine-learning
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.
21 lines
601 B
21 lines
601 B
from typing import Dict, List
|
|
|
|
from pydantic import UUID4
|
|
|
|
from examples.models import Example
|
|
|
|
|
|
class Examples:
|
|
def __init__(self, examples: List[Example]):
|
|
self.examples = examples
|
|
self.uuid_to_example: Dict[UUID4, Example] = {}
|
|
|
|
def __getitem__(self, uuid: UUID4) -> Example:
|
|
return self.uuid_to_example[uuid]
|
|
|
|
def __contains__(self, uuid: UUID4) -> bool:
|
|
return uuid in self.uuid_to_example
|
|
|
|
def save(self):
|
|
examples = Example.objects.bulk_create(self.examples)
|
|
self.uuid_to_example = {example.uuid: example for example in examples}
|