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.

177 lines
4.9 KiB

3 years ago
  1. import { FormatFactory, FormatItem } from './format'
  2. export interface CurrentUsersRole {
  3. is_project_admin: boolean;
  4. is_annotator: boolean;
  5. is_annotation_approver: boolean;
  6. }
  7. export type ProjectType = 'DocumentClassification' | 'SequenceLabeling' | 'Seq2seq'
  8. export class ProjectReadItem {
  9. constructor(
  10. public id: number,
  11. public name: string,
  12. public description: string,
  13. public guideline: string,
  14. public users: number[],
  15. public current_users_role: CurrentUsersRole,
  16. public project_type: ProjectType,
  17. public updated_at: string,
  18. public randomize_document_order: boolean,
  19. public collaborative_annotation: boolean,
  20. public single_class_classification: boolean,
  21. public resourcetype: string,
  22. ) {}
  23. static valueOf(
  24. {
  25. id,
  26. name,
  27. description,
  28. guideline,
  29. users,
  30. current_users_role,
  31. project_type,
  32. updated_at,
  33. randomize_document_order,
  34. collaborative_annotation,
  35. single_class_classification,
  36. resourcetype
  37. }:
  38. {
  39. id: number,
  40. name: string,
  41. description: string,
  42. guideline: string,
  43. users: number[],
  44. current_users_role: CurrentUsersRole,
  45. project_type: ProjectType,
  46. updated_at: string,
  47. randomize_document_order: boolean,
  48. collaborative_annotation: boolean,
  49. single_class_classification: boolean,
  50. resourcetype: string
  51. }
  52. ): ProjectReadItem {
  53. return new ProjectReadItem(
  54. id,
  55. name,
  56. description,
  57. guideline,
  58. users,
  59. current_users_role,
  60. project_type,
  61. updated_at,
  62. randomize_document_order,
  63. collaborative_annotation,
  64. single_class_classification,
  65. resourcetype
  66. )
  67. }
  68. get annotationPageLink(): string {
  69. const mapping = {
  70. DocumentClassification: 'text-classification',
  71. SequenceLabeling : 'sequence-labeling',
  72. Seq2seq : 'sequence-to-sequence'
  73. }
  74. const url = `/projects/${this.id}/${mapping[this.project_type]}`
  75. return url
  76. }
  77. get downloadFormats(): FormatItem[] {
  78. return new FormatFactory(this.project_type).createDownloadFormat()
  79. }
  80. get uploadFormats(): FormatItem[] {
  81. return new FormatFactory(this.project_type).createUploadFormat()
  82. }
  83. get permitApprove(): Boolean {
  84. const role = this.current_users_role
  85. return role && !role.is_annotator
  86. }
  87. toObject(): Object {
  88. return {
  89. id: this.id,
  90. name: this.name,
  91. description: this.description,
  92. guideline: this.guideline,
  93. users: this.users,
  94. current_users_role: this.current_users_role,
  95. project_type: this.project_type,
  96. updated_at: this.updated_at,
  97. randomize_document_order: this.randomize_document_order,
  98. collaborative_annotation: this.collaborative_annotation,
  99. single_class_classification: this.single_class_classification,
  100. resourcetype: this.resourcetype
  101. }
  102. }
  103. }
  104. export class ProjectWriteItem {
  105. constructor(
  106. public id: number,
  107. public name: string,
  108. public description: string,
  109. public guideline: string,
  110. public project_type: ProjectType,
  111. public randomize_document_order: boolean,
  112. public collaborative_annotation: boolean
  113. ) {}
  114. static valueOf(
  115. {
  116. id,
  117. name,
  118. description,
  119. guideline,
  120. project_type,
  121. randomize_document_order,
  122. collaborative_annotation,
  123. }:
  124. {
  125. id: number,
  126. name: string,
  127. description: string,
  128. guideline: string,
  129. project_type: ProjectType,
  130. randomize_document_order: boolean,
  131. collaborative_annotation: boolean
  132. }
  133. ): ProjectWriteItem {
  134. return new ProjectWriteItem(
  135. id,
  136. name,
  137. description,
  138. guideline,
  139. project_type,
  140. randomize_document_order,
  141. collaborative_annotation,
  142. )
  143. }
  144. get resourceType(): string {
  145. const mapping = {
  146. DocumentClassification: 'TextClassificationProject',
  147. SequenceLabeling : 'SequenceLabelingProject',
  148. Seq2seq : 'Seq2seqProject'
  149. }
  150. return mapping[this.project_type]
  151. }
  152. toObject(): Object {
  153. return {
  154. id: this.id,
  155. name: this.name,
  156. description: this.description,
  157. guideline: this.guideline,
  158. project_type: this.project_type,
  159. randomize_document_order: this.randomize_document_order,
  160. collaborative_annotation: this.collaborative_annotation,
  161. resourcetype: this.resourceType
  162. }
  163. }
  164. }