You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.7 KiB

  1. import "reflect-metadata"
  2. import { Expose, Type } from 'class-transformer'
  3. export type ProjectType = 'DocumentClassification' | 'SequenceLabeling' | 'Seq2seq' | 'IntentDetectionAndSlotFilling' | 'ImageClassification' | 'Speech2text'
  4. export class ProjectReadItem {
  5. id: number;
  6. name: string;
  7. description: string;
  8. guideline: string;
  9. users: number[];
  10. tags: Object[];
  11. @Expose({ name: 'project_type' })
  12. projectType: ProjectType;
  13. @Expose({ name: 'updated_at' })
  14. updatedAt: string;
  15. @Expose({ name: 'random_order' })
  16. randomOrder: boolean;
  17. @Expose({ name: 'collaborative_annotation' })
  18. collaborative_annotation: boolean;
  19. @Expose({ name: 'single_class_classification' })
  20. exclusiveCategories: boolean;
  21. @Expose({ name: 'resourcetype' })
  22. resourceType: string;
  23. @Expose({ name: 'allow_overlapping' })
  24. allowOverlapping: boolean;
  25. @Expose({ name: 'grapheme_mode' })
  26. graphemeMode: boolean;
  27. @Expose({ name: 'is_text_project'})
  28. isTextProject: boolean;
  29. @Expose({ name: 'can_define_label' })
  30. canDefineLabel: boolean;
  31. @Expose({ name: 'can_define_relation' })
  32. canDefineRelation: boolean;
  33. @Expose({ name: 'can_define_span'})
  34. canDefineSpan: boolean;
  35. @Expose({ name: 'can_define_category' })
  36. canDefineCategory: boolean;
  37. get annotationPageLink(): string {
  38. const mapping = {
  39. DocumentClassification: 'text-classification',
  40. SequenceLabeling : 'sequence-labeling',
  41. Seq2seq : 'sequence-to-sequence',
  42. IntentDetectionAndSlotFilling: 'intent-detection-and-slot-filling',
  43. ImageClassification : 'image-classification',
  44. Speech2text : 'speech-to-text',
  45. }
  46. const url = `/projects/${this.id}/${mapping[this.projectType]}`
  47. return url
  48. }
  49. get taskNames(): string[] {
  50. if (this.projectType === 'IntentDetectionAndSlotFilling') {
  51. return [
  52. 'DocumentClassification',
  53. 'SequenceLabeling',
  54. ]
  55. }
  56. return [this.projectType]
  57. }
  58. }
  59. export class ProjectItemList {
  60. count: number;
  61. next: string | null;
  62. prev: string | null;
  63. @Type(() => ProjectReadItem)
  64. @Expose({ name: 'results' })
  65. items: ProjectReadItem[];
  66. }
  67. export class ProjectWriteItem {
  68. constructor(
  69. public id: number,
  70. public name: string,
  71. public description: string,
  72. public guideline: string,
  73. public project_type: ProjectType,
  74. public random_order: boolean,
  75. public collaborative_annotation: boolean,
  76. public single_class_classification: boolean,
  77. public allow_overlapping: boolean,
  78. public grapheme_mode: boolean
  79. ) {}
  80. get resourceType(): string {
  81. const mapping = {
  82. DocumentClassification: 'TextClassificationProject',
  83. SequenceLabeling : 'SequenceLabelingProject',
  84. Seq2seq : 'Seq2seqProject',
  85. IntentDetectionAndSlotFilling: 'IntentDetectionAndSlotFillingProject',
  86. ImageClassification : 'ImageClassificationProject',
  87. Speech2text : 'Speech2textProject',
  88. }
  89. return mapping[this.project_type]
  90. }
  91. toObject(): Object {
  92. return {
  93. id: this.id,
  94. name: this.name,
  95. description: this.description,
  96. guideline: this.guideline,
  97. project_type: this.project_type,
  98. random_order: this.random_order,
  99. collaborative_annotation: this.collaborative_annotation,
  100. single_class_classification: this.single_class_classification,
  101. allow_overlapping: this.allow_overlapping,
  102. grapheme_mode: this.grapheme_mode,
  103. resourcetype: this.resourceType
  104. }
  105. }
  106. }