diff --git a/backend/projects/models.py b/backend/projects/models.py index 7722a369..5023a953 100644 --- a/backend/projects/models.py +++ b/backend/projects/models.py @@ -60,26 +60,6 @@ class Project(PolymorphicModel): def is_text_project(self) -> bool: return False - @property - def can_define_label(self) -> bool: - """Whether or not the project can define label(ignoring the type of label)""" - return False - - @property - def can_define_relation(self) -> bool: - """Whether or not the project can define relation.""" - return False - - @property - def can_define_category(self) -> bool: - """Whether or not the project can define category.""" - return False - - @property - def can_define_span(self) -> bool: - """Whether or not the project can define span.""" - return False - def __str__(self): return self.name @@ -89,14 +69,6 @@ class TextClassificationProject(Project): def is_text_project(self) -> bool: return True - @property - def can_define_label(self) -> bool: - return True - - @property - def can_define_category(self) -> bool: - return True - class SequenceLabelingProject(Project): allow_overlapping = models.BooleanField(default=False) @@ -107,14 +79,6 @@ class SequenceLabelingProject(Project): def is_text_project(self) -> bool: return True - @property - def can_define_label(self) -> bool: - return True - - @property - def can_define_span(self) -> bool: - return True - class Seq2seqProject(Project): @property @@ -127,18 +91,6 @@ class IntentDetectionAndSlotFillingProject(Project): def is_text_project(self) -> bool: return True - @property - def can_define_label(self) -> bool: - return True - - @property - def can_define_category(self) -> bool: - return True - - @property - def can_define_span(self) -> bool: - return True - class Speech2textProject(Project): @property @@ -151,42 +103,18 @@ class ImageClassificationProject(Project): def is_text_project(self) -> bool: return False - @property - def can_define_label(self) -> bool: - return True - - @property - def can_define_category(self) -> bool: - return True - class BoundingBoxProject(Project): @property def is_text_project(self) -> bool: return False - @property - def can_define_label(self) -> bool: - return True - - @property - def can_define_category(self) -> bool: - return True - class SegmentationProject(Project): @property def is_text_project(self) -> bool: return False - @property - def can_define_label(self) -> bool: - return True - - @property - def can_define_category(self) -> bool: - return True - class ImageCaptioningProject(Project): @property diff --git a/backend/projects/serializers.py b/backend/projects/serializers.py index d117b590..3f8b09bc 100644 --- a/backend/projects/serializers.py +++ b/backend/projects/serializers.py @@ -72,10 +72,6 @@ class ProjectSerializer(serializers.ModelSerializer): "collaborative_annotation", "single_class_classification", "is_text_project", - "can_define_label", - "can_define_relation", - "can_define_category", - "can_define_span", "tags", ] read_only_fields = ( @@ -83,10 +79,6 @@ class ProjectSerializer(serializers.ModelSerializer): "updated_at", "author", "is_text_project", - "can_define_label", - "can_define_relation", - "can_define_category", - "can_define_span", ) def create(self, validated_data): diff --git a/frontend/domain/models/project/project.ts b/frontend/domain/models/project/project.ts index 34a59cb8..dfb214a8 100644 --- a/frontend/domain/models/project/project.ts +++ b/frontend/domain/models/project/project.ts @@ -1,13 +1,23 @@ +const DocumentClassification = 'DocumentClassification' +const SequenceLabeling = 'SequenceLabeling' +const Seq2seq = 'Seq2seq' +const IntentDetectionAndSlotFilling = 'IntentDetectionAndSlotFilling' +const ImageClassification = 'ImageClassification' +const ImageCaptioning = 'ImageCaptioning' +const BoundingBox = 'BoundingBox' +const Segmentation = 'Segmentation' +const Speech2text = 'Speech2text' + export type ProjectType = - | 'DocumentClassification' - | 'SequenceLabeling' - | 'Seq2seq' - | 'IntentDetectionAndSlotFilling' - | 'ImageClassification' - | 'ImageCaptioning' - | 'BoundingBox' - | 'Segmentation' - | 'Speech2text' + | typeof DocumentClassification + | typeof SequenceLabeling + | typeof Seq2seq + | typeof IntentDetectionAndSlotFilling + | typeof ImageClassification + | typeof ImageCaptioning + | typeof BoundingBox + | typeof Segmentation + | typeof Speech2text export class ProjectReadItem { constructor( @@ -28,16 +38,37 @@ export class ProjectReadItem { readonly allowOverlapping: boolean, readonly graphemeMode: boolean, readonly useRelation: boolean, - readonly isTextProject: boolean, - readonly canDefineLabel: boolean, - readonly canDefineRelation: boolean, - readonly canDefineSpan: boolean, - readonly canDefineCategory: boolean + readonly isTextProject: boolean ) {} + get canDefineLabel(): boolean { + return this.canDefineCategory || this.canDefineSpan + } + + get canDefineCategory(): boolean { + return ( + this.projectType in + [ + DocumentClassification, + IntentDetectionAndSlotFilling, + ImageClassification, + BoundingBox, + Segmentation + ] + ) + } + + get canDefineSpan(): boolean { + return this.projectType in [SequenceLabeling, IntentDetectionAndSlotFilling] + } + + get canDefineRelation(): boolean { + return this.useRelation + } + get taskNames(): string[] { - if (this.projectType === 'IntentDetectionAndSlotFilling') { - return ['DocumentClassification', 'SequenceLabeling'] + if (this.projectType === IntentDetectionAndSlotFilling) { + return [DocumentClassification, SequenceLabeling] } return [this.projectType] } diff --git a/frontend/repositories/project/apiProjectRepository.ts b/frontend/repositories/project/apiProjectRepository.ts index 22a20832..17495db9 100644 --- a/frontend/repositories/project/apiProjectRepository.ts +++ b/frontend/repositories/project/apiProjectRepository.ts @@ -1,6 +1,6 @@ -import ApiService from '@/services/api.service' +import { ProjectItemList, ProjectReadItem, ProjectWriteItem } from '@/domain/models/project/project' import { ProjectRepository, SearchQuery } from '@/domain/models/project/projectRepository' -import { ProjectReadItem, ProjectWriteItem, ProjectItemList } from '@/domain/models/project/project' +import ApiService from '@/services/api.service' function toModel(item: { [key: string]: any }): ProjectReadItem { return new ProjectReadItem( @@ -21,11 +21,7 @@ function toModel(item: { [key: string]: any }): ProjectReadItem { item.allow_overlapping, item.grapheme_mode, item.use_relation, - item.is_text_project, - item.can_define_label, - item.can_define_relation, - item.can_define_span, - item.can_define_category + item.is_text_project ) }