Skip to content

Commit 60c207b

Browse files
committed
Odin: Bugfix
- Previously, Word indices were being reset to 0 for each new document/sentence.
1 parent 2fccea7 commit 60c207b

File tree

6 files changed

+54
-34
lines changed

6 files changed

+54
-34
lines changed

demo/demo.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/tag/js/tag.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40855,6 +40855,7 @@ function () {
4085540855
* Returns the amount of descent below the baseline needed to fit
4085640856
* all this Row's bottom WordTags and Links.
4085740857
* Includes vertical Row padding.
40858+
* TODO: Have this account for whether or not bottom Links are visible.
4085840859
* @return {number}
4085940860
*/
4086040861

@@ -42645,22 +42646,15 @@ function () {
4264542646
// event.detail.object.remove();
4264642647
// this.taxonomyManager.remove(event.detail.object);
4264742648
// });
42648-
42649-
this.svg.on("row-recalculate-slots", function () {
42650-
_this2.links.forEach(function (link) {
42651-
link.slot = null;
42652-
});
42653-
42654-
_this2.links = Util.sortForSlotting(_this2.links);
42655-
42656-
_this2.links.forEach(function (link) {
42657-
return link.calculateSlot(_this2.words);
42658-
});
42659-
42660-
_this2.links.forEach(function (link) {
42661-
return link.draw();
42662-
});
42663-
}); // ZW: Hardcoded dependencies on full UI
42649+
// this.svg.on("row-recalculate-slots", () => {
42650+
// this.links.forEach(link => {
42651+
// link.slot = null;
42652+
// });
42653+
// this.links = Util.sortForSlotting(this.links);
42654+
// this.links.forEach(link => link.calculateSlot(this.words));
42655+
// this.links.forEach(link => link.draw());
42656+
// });
42657+
// ZW: Hardcoded dependencies on full UI
4266442658
// this.svg.on("build-tree", (event) => {
4266542659
// document.body.classList.remove("tree-closed");
4266642660
// if (tree.isInModal) {
@@ -43836,7 +43830,11 @@ function () {
4383643830
// Old TextBoundMentions return their host Word/WordCluster
4383743831
// Old EventMentions/RelationMentions return their Link
4383843832

43839-
this.parsedMentions = {};
43833+
this.parsedMentions = {}; // We record the index of the last Word from the previous sentence so
43834+
// that we can generate each Word's global index (if not Word indices
43835+
// will incorrectly restart from 0 for each new document/sentence)
43836+
43837+
this.lastWordIdx = -1;
4384043838
}
4384143839
/**
4384243840
* Parses the given data, filling out `this.data` accordingly.
@@ -43925,6 +43923,7 @@ function () {
4392543923
};
4392643924
this.parsedDocuments = {};
4392743925
this.parsedMentions = {};
43926+
this.lastWordIdx = -1;
4392843927
}
4392943928
/**
4393043929
* Parses a given document (essentially an array of sentences), appending
@@ -43965,15 +43964,20 @@ function () {
4396543964

4396643965
// Hold on to the Words we generate even as we push them up to the
4396743966
// main data store, so that we can create their syntax Links too
43967+
// (which rely on sentence-level indices, not global indices)
4396843968
var thisSentence = []; // The lengths of the `words` and `tags` arrays should be the same
4396943969

43970-
for (var idx = 0; idx < sentence.words.length; idx++) {
43971-
var thisWord = new _word.default(sentence.words[idx], idx);
43972-
thisWord.setSyntaxTag(sentence.tags[idx]);
43970+
for (var thisIdx = 0; thisIdx < sentence.words.length; thisIdx++) {
43971+
var thisWord = new _word.default( // Text
43972+
sentence.words[thisIdx], // (Global) Word index
43973+
thisIdx + this.lastWordIdx + 1);
43974+
thisWord.setSyntaxTag(sentence.tags[thisIdx]);
4397343975
thisSentence.push(thisWord);
4397443976
this.data.words.push(thisWord);
43975-
} // Sentences may have multiple dependency graphs available
43977+
} // Update the global Word index offset for the next sentence
43978+
4397643979

43980+
this.lastWordIdx += sentence.words.length; // Sentences may have multiple dependency graphs available
4397743981

4397843982
var graphTypes = Object.keys(sentence.graphs);
4397943983

dist/tag/js/tag.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/components/row.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ class Row {
380380
* Returns the amount of descent below the baseline needed to fit
381381
* all this Row's bottom WordTags and Links.
382382
* Includes vertical Row padding.
383+
* TODO: Have this account for whether or not bottom Links are visible.
383384
* @return {number}
384385
*/
385386
get descent() {

src/js/main.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -441,14 +441,14 @@ class Main {
441441
// this.taxonomyManager.remove(event.detail.object);
442442
// });
443443

444-
this.svg.on("row-recalculate-slots", () => {
445-
this.links.forEach(link => {
446-
link.slot = null;
447-
});
448-
this.links = Util.sortForSlotting(this.links);
449-
this.links.forEach(link => link.calculateSlot(this.words));
450-
this.links.forEach(link => link.draw());
451-
});
444+
// this.svg.on("row-recalculate-slots", () => {
445+
// this.links.forEach(link => {
446+
// link.slot = null;
447+
// });
448+
// this.links = Util.sortForSlotting(this.links);
449+
// this.links.forEach(link => link.calculateSlot(this.words));
450+
// this.links.forEach(link => link.draw());
451+
// });
452452

453453
// ZW: Hardcoded dependencies on full UI
454454
// this.svg.on("build-tree", (event) => {

src/js/parse/odin.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class OdinParser {
2323
// Old TextBoundMentions return their host Word/WordCluster
2424
// Old EventMentions/RelationMentions return their Link
2525
this.parsedMentions = {};
26+
27+
// We record the index of the last Word from the previous sentence so
28+
// that we can generate each Word's global index (if not Word indices
29+
// will incorrectly restart from 0 for each new document/sentence)
30+
this.lastWordIdx = -1;
2631
}
2732

2833
/**
@@ -68,6 +73,7 @@ class OdinParser {
6873
};
6974
this.parsedDocuments = {};
7075
this.parsedMentions = {};
76+
this.lastWordIdx = -1;
7177
}
7278

7379
/**
@@ -96,17 +102,26 @@ class OdinParser {
96102
for (const [sentenceId, sentence] of document.sentences.entries()) {
97103
// Hold on to the Words we generate even as we push them up to the
98104
// main data store, so that we can create their syntax Links too
105+
// (which rely on sentence-level indices, not global indices)
99106
const thisSentence = [];
100107

101108
// The lengths of the `words` and `tags` arrays should be the same
102-
for (let idx = 0; idx < sentence.words.length; idx++) {
103-
const thisWord = new Word(sentence.words[idx], idx);
104-
thisWord.setSyntaxTag(sentence.tags[idx]);
109+
for (let thisIdx = 0; thisIdx < sentence.words.length; thisIdx++) {
110+
const thisWord = new Word(
111+
// Text
112+
sentence.words[thisIdx],
113+
// (Global) Word index
114+
thisIdx + this.lastWordIdx + 1
115+
);
116+
thisWord.setSyntaxTag(sentence.tags[thisIdx]);
105117

106118
thisSentence.push(thisWord);
107119
this.data.words.push(thisWord);
108120
}
109121

122+
// Update the global Word index offset for the next sentence
123+
this.lastWordIdx += sentence.words.length;
124+
110125
// Sentences may have multiple dependency graphs available
111126
const graphTypes = Object.keys(sentence.graphs);
112127

0 commit comments

Comments
 (0)