Browse Source

Add can_define_label method to project model

pull/1632/head
Hironsan 2 years ago
parent
commit
80074942a9
3 changed files with 41 additions and 11 deletions
  1. 29
      backend/api/models.py
  2. 2
      backend/api/serializers.py
  3. 21
      frontend/domain/models/project/project.ts

29
backend/api/models.py

@ -45,6 +45,11 @@ class Project(PolymorphicModel):
def is_text_project(self) -> bool:
return False
@property
@abc.abstractmethod
def can_define_label(self) -> bool:
return False
def __str__(self):
return self.name
@ -55,6 +60,10 @@ class TextClassificationProject(Project):
def is_text_project(self) -> bool:
return True
@property
def can_define_label(self) -> bool:
return True
class SequenceLabelingProject(Project):
allow_overlapping = models.BooleanField(default=False)
@ -64,6 +73,10 @@ class SequenceLabelingProject(Project):
def is_text_project(self) -> bool:
return True
@property
def can_define_label(self) -> bool:
return True
class Seq2seqProject(Project):
@ -71,6 +84,10 @@ class Seq2seqProject(Project):
def is_text_project(self) -> bool:
return True
@property
def can_define_label(self) -> bool:
return False
class IntentDetectionAndSlotFillingProject(Project):
@ -78,6 +95,10 @@ class IntentDetectionAndSlotFillingProject(Project):
def is_text_project(self) -> bool:
return True
@property
def can_define_label(self) -> bool:
return True
class Speech2textProject(Project):
@ -85,6 +106,10 @@ class Speech2textProject(Project):
def is_text_project(self) -> bool:
return False
@property
def can_define_label(self) -> bool:
return False
class ImageClassificationProject(Project):
@ -92,6 +117,10 @@ class ImageClassificationProject(Project):
def is_text_project(self) -> bool:
return False
@property
def can_define_label(self) -> bool:
return True
def generate_random_hex_color():
return f'#{random.randint(0, 0xFFFFFF):06x}'

2
backend/api/serializers.py

@ -174,12 +174,14 @@ class ProjectSerializer(serializers.ModelSerializer):
'collaborative_annotation',
'single_class_classification',
'is_text_project',
'can_define_label',
'tags'
)
read_only_fields = (
'updated_at',
'users',
'is_text_project',
'can_define_label',
'tags'
)

21
frontend/domain/models/project/project.ts

@ -18,6 +18,7 @@ export class ProjectReadItem {
public grapheme_mode: boolean,
public tags: Object[],
public is_text_project: boolean,
public can_define_label: boolean,
) {}
static valueOf(
@ -36,7 +37,8 @@ export class ProjectReadItem {
allow_overlapping,
grapheme_mode,
tags,
is_text_project
is_text_project,
can_define_label,
}:
{
id: number,
@ -53,7 +55,8 @@ export class ProjectReadItem {
allow_overlapping: boolean,
grapheme_mode: boolean,
tags: Object[],
is_text_project: boolean
is_text_project: boolean,
can_define_label: boolean
}
): ProjectReadItem {
return new ProjectReadItem(
@ -71,7 +74,8 @@ export class ProjectReadItem {
allow_overlapping,
grapheme_mode,
tags,
is_text_project
is_text_project,
can_define_label
)
}
@ -89,13 +93,7 @@ export class ProjectReadItem {
}
get canDefineLabel() {
const allowedProjectTypes = [
'DocumentClassification',
'SequenceLabeling',
'IntentDetectionAndSlotFilling',
'ImageClassification'
]
return allowedProjectTypes.includes(this.project_type)
return this.can_define_label
}
get canDefineRelation() {
@ -142,7 +140,8 @@ export class ProjectReadItem {
allow_overlapping: this.allow_overlapping,
grapheme_mode: this.grapheme_mode,
tags: this.tags,
is_text_project: this.is_text_project
is_text_project: this.is_text_project,
can_define_label: this.can_define_label
}
}
}

Loading…
Cancel
Save