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.

209 lines
4.9 KiB

  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(item => item.id !== annotationId)
  165. },
  166. updateEntity(annotationId, labelId) {
  167. const index = this.currentDoc.annotations.findIndex(item => item.id === annotationId)
  168. this.currentDoc.annotations[index].label = labelId
  169. },
  170. addEntity(startOffset, endOffset, labelId) {
  171. const payload = {
  172. id: Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER)),
  173. startOffset,
  174. endOffset,
  175. label: labelId
  176. }
  177. this.currentDoc.annotations.push(payload)
  178. },
  179. removeLabel(annotationId) {
  180. this.categoryAnnotations = this.categoryAnnotations.filter(item => item.id !== annotationId)
  181. },
  182. addLabel(labelId) {
  183. const payload = {
  184. id: Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER)),
  185. label: labelId
  186. }
  187. this.categoryAnnotations.push(payload)
  188. }
  189. }
  190. }
  191. </script>
  192. <style scoped>
  193. .annotation-text {
  194. font-size: 1.25rem !important;
  195. font-weight: 500;
  196. line-height: 2rem;
  197. font-family: "Roboto", sans-serif !important;
  198. opacity: 0.6;
  199. }
  200. </style>