Skip to content

Commit 30d0333

Browse files
committed
toggle POS and REACH (some bugginess in the alignment)
1 parent 6c5d5ee commit 30d0333

File tree

2 files changed

+69
-16
lines changed

2 files changed

+69
-16
lines changed

index.html

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363

6464
<div id="header">
6565
<input type="file">
66-
<button class="active" id="POS">POS</button>
67-
<button id="BIO">BIO</button>
66+
<button id="POS">POS</button>
67+
<button class="active" id="REACH">REACH</button>
6868
</div>
6969

7070
<div id="drawing">
@@ -181,18 +181,24 @@
181181
// init objects/listeners...
182182
window.onload = function() {
183183

184+
function generateLinksPOS(){};
185+
function generateLinksREACH(){};
186+
184187
// init buttons
185188
const State = {
186189
annotationStyle: document.querySelector('button.active').id,
187190
setAnnotationStyle: function(type) {
188191
this.annotationStyle = type;
189192
if (type === "POS") {
190193
wordObjs.forEach(w => w.tag = w.data.syntaxData.tag);
194+
generateLinksPOS();
191195
}
192196
else {
193197
wordObjs.forEach(w => w.tag = w.data.bioData.tag);
198+
generateLinksREACH();
194199
}
195200
redrawWords(wordObjs);
201+
redrawLinks(true);
196202
}
197203
};
198204
const buttons = document.querySelectorAll('#header button');
@@ -385,11 +391,58 @@
385391
wordObjs.push(w);
386392
})
387393

388-
linkObjs = [];
389-
if (State.annotationStyle == 'POS') {
390-
// syntaxDataArray.forEach
391-
// }
392-
// else {
394+
function clearLinkObjs() {
395+
linkObjs.forEach(link => link.removeSVGs());
396+
linkObjs = [];
397+
398+
wordObjs.forEach(word => {
399+
word.slotsL = [];
400+
word.slotsR = [];
401+
word.parentsL = [];
402+
word.parentsR = [];
403+
})
404+
}
405+
406+
generateLinksPOS = function() {
407+
clearLinkObjs();
408+
syntaxDataArray.forEach(link => {
409+
let ltr = link.source.locationInSentence < link.destination.locationInSentence;
410+
let style;
411+
switch (link.label) {
412+
case "nsubj":
413+
style = ltr ? styles.gradientLine2 : styles.gradientLine2r;
414+
break;
415+
case "dobj":
416+
style = ltr ? styles.gradientLine1 : styles.gradientLine1r;
417+
break;
418+
case "det":
419+
style = styles.simpleLine;
420+
break;
421+
default:
422+
style = styles.noneLine;
423+
break;
424+
}
425+
426+
427+
let linkObject = new Link(
428+
link.source.object,
429+
link.destination.object,
430+
ltr ? 1 : -1,
431+
style,
432+
link.label,
433+
texts.linkText
434+
);
435+
436+
// create circular reference to link and data
437+
linkObject.data = link;
438+
link.object = linkObject;
439+
linkObjs.push( linkObject );
440+
createLink(linkObject);
441+
})
442+
}
443+
444+
generateLinksREACH = function() {
445+
clearLinkObjs();
393446
mentionDataArray.forEach(function(link) {
394447
if (link.words) {
395448

@@ -458,15 +511,9 @@
458511
});
459512
}
460513

461-
// draw
462-
// linkObjs.sort(function(a, b) {
463-
// var d1 = Math.abs(a.s.idx - a.e.idx);
464-
// var d2 = Math.abs(b.s.idx - b.e.idx);
465-
466-
// return d1 - d2;
467-
// });
468-
// linkObjs.forEach(createLink);
469514

515+
// draw
516+
generateLinksREACH();
470517
drawWords(wordObjs);
471518
drawLinks(linkObjs);
472519

js/annotate.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ class Link {
7575

7676
}
7777

78-
78+
removeSVGs() {
79+
this.polylineSVGs.forEach(svg => svg.remove());
80+
this.labelRectSVGs.forEach(svg => svg.remove());
81+
this.labelTextSVGs.forEach(svg => svg.remove());
82+
this.arrow1Style.path.remove();
83+
this.arrow2Style.path.remove();
84+
}
7985

8086
toString() {
8187
return this.id;

0 commit comments

Comments
 (0)