Skip to content

Commit 1b47cf5

Browse files
authored
Merge pull request #5324 from inception-project/feature/5317-Display-correction-suggestions
#5317 - Display correction suggestions
2 parents 7812d8c + 08348eb commit 1b47cf5

File tree

41 files changed

+527
-137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+527
-137
lines changed

inception/inception-brat-editor/src/main/ts/src/protocol/Protocol.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export type VID = string | number
2222
export type CommentType = 'AnnotatorNotes' | 'EditHighlight' | 'AnnotationError'
2323
| 'AnnotationIncomplete' | 'AnnotationUnconfirmed' | 'AnnotationWarning' | 'MissingAnnotation'
2424
| 'ChangedAnnotation' | 'Normalized' | 'True_positive' | 'False_positive' | 'False_negative'
25-
export type MarkerType = 'edited' | 'focus' | 'matchfocus' | 'match'
25+
export type MarkerType = 'edited' | 'focus' | 'matchfocus' | 'match' | 'warn'
2626
export type ClippedState = '' | 's' | 'e' | 'se'
2727
export type ColorCode = string
2828

@@ -265,6 +265,7 @@ export type SourceData = {
265265
events: Array<EventDto>; // deprecated?
266266
}
267267

268+
export const WARN: MarkerType = 'warn'
268269
export const EDITED: MarkerType = 'edited'
269270
export const FOCUS: MarkerType = 'focus'
270271
export const MATCH_FOCUS: MarkerType = 'matchfocus'

