Browse Source

Remove unused properties from Project model

pull/2093/head
Hironsan 2 years ago
parent
commit
0aa24a8d16
4 changed files with 50 additions and 103 deletions
  1. 72
      backend/projects/models.py
  2. 8
      backend/projects/serializers.py
  3. 63
      frontend/domain/models/project/project.ts
  4. 10
      frontend/repositories/project/apiProjectRepository.ts

72
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

8
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):

63
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]
}

10
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
)
}

Loading…
Cancel
Save