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.

222 lines
6.3 KiB

  1. export interface CurrentUsersRole {
  2. is_project_admin: boolean;
  3. is_annotator: boolean;
  4. is_annotation_approver: boolean;
  5. }
  6. export type ProjectType = 'DocumentClassification' | 'SequenceLabeling' | 'Seq2seq' | 'ImageClassification' | 'Speech2text'
  7. export class ProjectReadItem {
  8. constructor(
  9. public id: number,
  10. public name: string,
  11. public description: string,
  12. public guideline: string,
  13. public users: number[],
  14. public current_users_role: CurrentUsersRole,
  15. public project_type: ProjectType,
  16. public updated_at: string,
  17. public random_order: boolean,
  18. public collaborative_annotation: boolean,
  19. public single_class_classification: boolean,
  20. public resourcetype: string,
  21. public allow_overlapping: boolean,
  22. public grapheme_mode: boolean,
  23. public tags: Object[],
  24. ) {}
  25. static valueOf(
  26. {
  27. id,
  28. name,
  29. description,
  30. guideline,
  31. users,
  32. current_users_role,
  33. project_type,
  34. updated_at,
  35. random_order,
  36. collaborative_annotation,
  37. single_class_classification,
  38. resourcetype,
  39. allow_overlapping,
  40. grapheme_mode,
  41. tags
  42. }:
  43. {
  44. id: number,
  45. name: string,
  46. description: string,
  47. guideline: string,
  48. users: number[],
  49. current_users_role: CurrentUsersRole,
  50. project_type: ProjectType,
  51. updated_at: string,
  52. random_order: boolean,
  53. collaborative_annotation: boolean,
  54. single_class_classification: boolean,
  55. resourcetype: string,
  56. allow_overlapping: boolean,
  57. grapheme_mode: boolean,
  58. tags: Object[]
  59. }
  60. ): ProjectReadItem {
  61. return new ProjectReadItem(
  62. id,
  63. name,
  64. description,
  65. guideline,
  66. users,
  67. current_users_role,
  68. project_type,
  69. updated_at,
  70. random_order,
  71. collaborative_annotation,
  72. single_class_classification,
  73. resourcetype,
  74. allow_overlapping,
  75. grapheme_mode,
  76. tags
  77. )
  78. }
  79. get annotationPageLink(): string {
  80. const mapping = {
  81. DocumentClassification: 'text-classification',
  82. SequenceLabeling : 'sequence-labeling',
  83. Seq2seq : 'sequence-to-sequence',
  84. ImageClassification : 'image-classification',
  85. Speech2text : 'speech-to-text',
  86. }
  87. const url = `/projects/${this.id}/${mapping[this.project_type]}`
  88. return url
  89. }
  90. get canDefineLabel() {
  91. const allowedProjectTypes = [
  92. 'DocumentClassification',
  93. 'SequenceLabeling',
  94. 'ImageClassification'
  95. ]
  96. return allowedProjectTypes.includes(this.project_type)
  97. }
  98. get canDefineRelation() {
  99. const allowedProjectTypes = [
  100. 'SequenceLabeling'
  101. ]
  102. return allowedProjectTypes.includes(this.project_type)
  103. }
  104. get isTextProject() {
  105. const allowedProjectTypes = [
  106. 'DocumentClassification',
  107. 'SequenceLabeling',
  108. 'Seq2seq'
  109. ]
  110. return allowedProjectTypes.includes(this.project_type)
  111. }
  112. toObject(): Object {
  113. return {
  114. id: this.id,
  115. name: this.name,
  116. description: this.description,
  117. guideline: this.guideline,
  118. users: this.users,
  119. current_users_role: this.current_users_role,
  120. project_type: this.project_type,
  121. updated_at: this.updated_at,
  122. random_order: this.random_order,
  123. collaborative_annotation: this.collaborative_annotation,
  124. single_class_classification: this.single_class_classification,
  125. resourcetype: this.resourcetype,
  126. allow_overlapping: this.allow_overlapping,
  127. grapheme_mode: this.grapheme_mode,
  128. tags: this.tags
  129. }
  130. }
  131. }
  132. export class ProjectWriteItem {
  133. constructor(
  134. public id: number,
  135. public name: string,
  136. public description: string,
  137. public guideline: string,
  138. public project_type: ProjectType,
  139. public random_order: boolean,
  140. public collaborative_annotation: boolean,
  141. public single_class_classification: boolean,
  142. public allow_overlapping: boolean,
  143. public grapheme_mode: boolean
  144. ) {}
  145. static valueOf(
  146. {
  147. id,
  148. name,
  149. description,
  150. guideline,
  151. project_type,
  152. random_order,
  153. collaborative_annotation,
  154. single_class_classification,
  155. allow_overlapping,
  156. grapheme_mode
  157. }:
  158. {
  159. id: number,
  160. name: string,
  161. description: string,
  162. guideline: string,
  163. project_type: ProjectType,
  164. random_order: boolean,
  165. collaborative_annotation: boolean,
  166. single_class_classification: boolean,
  167. allow_overlapping: boolean,
  168. grapheme_mode: boolean
  169. }
  170. ): ProjectWriteItem {
  171. return new ProjectWriteItem(
  172. id,
  173. name,
  174. description,
  175. guideline,
  176. project_type,
  177. random_order,
  178. collaborative_annotation,
  179. single_class_classification,
  180. allow_overlapping,
  181. grapheme_mode
  182. )
  183. }
  184. get resourceType(): string {
  185. const mapping = {
  186. DocumentClassification: 'TextClassificationProject',
  187. SequenceLabeling : 'SequenceLabelingProject',
  188. Seq2seq : 'Seq2seqProject',
  189. ImageClassification : 'ImageClassificationProject',
  190. Speech2text : 'Speech2textProject',
  191. }
  192. return mapping[this.project_type]
  193. }
  194. toObject(): Object {
  195. return {
  196. id: this.id,
  197. name: this.name,
  198. description: this.description,
  199. guideline: this.guideline,
  200. project_type: this.project_type,
  201. random_order: this.random_order,
  202. collaborative_annotation: this.collaborative_annotation,
  203. single_class_classification: this.single_class_classification,
  204. allow_overlapping: this.allow_overlapping,
  205. grapheme_mode: this.grapheme_mode,
  206. resourcetype: this.resourceType
  207. }
  208. }
  209. }