diff --git a/backend/api/models.py b/backend/api/models.py index e79288e4..9ba82249 100644 --- a/backend/api/models.py +++ b/backend/api/models.py @@ -2,7 +2,6 @@ import abc import random import string import uuid -from typing import Literal from auto_labeling_pipeline.models import RequestModelFactory from django.contrib.auth.models import User @@ -46,8 +45,23 @@ class Project(PolymorphicModel): return False @property - @abc.abstractmethod 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): @@ -64,6 +78,10 @@ class TextClassificationProject(Project): 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) @@ -77,6 +95,10 @@ class SequenceLabelingProject(Project): def can_define_label(self) -> bool: return True + @property + def can_define_span(self) -> bool: + return True + class Seq2seqProject(Project): @@ -84,10 +106,6 @@ class Seq2seqProject(Project): def is_text_project(self) -> bool: return True - @property - def can_define_label(self) -> bool: - return False - class IntentDetectionAndSlotFillingProject(Project): @@ -99,6 +117,14 @@ class IntentDetectionAndSlotFillingProject(Project): 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): @@ -106,10 +132,6 @@ class Speech2textProject(Project): def is_text_project(self) -> bool: return False - @property - def can_define_label(self) -> bool: - return False - class ImageClassificationProject(Project): @@ -121,6 +143,10 @@ class ImageClassificationProject(Project): def can_define_label(self) -> bool: return True + @property + def can_define_category(self) -> bool: + return True + def generate_random_hex_color(): return f'#{random.randint(0, 0xFFFFFF):06x}' diff --git a/backend/api/serializers.py b/backend/api/serializers.py index c09b4b66..c4f00c0b 100644 --- a/backend/api/serializers.py +++ b/backend/api/serializers.py @@ -175,6 +175,9 @@ class ProjectSerializer(serializers.ModelSerializer): 'single_class_classification', 'is_text_project', 'can_define_label', + 'can_define_relation', + 'can_define_category', + 'can_define_span', 'tags' ) read_only_fields = ( @@ -182,6 +185,9 @@ class ProjectSerializer(serializers.ModelSerializer): 'users', 'is_text_project', 'can_define_label', + 'can_define_relation', + 'can_define_category', + 'can_define_span', 'tags' ) diff --git a/frontend/domain/models/project/project.ts b/frontend/domain/models/project/project.ts index 01bb21ee..a6f70048 100644 --- a/frontend/domain/models/project/project.ts +++ b/frontend/domain/models/project/project.ts @@ -19,6 +19,9 @@ export class ProjectReadItem { public tags: Object[], public is_text_project: boolean, public can_define_label: boolean, + public can_define_relation: boolean, + public can_define_span: boolean, + public can_define_category: boolean, ) {} static valueOf( @@ -39,6 +42,9 @@ export class ProjectReadItem { tags, is_text_project, can_define_label, + can_define_relation, + can_define_span, + can_define_category, }: { id: number, @@ -56,7 +62,10 @@ export class ProjectReadItem { grapheme_mode: boolean, tags: Object[], is_text_project: boolean, - can_define_label: boolean + can_define_label: boolean, + can_define_relation: boolean, + can_define_span: boolean, + can_define_category: boolean } ): ProjectReadItem { return new ProjectReadItem( @@ -75,7 +84,10 @@ export class ProjectReadItem { grapheme_mode, tags, is_text_project, - can_define_label + can_define_label, + can_define_relation, + can_define_span, + can_define_category ) } @@ -97,10 +109,7 @@ export class ProjectReadItem { } get canDefineRelation() { - const allowedProjectTypes = [ - 'SequenceLabeling' - ] - return allowedProjectTypes.includes(this.project_type) + return this.can_define_relation } get isTextProject() { @@ -108,41 +117,11 @@ export class ProjectReadItem { } get hasCategory(): boolean { - const allowedProjectTypes = [ - 'DocumentClassification', - 'IntentDetectionAndSlotFilling', - 'ImageClassification' - ] - return allowedProjectTypes.includes(this.project_type) + return this.can_define_category } get hasSpan(): boolean { - const allowedProjectTypes = [ - 'IntentDetectionAndSlotFilling', - 'SequenceLabeling' - ] - return allowedProjectTypes.includes(this.project_type) - } - - toObject(): Object { - return { - id: this.id, - name: this.name, - description: this.description, - guideline: this.guideline, - users: this.users, - project_type: this.project_type, - updated_at: this.updated_at, - random_order: this.random_order, - collaborative_annotation: this.collaborative_annotation, - single_class_classification: this.single_class_classification, - resourcetype: this.resourcetype, - allow_overlapping: this.allow_overlapping, - grapheme_mode: this.grapheme_mode, - tags: this.tags, - is_text_project: this.is_text_project, - can_define_label: this.can_define_label - } + return this.can_define_span } }