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.

134 lines
3.9 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: 'use_relation' })
  28. useRelation: boolean;
  29. @Expose({ name: 'is_text_project'})
  30. isTextProject: boolean;
  31. @Expose({ name: 'can_define_label' })
  32. canDefineLabel: boolean;
  33. @Expose({ name: 'can_define_relation' })
  34. canDefineRelation: boolean;
  35. @Expose({ name: 'can_define_span'})
  36. canDefineSpan: boolean;
  37. @Expose({ name: 'can_define_category' })
  38. canDefineCategory: boolean;
  39. get annotationPageLink(): string {
  40. const mapping = {
  41. DocumentClassification: 'text-classification',
  42. SequenceLabeling : 'sequence-labeling',
  43. Seq2seq : 'sequence-to-sequence',
  44. IntentDetectionAndSlotFilling: 'intent-detection-and-slot-filling',
  45. ImageClassification : 'image-classification',
  46. Speech2text : 'speech-to-text',
  47. }
  48. const url = `/projects/${this.id}/${mapping[this.projectType]}`
  49. return url
  50. }
  51. get taskNames(): string[] {
  52. if (this.projectType === 'IntentDetectionAndSlotFilling') {
  53. return [
  54. 'DocumentClassification',
  55. 'SequenceLabeling',
  56. ]
  57. }
  58. return [this.projectType]
  59. }
  60. }
  61. export class ProjectItemList {
  62. count: number;
  63. next: string | null;
  64. prev: string | null;
  65. @Type(() => ProjectReadItem)
  66. @Expose({ name: 'results' })
  67. items: ProjectReadItem[];
  68. }
  69. export class ProjectWriteItem {
  70. constructor(
  71. public id: number,
  72. public name: string,
  73. public description: string,
  74. public guideline: string,
  75. public project_type: ProjectType,
  76. public random_order: boolean,
  77. public collaborative_annotation: boolean,
  78. public single_class_classification: boolean,
  79. public allow_overlapping: boolean,
  80. public grapheme_mode: boolean,
  81. public use_relation: boolean,
  82. ) {}
  83. get resourceType(): string {
  84. const mapping = {
  85. DocumentClassification: 'TextClassificationProject',
  86. SequenceLabeling : 'SequenceLabelingProject',
  87. Seq2seq : 'Seq2seqProject',
  88. IntentDetectionAndSlotFilling: 'IntentDetectionAndSlotFillingProject',
  89. ImageClassification : 'ImageClassificationProject',
  90. Speech2text : 'Speech2textProject',
  91. }
  92. return mapping[this.project_type]
  93. }
  94. toObject(): Object {
  95. return {
  96. id: this.id,
  97. name: this.name,
  98. description: this.description,
  99. guideline: this.guideline,
  100. project_type: this.project_type,
  101. random_order: this.random_order,
  102. collaborative_annotation: this.collaborative_annotation,
  103. single_class_classification: this.single_class_classification,
  104. allow_overlapping: this.allow_overlapping,
  105. grapheme_mode: this.grapheme_mode,
  106. use_relation: this.use_relation,
  107. resourcetype: this.resourceType
  108. }
  109. }
  110. }