inception/inception-brat-editor/src/main/ts/src/style-vis.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ $background_color_10: #ffcccc;
569569
-webkit-animation-fill-mode: both;
570570
animation-fill-mode: both;
571571
}
572+
572573
.focus {
573574
fill: #3ab7ee;
574575
-webkit-animation-name: flash;
@@ -578,6 +579,7 @@ $background_color_10: #ffcccc;
578579
-webkit-animation-fill-mode: both;
579580
animation-fill-mode: both;
580581
}
582+
581583
rect.match {
582584
fill: orange;
583585
opacity: 0.25;

inception/inception-brat-editor/src/main/ts/src/visualizer/Visualizer.ts

Lines changed: 72 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { Row } from './Row'
5050
import { RectBox } from './RectBox'
5151
import { AttributeType, ValType } from './AttributeType'
5252
import { CollectionLoadedResponse } from './CollectionLoadedResponse'
53-
import { RelationTypeDto, EntityTypeDto, EntityDto, CommentDto, SourceData, TriggerDto, AttributeDto, EquivDto, ColorCode, MarkerType, MarkerDto, RelationDto, EDITED, FOCUS, MATCH_FOCUS, MATCH, RoleDto, VID } from '../protocol/Protocol'
53+
import { RelationTypeDto, EntityTypeDto, EntityDto, CommentDto, SourceData, TriggerDto, AttributeDto, EquivDto, ColorCode, MarkerType, MarkerDto, RelationDto, EDITED, FOCUS, MATCH_FOCUS, MATCH, RoleDto, VID, WARN } from '../protocol/Protocol'
5454
import type { Dispatcher, Message } from '../dispatcher/Dispatcher'
5555
import * as jsonpatch from 'fast-json-patch'
5656
import { Operation } from 'fast-json-patch'
@@ -349,50 +349,60 @@ export class Visualizer {
349349
}
350350

351351
setMarked (docData: DocumentData, sourceData: SourceData, markedType: MarkerType) {
352-
if (!this.args[markedType]) {
352+
if (!this.data || !this.args[markedType]) {
353353
return
354354
}
355355

356356
for (const marker of this.args[markedType]) {
357+
// Sentence marker
357358
if (marker[0] === 'sent') {
358359
docData.markedSent[marker[1]] = true
359360
continue
360361
}
361362

362-
if (marker[0] === 'equiv') { // [equiv, Equiv, T1]
363-
for (const equiv of sourceData.equivs) {
364-
if (equiv[1] === marker[1]) {
365-
let len = equiv.length
366-
for (let i = 2; i < len; i++) {
367-
if (equiv[i] === marker[2]) {
368-
// found it
369-
len -= 3
370-
for (let n = 1; n <= len; n++) {
371-
const arc = docData.eventDescs[equiv[0] + '*' + n].equivArc
372-
arc.marked = markedType
373-
}
374-
continue // next equiv
375-
}
376-
}
377-
}
378-
}
379-
363+
// INCEpTION does not use equivs, so we should not need this
364+
// if (marker[0] === 'equiv') { // [equiv, Equiv, T1]
365+
// for (const equiv of sourceData.equivs) {
366+
// if (equiv[1] === marker[1]) {
367+
// let len = equiv.length
368+
// for (let i = 2; i < len; i++) {
369+
// if (equiv[i] === marker[2]) {
370+
// // found it
371+
// len -= 3
372+
// for (let n = 1; n <= len; n++) {
373+
// const arc = docData.eventDescs[equiv[0] + '*' + n].equivArc
374+
// arc.marked = markedType
375+
// }
376+
// continue // next equiv
377+
// }
378+
// }
379+
// }
380+
// }
381+
382+
// continue
383+
// }
384+
385+
if (!Array.isArray(marker)) {
380386
continue
381387
}
382388

389+
// Text marker
383390
if (marker.length === 2) {
384-
this.markedText.push([parseInt(marker[0], 10), parseInt(marker[1], 10), markedType])
391+
const begin = parseInt(marker[0], 10)
392+
const end = parseInt(marker[1], 10)
393+
this.markedText.push([begin, end, markedType])
385394
continue
386395
}
387396

397+
// Annotation marker (span or arc)
388398
const span = this.data.spans[marker[0]]
389399
if (span) {
390400
if (marker.length === 3) { // arc
391-
$.each(span.outgoing, (arcNo, arc) => {
401+
for (const arc of span.outgoing) {
392402
if (arc.target === marker[2] && arc.type === marker[1]) {
393-
arc.marked = markedType
403+
arc.marked = markedType;
394404
}
395-
})
405+
}
396406
} else { // span
397407
span.marked = markedType
398408
}
@@ -438,9 +448,10 @@ export class Visualizer {
438448
applyHighlighting (docData: DocumentData, sourceData: SourceData) {
439449
this.markedText = []
440450
this.setMarked(docData, sourceData, EDITED) // set by editing process
441-
this.setMarked(docData, sourceData, FOCUS) // set by URL
442451
this.setMarked(docData, sourceData, MATCH_FOCUS) // set by search process, focused match
443452
this.setMarked(docData, sourceData, MATCH) // set by search process, other (non-focused) match
453+
this.setMarked(docData, sourceData, WARN) // set by editing process
454+
this.setMarked(docData, sourceData, FOCUS) // set by URL
444455
}
445456

446457
/**
@@ -1289,7 +1300,6 @@ export class Visualizer {
12891300
textMeasureGroup.addClass(cssClass)
12901301
}
12911302

1292-
// changed from $.each because of #264 ('length' can appear)
12931303
for (const text in textsHash) {
12941304
if (Object.prototype.hasOwnProperty.call(textsHash, text)) {
12951305
this.svg.plain(text).addTo(textMeasureGroup)
@@ -1360,8 +1370,9 @@ export class Visualizer {
13601370
// Adjust for the browser collapsing whitespace
13611371
let lastCharSpace = true
13621372
let collapsedSpaces = 0
1373+
const tc = text.textContent || "";
13631374
for (let i = 0; i < fragment[2]; i++) {
1364-
const c = text.textContent[i]
1375+
const c = tc[i]
13651376
if (/\s/.test(c)) {
13661377
if (lastCharSpace) {
13671378
collapsedSpaces++
@@ -1637,8 +1648,8 @@ export class Visualizer {
16371648
let width = 5
16381649
let height = 5
16391650
let color = 'black'
1640-
if ($.isNumeric(parsedSpec[1]) && parsedSpec[2]) {
1641-
if ($.isNumeric(parsedSpec[2]) && parsedSpec[3]) {
1651+
if (!isNaN(parseFloat(parsedSpec[1])) && parsedSpec[2]) {
1652+
if (!isNaN(parseFloat(parsedSpec[2])) && parsedSpec[3]) {
16421653
// 3 args, 2 numeric: assume width, height, color
16431654
width = parseFloat(parsedSpec[1])
16441655
height = parseFloat(parsedSpec[2])
@@ -1734,7 +1745,8 @@ export class Visualizer {
17341745
const thisCurlyHeight = span.drawCurly ? Configuration.visual.curlyHeight : 0
17351746
const height = docData.sizes.fragments.height + thisCurlyHeight + Configuration.visual.boxSpacing +
17361747
2 * Configuration.visual.margin.y - 3
1737-
$.each(floors, (floorNo, floor) => {
1748+
1749+
for (const floor in floors) {
17381750
let floorAvailable = true
17391751
for (let i = i1; i <= i2; i++) {
17401752
if (!(reservations[i] && reservations[i][floor])) {
@@ -1760,7 +1772,7 @@ export class Visualizer {
17601772
} else {
17611773
carpet = null
17621774
}
1763-
})
1775+
}
17641776

17651777
const reslen = reservations.length
17661778
const makeNewFloorIfNeeded = function (floor: number) {
@@ -1919,7 +1931,7 @@ export class Visualizer {
19191931
hh -= 2 * this.boxTextMargin.y
19201932
xx += this.boxTextMargin.x
19211933
ww -= 2 * this.boxTextMargin.x
1922-
let rectClass = 'span_' + (span.cue || span.type) + ' span_default' // TODO XXX first part unneeded I think; remove
1934+
let rectClass = 'span_default'
19231935

19241936
// attach e.g. "False_positive" into the type
19251937
if (span.comment && span.comment.type) {
@@ -2196,18 +2208,18 @@ export class Visualizer {
21962208
}
21972209

21982210
// open text highlights
2199-
$.each(chunk.markedTextStart, (textNo, textDesc) => {
2200-
textDesc[3] += currentX + (this.rtlmode ? -boxX : boxX)
2201-
openTextHighlights[textDesc[0]] = textDesc
2202-
})
2211+
for (const textDesc of chunk.markedTextStart) {
2212+
textDesc[3] += currentX + (this.rtlmode ? -boxX : boxX);
2213+
openTextHighlights[textDesc[0]] = textDesc;
2214+
}
22032215

22042216
// close text highlights
2205-
$.each(chunk.markedTextEnd, (textNo, textDesc) => {
2206-
textDesc[3] += currentX + (this.rtlmode ? -boxX : boxX)
2207-
const startDesc = openTextHighlights[textDesc[0]]
2208-
delete openTextHighlights[textDesc[0]]
2209-
textMarkedRows.push([row, startDesc[3], textDesc[3], startDesc[4]])
2210-
})
2217+
for (const textDesc of chunk.markedTextEnd) {
2218+
textDesc[3] += currentX + (this.rtlmode ? -boxX : boxX);
2219+
const startDesc = openTextHighlights[textDesc[0]];
2220+
delete openTextHighlights[textDesc[0]];
2221+
textMarkedRows.push([row, startDesc[3], textDesc[3], startDesc[4]]);
2222+
}
22112223

22122224
// XXX check this - is it used? should it be lastRow?
22132225
if (hasAnnotations) {
@@ -3975,23 +3987,24 @@ export class Visualizer {
39753987
}
39763988
}
39773989

3978-
loadAttributeTypes (responseTypes) {
3979-
const processed = {}
3980-
$.each(responseTypes, (aTypeNo, aType) => {
3981-
processed[aType.type] = aType
3982-
// count the values; if only one, it's a boolean attribute
3983-
const values: string[] = []
3984-
for (const i in aType.values) {
3985-
if (Object.prototype.hasOwnProperty.call(aType.values, i)) {
3986-
values.push(i)
3987-
}
3988-
}
3989-
if (values.length === 1) {
3990-
aType.bool = values[0]
3991-
}
3992-
})
3993-
return processed
3994-
}
3990+
// INCEpTION does not use event attributes and entity attributes
3991+
// loadAttributeTypes (responseTypes) {
3992+
// const processed = {}
3993+
// for (const type of responseTypes) {
3994+
// processed[type.type] = type
3995+
// // count the values; if only one, it's a boolean attribute
3996+
// const values: string[] = []
3997+
// for (const i in type.values) {
3998+
// if (Object.prototype.hasOwnProperty.call(type.values, i)) {
3999+
// values.push(i)
4000+
// }
4001+
// }
4002+
// if (values.length === 1) {
4003+
// type.bool = values[0]
4004+
// }
4005+
// }
4006+
// return processed
4007+
// }
39954008

39964009
loadRelationTypes (relationTypes: RelationTypeDto[]) {
39974010
for (const relType of relationTypes) {

inception/inception-diam-editor/src/main/ts/src/AnnotationsByLabelList.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
const spans = data?.spans.values() || []
5353
groupedAnnotations = groupBy(
5454
[...spans, ...relations],
55-
(s) => renderLabel(s)
55+
(s) => renderLabel(data, s)
5656
)
5757
5858
for (let [key, items] of Object.entries(groupedAnnotations)) {
@@ -233,6 +233,7 @@
233233
>
234234
<div class="float-end labels">
235235
<LabelBadge
236+
{data}
236237
annotation={ann}
237238
{ajaxClient}
238239
showText={false}

inception/inception-diam-editor/src/main/ts/src/AnnotationsByLayerList.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
<div class="flex-grow-1 my-1 mx-2 position-relative overflow-hidden" on:click={() => scrollToSpan(ann)}>
223223
<div class="float-end labels">
224224
<LabelBadge
225+
{data}
225226
annotation={ann}
226227
{ajaxClient}
227228
showText={true}
@@ -256,6 +257,7 @@
256257
>
257258
<div class="float-end labels">
258259
<LabelBadge
260+
{data}
259261
annotation={relation}
260262
{ajaxClient}
261263
/>
@@ -277,6 +279,7 @@
277279
<div class="flex-grow-1 my-1 mx-0 position-relative overflow-hidden">
278280
<div class="me-2">
279281
<LabelBadge
282+
{data}
280283
annotation={ann}
281284
{ajaxClient}
282285
showText={true}

inception/inception-diam-editor/src/main/ts/src/AnnotationsByPositionList.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
mouseOutAnnotation(ev, span)}
113113
>
114114
<LabelBadge
115+
{data}
115116
annotation={span}
116117
{ajaxClient}
117118
/>
@@ -146,6 +147,7 @@
146147
>
147148
<div class="float-end labels">
148149
<LabelBadge
150+
{data}
149151
annotation={relation}
150152
{ajaxClient}
151153
/>

0 commit comments

Comments
 (0)