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.

211 lines
5.0 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <v-main>
  3. <v-container fluid>
  4. <v-row justify="center">
  5. <v-col cols="12" md="9">
  6. <v-card>
  7. <v-card-title>
  8. <label-group
  9. :labels="items"
  10. :annotations="categoryAnnotations"
  11. :single-label="exclusive"
  12. @add="addLabel"
  13. @remove="removeLabel"
  14. />
  15. </v-card-title>
  16. <v-divider />
  17. <div class="annotation-text pa-4">
  18. <entity-editor
  19. :dark="$vuetify.theme.dark"
  20. :text="currentDoc.text"
  21. :entities="currentDoc.annotations"
  22. :entity-labels="entityLabels"
  23. @addEntity="addEntity"
  24. @click:entity="updateEntity"
  25. @contextmenu:entity="deleteEntity"
  26. />
  27. </div>
  28. </v-card>
  29. </v-col>
  30. <v-col cols="12" md="3">
  31. <list-metadata :metadata="currentDoc.meta" />
  32. </v-col>
  33. </v-row>
  34. </v-container>
  35. </v-main>
  36. </template>
  37. <script>
  38. import EntityEditor from '@/components/tasks/sequenceLabeling/EntityEditor.vue'
  39. import LabelGroup from '@/components/tasks/textClassification/LabelGroup'
  40. import ListMetadata from '@/components/tasks/metadata/ListMetadata'
  41. export default {
  42. components: {
  43. EntityEditor,
  44. ListMetadata,
  45. LabelGroup
  46. },
  47. layout: 'demo',
  48. data() {
  49. return {
  50. entityLabels: [
  51. {
  52. id: 4,
  53. text: 'City',
  54. prefixKey: null,
  55. suffixKey: 'l',
  56. color: '#fbb028',
  57. textColor: '#ffffff'
  58. },
  59. {
  60. id: 5,
  61. text: 'MISC',
  62. prefixKey: null,
  63. suffixKey: 'm',
  64. color: '#7c20e0',
  65. textColor: '#000000'
  66. },
  67. {
  68. id: 6,
  69. text: 'ORG',
  70. prefixKey: null,
  71. suffixKey: 'o',
  72. color: '#e6d176',
  73. textColor: '#000000'
  74. },
  75. {
  76. id: 7,
  77. text: 'Time',
  78. prefixKey: null,
  79. suffixKey: 'p',
  80. color: '#6a74b9',
  81. textColor: '#ffffff'
  82. }
  83. ],
  84. items: [
  85. {
  86. id: 4,
  87. text: 'Flight',
  88. prefixKey: null,
  89. suffixKey: 'f',
  90. backgroundColor: '#7c20e0',
  91. textColor: '#ffffff'
  92. },
  93. {
  94. id: 5,
  95. text: 'FlightTime',
  96. prefixKey: null,
  97. suffixKey: 't',
  98. backgroundColor: '#fbb028',
  99. textColor: '#000000'
  100. },
  101. {
  102. id: 6,
  103. text: 'Airfare',
  104. prefixKey: null,
  105. suffixKey: 'a',
  106. backgroundColor: '#1e90ff',
  107. textColor: '#000000'
  108. }
  109. ],
  110. categoryAnnotations: [
  111. {
  112. id: 17,
  113. prob: 0.0,
  114. label: 4,
  115. user: 1,
  116. document: 8
  117. }
  118. ],
  119. exclusive: true,
  120. currentDoc: {
  121. id: 8,
  122. text: 'I want to fly from Boston at 8:38 am and arrive in Denver at 11:10 in the morning.',
  123. annotations: [
  124. {
  125. id: 17,
  126. prob: 0.0,
  127. label: 4,
  128. startOffset: 19,
  129. endOffset: 25,
  130. user: 1
  131. },
  132. {
  133. id: 19,
  134. prob: 0.0,
  135. label: 7,
  136. startOffset: 29,
  137. endOffset: 36,
  138. user: 1
  139. },
  140. {
  141. id: 16,
  142. prob: 0.0,
  143. label: 4,
  144. startOffset: 51,
  145. endOffset: 57,
  146. user: 1
  147. },
  148. {
  149. id: 18,
  150. prob: 0.0,
  151. label: 7,
  152. startOffset: 61,
  153. endOffset: 66,
  154. user: 1
  155. }
  156. ],
  157. meta: { wikiPageId: 2 },
  158. annotation_approver: null
  159. }
  160. }
  161. },
  162. methods: {
  163. deleteEntity(annotationId) {
  164. this.currentDoc.annotations = this.currentDoc.annotations.filter(
  165. (item) => item.id !== annotationId
  166. )
  167. },
  168. updateEntity(annotationId, labelId) {
  169. const index = this.currentDoc.annotations.findIndex((item) => item.id === annotationId)
  170. this.currentDoc.annotations[index].label = labelId
  171. this.currentDoc.annotations = [...this.currentDoc.annotations]
  172. },
  173. addEntity(startOffset, endOffset, labelId) {
  174. const payload = {
  175. id: Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER)),
  176. startOffset,
  177. endOffset,
  178. label: labelId
  179. }
  180. this.currentDoc.annotations = [...this.currentDoc.annotations, payload]
  181. },
  182. removeLabel(annotationId) {
  183. this.categoryAnnotations = this.categoryAnnotations.filter((item) => item.id !== annotationId)
  184. },
  185. addLabel(labelId) {
  186. const payload = {
  187. id: Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER)),
  188. label: labelId
  189. }
  190. this.categoryAnnotations.push(payload)
  191. }
  192. }
  193. }
  194. </script>
  195. <style scoped>
  196. .annotation-text {
  197. font-size: 1.25rem !important;
  198. font-weight: 500;
  199. line-height: 2rem;
  200. font-family: 'Roboto', sans-serif !important;
  201. opacity: 0.6;
  202. }
  203. </style>