Browse Source

Add is_text_project property to Project model

pull/1632/head
Hironsan 3 years ago
parent
commit
fae65162ef
2 changed files with 24 additions and 15 deletions
  1. 35
      backend/api/models.py
  2. 4
      backend/api/views/auto_labeling.py

35
backend/api/models.py

@ -1,3 +1,4 @@
import abc
import random import random
import string import string
import uuid import uuid
@ -39,7 +40,9 @@ class Project(PolymorphicModel):
collaborative_annotation = models.BooleanField(default=False) collaborative_annotation = models.BooleanField(default=False)
single_class_classification = models.BooleanField(default=False) single_class_classification = models.BooleanField(default=False)
def is_task_of(self, task: Literal['text', 'image', 'speech']):
@property
@abc.abstractmethod
def is_text_project(self) -> bool:
raise NotImplementedError() raise NotImplementedError()
def __str__(self): def __str__(self):
@ -48,40 +51,46 @@ class Project(PolymorphicModel):
class TextClassificationProject(Project): class TextClassificationProject(Project):
def is_task_of(self, task: Literal['text', 'image', 'speech']):
return task == 'text'
@property
def is_text_project(self) -> bool:
return True
class SequenceLabelingProject(Project): class SequenceLabelingProject(Project):
allow_overlapping = models.BooleanField(default=False) allow_overlapping = models.BooleanField(default=False)
grapheme_mode = models.BooleanField(default=False) grapheme_mode = models.BooleanField(default=False)
def is_task_of(self, task: Literal['text', 'image', 'speech']):
return task == 'text'
@property
def is_text_project(self) -> bool:
return True
class Seq2seqProject(Project): class Seq2seqProject(Project):
def is_task_of(self, task: Literal['text', 'image', 'speech']):
return task == 'text'
@property
def is_text_project(self) -> bool:
return True
class IntentDetectionAndSlotFillingProject(Project): class IntentDetectionAndSlotFillingProject(Project):
def is_task_of(self, task: Literal['text', 'image', 'speech']):
return task == 'text'
@property
def is_text_project(self) -> bool:
return True
class Speech2textProject(Project): class Speech2textProject(Project):
def is_task_of(self, task: Literal['text', 'image', 'speech']):
return task == 'speech'
@property
def is_text_project(self) -> bool:
return False
class ImageClassificationProject(Project): class ImageClassificationProject(Project):
def is_task_of(self, task: Literal['text', 'image', 'speech']):
return task == 'image'
@property
def is_text_project(self) -> bool:
return False
def generate_random_hex_color(): def generate_random_hex_color():

4
backend/api/views/auto_labeling.py

@ -142,7 +142,7 @@ class AutoLabelingConfigParameterTest(APIView):
def prepare_example(self): def prepare_example(self):
text = self.request.data['text'] text = self.request.data['text']
if self.project.is_task_of('text'):
if self.project.is_text_project:
return text return text
else: else:
tu = TemporaryUpload.objects.get(upload_id=text) tu = TemporaryUpload.objects.get(upload_id=text)
@ -221,7 +221,7 @@ class AutoLabelingAnnotation(generics.CreateAPIView):
def get_example(self, project): def get_example(self, project):
example = get_object_or_404(Example, pk=self.kwargs['example_id']) example = get_object_or_404(Example, pk=self.kwargs['example_id'])
if project.is_task_of('text'):
if project.is_text_project:
return example.text return example.text
else: else:
return str(example.filename) return str(example.filename)

Loading…
Cancel
Save