diff --git a/app/server/static/bundle/sequence_labeling.js b/app/server/static/bundle/sequence_labeling.js index 8016361e..29293ff2 100644 --- a/app/server/static/bundle/sequence_labeling.js +++ b/app/server/static/bundle/sequence_labeling.js @@ -495,7 +495,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _htt /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! vue */ \"./node_modules/vue/dist/vue.esm.js\");\n/* harmony import */ var _mixin__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mixin */ \"./static/js/mixin.js\");\n/* harmony import */ var _http__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./http */ \"./static/js/http.js\");\n\n\n\n\nvue__WEBPACK_IMPORTED_MODULE_0__[\"default\"].use(__webpack_require__(/*! vue-shortkey */ \"./node_modules/vue-shortkey/dist/index.js\"), {\n prevent: ['input', 'textarea'],\n});\n\nvue__WEBPACK_IMPORTED_MODULE_0__[\"default\"].component('annotator', {\n template: '
\\\n {{ text.slice(r.start_offset, r.end_offset) }}\\\n
',\n props: {\n labels: Array, // [{id: Integer, color: String, text: String}]\n text: String,\n entityPositions: Array, // [{'startOffset': 10, 'endOffset': 15, 'label_id': 1}]\n },\n data() {\n return {\n startOffset: 0,\n endOffset: 0,\n };\n },\n\n methods: {\n setSelectedRange(e) {\n let start;\n let end;\n if (window.getSelection) {\n const range = window.getSelection().getRangeAt(0);\n const preSelectionRange = range.cloneRange();\n preSelectionRange.selectNodeContents(this.$el);\n preSelectionRange.setEnd(range.startContainer, range.startOffset);\n start = preSelectionRange.toString().length;\n end = start + range.toString().length;\n } else if (document.selection && document.selection.type !== 'Control') {\n const selectedTextRange = document.selection.createRange();\n const preSelectionTextRange = document.body.createTextRange();\n preSelectionTextRange.moveToElementText(this.$el);\n preSelectionTextRange.setEndPoint('EndToStart', selectedTextRange);\n start = preSelectionTextRange.text.length;\n end = start + selectedTextRange.text.length;\n }\n this.startOffset = start;\n this.endOffset = end;\n console.log(start, end);\n },\n\n validRange() {\n if (this.startOffset === this.endOffset) {\n return false;\n }\n if (this.startOffset > this.text.length || this.endOffset > this.text.length) {\n return false;\n }\n if (this.startOffset < 0 || this.endOffset < 0) {\n return false;\n }\n for (let i = 0; i < this.entityPositions.length; i++) {\n const e = this.entityPositions[i];\n if ((e.start_offset < this.startOffset) && (this.startOffset < e.end_offset)) {\n return false;\n }\n if ((e.start_offset < this.endOffset) && (this.endOffset < e.end_offset)) {\n return false;\n }\n }\n return true;\n },\n\n resetRange() {\n this.startOffset = 0;\n this.endOffset = 0;\n },\n\n addLabel(labelId) {\n if (this.validRange()) {\n const label = {\n start_offset: this.startOffset,\n end_offset: this.endOffset,\n label: labelId,\n };\n this.$emit('add-label', label);\n }\n },\n\n removeLabel(index) {\n this.$emit('remove-label', index);\n },\n\n makeLabel(startOffset, endOffset) {\n const label = {\n id: 0,\n label: -1,\n start_offset: startOffset,\n end_offset: endOffset,\n };\n return label;\n },\n },\n\n watch: {\n entityPositions() {\n this.resetRange();\n },\n },\n\n computed: {\n sortedEntityPositions() {\n this.entityPositions = this.entityPositions.sort((a, b) => a.start_offset - b.start_offset);\n return this.entityPositions;\n },\n\n chunks() {\n const res = [];\n let left = 0;\n for (let i = 0; i < this.sortedEntityPositions.length; i++) {\n const e = this.sortedEntityPositions[i];\n const l = this.makeLabel(left, e.start_offset);\n res.push(l);\n res.push(e);\n left = e.end_offset;\n }\n const l = this.makeLabel(left, this.text.length);\n res.push(l);\n\n return res;\n },\n\n id2label() {\n let id2label = {};\n // default value;\n id2label[-1] = {\n text_color: '',\n background_color: '',\n };\n for (let i = 0; i < this.labels.length; i++) {\n const label = this.labels[i];\n id2label[label.id] = label;\n }\n return id2label;\n },\n },\n});\n\nconst vm = new vue__WEBPACK_IMPORTED_MODULE_0__[\"default\"]({\n el: '#mail-app',\n delimiters: ['[[', ']]'],\n mixins: [_mixin__WEBPACK_IMPORTED_MODULE_1__[\"default\"]],\n methods: {\n annotate(labelId) {\n this.$refs.annotator.addLabel(labelId);\n },\n\n addLabel(annotation) {\n const docId = this.docs[this.pageNumber].id;\n _http__WEBPACK_IMPORTED_MODULE_2__[\"default\"].post(`docs/${docId}/annotations/`, annotation).then((response) => {\n this.annotations[this.pageNumber].push(response.data);\n });\n },\n },\n});\n\n\n//# sourceURL=webpack:///./static/js/sequence_labeling.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! vue */ \"./node_modules/vue/dist/vue.esm.js\");\n/* harmony import */ var _mixin__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mixin */ \"./static/js/mixin.js\");\n/* harmony import */ var _http__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./http */ \"./static/js/http.js\");\n\n\n\n\nvue__WEBPACK_IMPORTED_MODULE_0__[\"default\"].use(__webpack_require__(/*! vue-shortkey */ \"./node_modules/vue-shortkey/dist/index.js\"), {\n prevent: ['input', 'textarea'],\n});\n\nvue__WEBPACK_IMPORTED_MODULE_0__[\"default\"].component('annotator', {\n template: '
\\\n {{ text.slice(r.start_offset, r.end_offset) }}\\\n
',\n props: {\n labels: Array, // [{id: Integer, color: String, text: String}]\n text: String,\n entityPositions: Array, // [{'startOffset': 10, 'endOffset': 15, 'label_id': 1}]\n },\n data() {\n return {\n startOffset: 0,\n endOffset: 0,\n };\n },\n\n methods: {\n setSelectedRange(e) {\n let start;\n let end;\n if (window.getSelection) {\n const range = window.getSelection().getRangeAt(0);\n const preSelectionRange = range.cloneRange();\n preSelectionRange.selectNodeContents(this.$el);\n preSelectionRange.setEnd(range.startContainer, range.startOffset);\n start = preSelectionRange.toString().length;\n end = start + range.toString().length;\n } else if (document.selection && document.selection.type !== 'Control') {\n const selectedTextRange = document.selection.createRange();\n const preSelectionTextRange = document.body.createTextRange();\n preSelectionTextRange.moveToElementText(this.$el);\n preSelectionTextRange.setEndPoint('EndToStart', selectedTextRange);\n start = preSelectionTextRange.text.length;\n end = start + selectedTextRange.text.length;\n }\n this.startOffset = start;\n this.endOffset = end;\n console.log(start, end);\n },\n\n validRange() {\n if (this.startOffset === this.endOffset) {\n return false;\n }\n if (this.startOffset > this.text.length || this.endOffset > this.text.length) {\n return false;\n }\n if (this.startOffset < 0 || this.endOffset < 0) {\n return false;\n }\n for (let i = 0; i < this.entityPositions.length; i++) {\n const e = this.entityPositions[i];\n if ((e.start_offset < this.startOffset) && (this.startOffset < e.end_offset)) {\n return false;\n }\n if ((e.start_offset < this.endOffset) && (this.endOffset < e.end_offset)) {\n return false;\n }\n if ((this.startOffset < e.start_offset) && (e.start_offset < this.endOffset)) {\n return false;\n }\n if ((this.startOffset < e.end_offset) && (e.end_offset < this.endOffset)) {\n return false;\n }\n }\n return true;\n },\n\n resetRange() {\n this.startOffset = 0;\n this.endOffset = 0;\n },\n\n addLabel(labelId) {\n if (this.validRange()) {\n const label = {\n start_offset: this.startOffset,\n end_offset: this.endOffset,\n label: labelId,\n };\n this.$emit('add-label', label);\n }\n },\n\n removeLabel(index) {\n this.$emit('remove-label', index);\n },\n\n makeLabel(startOffset, endOffset) {\n const label = {\n id: 0,\n label: -1,\n start_offset: startOffset,\n end_offset: endOffset,\n };\n return label;\n },\n },\n\n watch: {\n entityPositions() {\n this.resetRange();\n },\n },\n\n computed: {\n sortedEntityPositions() {\n this.entityPositions = this.entityPositions.sort((a, b) => a.start_offset - b.start_offset);\n return this.entityPositions;\n },\n\n chunks() {\n const res = [];\n let left = 0;\n for (let i = 0; i < this.sortedEntityPositions.length; i++) {\n const e = this.sortedEntityPositions[i];\n const l = this.makeLabel(left, e.start_offset);\n res.push(l);\n res.push(e);\n left = e.end_offset;\n }\n const l = this.makeLabel(left, this.text.length);\n res.push(l);\n\n return res;\n },\n\n id2label() {\n let id2label = {};\n // default value;\n id2label[-1] = {\n text_color: '',\n background_color: '',\n };\n for (let i = 0; i < this.labels.length; i++) {\n const label = this.labels[i];\n id2label[label.id] = label;\n }\n return id2label;\n },\n },\n});\n\nconst vm = new vue__WEBPACK_IMPORTED_MODULE_0__[\"default\"]({\n el: '#mail-app',\n delimiters: ['[[', ']]'],\n mixins: [_mixin__WEBPACK_IMPORTED_MODULE_1__[\"default\"]],\n methods: {\n annotate(labelId) {\n this.$refs.annotator.addLabel(labelId);\n },\n\n addLabel(annotation) {\n const docId = this.docs[this.pageNumber].id;\n _http__WEBPACK_IMPORTED_MODULE_2__[\"default\"].post(`docs/${docId}/annotations/`, annotation).then((response) => {\n this.annotations[this.pageNumber].push(response.data);\n });\n },\n },\n});\n\n\n//# sourceURL=webpack:///./static/js/sequence_labeling.js?"); /***/ }) diff --git a/app/server/static/js/sequence_labeling.js b/app/server/static/js/sequence_labeling.js index 693ff390..5ab7ed34 100644 --- a/app/server/static/js/sequence_labeling.js +++ b/app/server/static/js/sequence_labeling.js @@ -70,6 +70,12 @@ Vue.component('annotator', { if ((e.start_offset < this.endOffset) && (this.endOffset < e.end_offset)) { return false; } + if ((this.startOffset < e.start_offset) && (e.start_offset < this.endOffset)) { + return false; + } + if ((this.startOffset < e.end_offset) && (e.end_offset < this.endOffset)) { + return false; + } } return true; },