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.

194 lines
5.5 KiB

4 years ago
  1. import { FormatFactory, FormatItem } from '../document/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. get filterOption() {
  88. if (this.project_type === 'DocumentClassification') {
  89. return 'doc_annotations__isnull'
  90. } else if (this.project_type === 'SequenceLabeling') {
  91. return 'seq_annotations__isnull'
  92. } else if (this.project_type === 'Seq2seq') {
  93. return 'seq2seq_annotations__isnull'
  94. } else {
  95. return ''
  96. }
  97. }
  98. toObject(): Object {
  99. return {
  100. id: this.id,
  101. name: this.name,
  102. description: this.description,
  103. guideline: this.guideline,
  104. users: this.users,
  105. current_users_role: this.current_users_role,
  106. project_type: this.project_type,
  107. updated_at: this.updated_at,
  108. randomize_document_order: this.randomize_document_order,
  109. collaborative_annotation: this.collaborative_annotation,
  110. single_class_classification: this.single_class_classification,
  111. resourcetype: this.resourcetype
  112. }
  113. }
  114. }
  115. export class ProjectWriteItem {
  116. constructor(
  117. public id: number,
  118. public name: string,
  119. public description: string,
  120. public guideline: string,
  121. public project_type: ProjectType,
  122. public randomize_document_order: boolean,
  123. public collaborative_annotation: boolean,
  124. public single_class_classification: boolean
  125. ) {}
  126. static valueOf(
  127. {
  128. id,
  129. name,
  130. description,
  131. guideline,
  132. project_type,
  133. randomize_document_order,
  134. collaborative_annotation,
  135. single_class_classification
  136. }:
  137. {
  138. id: number,
  139. name: string,
  140. description: string,
  141. guideline: string,
  142. project_type: ProjectType,
  143. randomize_document_order: boolean,
  144. collaborative_annotation: boolean,
  145. single_class_classification: boolean
  146. }
  147. ): ProjectWriteItem {
  148. return new ProjectWriteItem(
  149. id,
  150. name,
  151. description,
  152. guideline,
  153. project_type,
  154. randomize_document_order,
  155. collaborative_annotation,
  156. single_class_classification
  157. )
  158. }
  159. get resourceType(): string {
  160. const mapping = {
  161. DocumentClassification: 'TextClassificationProject',
  162. SequenceLabeling : 'SequenceLabelingProject',
  163. Seq2seq : 'Seq2seqProject'
  164. }
  165. return mapping[this.project_type]
  166. }
  167. toObject(): Object {
  168. return {
  169. id: this.id,
  170. name: this.name,
  171. description: this.description,
  172. guideline: this.guideline,
  173. project_type: this.project_type,
  174. randomize_document_order: this.randomize_document_order,
  175. collaborative_annotation: this.collaborative_annotation,
  176. single_class_classification: this.single_class_classification,
  177. resourcetype: this.resourceType
  178. }
  179. }
  180. }