Browse Source

Enable to handle multiline document, resolves #463, resolves #577

pull/654/head
Hironsan 5 years ago
parent
commit
46e042907a
2 changed files with 36 additions and 12 deletions
  1. 8
      frontend/components/molecules/EntityItem.vue
  2. 40
      frontend/components/organisms/annotation/EntityItemBox.vue

8
frontend/components/molecules/EntityItem.vue

@ -31,7 +31,7 @@
</v-list-item> </v-list-item>
</v-list> </v-list>
</v-menu> </v-menu>
<span v-else>{{ content }}</span>
<span v-else :class="[newline ? 'newline' : '']">{{ content }}</span>
</template> </template>
<script> <script>
@ -56,6 +56,9 @@ export default {
type: Array, type: Array,
default: () => [], default: () => [],
required: true required: true
},
newline: {
type: Boolean
} }
}, },
data() { data() {
@ -142,4 +145,7 @@ export default {
-webkit-font-smoothing: subpixel-antialiased; -webkit-font-smoothing: subpixel-antialiased;
letter-spacing: .1em; letter-spacing: .1em;
} }
.newline {
width: 100%;
}
</style> </style>

40
frontend/components/organisms/annotation/EntityItemBox.vue

@ -4,6 +4,7 @@
v-for="(chunk, i) in chunks" v-for="(chunk, i) in chunks"
:key="i" :key="i"
:content="chunk.text" :content="chunk.text"
:newline="chunk.newline"
:label="chunk.label" :label="chunk.label"
:color="chunk.color" :color="chunk.color"
:labels="labels" :labels="labels"
@ -96,16 +97,12 @@ export default {
}, },
chunks() { chunks() {
const chunks = []
let chunks = []
const entities = this.sortedEntities const entities = this.sortedEntities
let startOffset = 0 let startOffset = 0
for (const entity of entities) { for (const entity of entities) {
// add non-entities to chunks. // add non-entities to chunks.
chunks.push({
label: null,
color: null,
text: this.text.slice(startOffset, entity.start_offset)
})
chunks = chunks.concat(this.makeChunks(this.text.slice(startOffset, entity.start_offset)))
startOffset = entity.end_offset startOffset = entity.end_offset
// add entities to chunks. // add entities to chunks.
@ -118,11 +115,7 @@ export default {
}) })
} }
// add the rest of text. // add the rest of text.
chunks.push({
label: null,
color: null,
text: this.text.slice(startOffset, this.text.length)
})
chunks = chunks.concat(this.makeChunks(this.text.slice(startOffset, this.text.length)))
return chunks return chunks
}, },
@ -135,6 +128,31 @@ export default {
} }
}, },
methods: { methods: {
makeChunks(text) {
const chunks = []
const snippets = text.split('\n')
for (const snippet of snippets.slice(0, -1)) {
chunks.push({
label: null,
color: null,
text: snippet + '\n',
newline: false
})
chunks.push({
label: null,
color: null,
text: '',
newline: true
})
}
chunks.push({
label: null,
color: null,
text: snippets.slice(-1)[0],
newline: false
})
return chunks
},
show(e) { show(e) {
e.preventDefault() e.preventDefault()
this.showMenu = false this.showMenu = false

Loading…
Cancel
Save