Skip to content

Commit 554d0cd

Browse files
authored
Merge pull request doccano#654 from doccano/bugfix/multiline-display-error
Enable to handle multiline document in sequence labeling
2 parents 5fc6253 + 46e0429 commit 554d0cd

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

frontend/components/molecules/EntityItem.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</v-list-item>
3232
</v-list>
3333
</v-menu>
34-
<span v-else>{{ content }}</span>
34+
<span v-else :class="[newline ? 'newline' : '']">{{ content }}</span>
3535
</template>
3636

3737
<script>
@@ -56,6 +56,9 @@ export default {
5656
type: Array,
5757
default: () => [],
5858
required: true
59+
},
60+
newline: {
61+
type: Boolean
5962
}
6063
},
6164
data() {
@@ -142,4 +145,7 @@ export default {
142145
-webkit-font-smoothing: subpixel-antialiased;
143146
letter-spacing: .1em;
144147
}
148+
.newline {
149+
width: 100%;
150+
}
145151
</style>

frontend/components/organisms/annotation/EntityItemBox.vue

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
v-for="(chunk, i) in chunks"
55
:key="i"
66
:content="chunk.text"
7+
:newline="chunk.newline"
78
:label="chunk.label"
89
:color="chunk.color"
910
:labels="labels"
@@ -96,16 +97,12 @@ export default {
9697
},
9798
9899
chunks() {
99-
const chunks = []
100+
let chunks = []
100101
const entities = this.sortedEntities
101102
let startOffset = 0
102103
for (const entity of entities) {
103104
// add non-entities to chunks.
104-
chunks.push({
105-
label: null,
106-
color: null,
107-
text: this.text.slice(startOffset, entity.start_offset)
108-
})
105+
chunks = chunks.concat(this.makeChunks(this.text.slice(startOffset, entity.start_offset)))
109106
startOffset = entity.end_offset
110107
111108
// add entities to chunks.
@@ -118,11 +115,7 @@ export default {
118115
})
119116
}
120117
// add the rest of text.
121-
chunks.push({
122-
label: null,
123-
color: null,
124-
text: this.text.slice(startOffset, this.text.length)
125-
})
118+
chunks = chunks.concat(this.makeChunks(this.text.slice(startOffset, this.text.length)))
126119
return chunks
127120
},
128121
@@ -135,6 +128,31 @@ export default {
135128
}
136129
},
137130
methods: {
131+
makeChunks(text) {
132+
const chunks = []
133+
const snippets = text.split('\n')
134+
for (const snippet of snippets.slice(0, -1)) {
135+
chunks.push({
136+
label: null,
137+
color: null,
138+
text: snippet + '\n',
139+
newline: false
140+
})
141+
chunks.push({
142+
label: null,
143+
color: null,
144+
text: '',
145+
newline: true
146+
})
147+
}
148+
chunks.push({
149+
label: null,
150+
color: null,
151+
text: snippets.slice(-1)[0],
152+
newline: false
153+
})
154+
return chunks
155+
},
138156
show(e) {
139157
e.preventDefault()
140158
this.showMenu = false

0 commit comments

Comments
 (0)