Skip to content

Commit 1487279

Browse files
committed
refactor -- start adding POS
1 parent 45c8379 commit 1487279

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

js2/components/link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Link {
105105
+ 'c' + [dx, 0, dx, 10, dx, 10];
106106
}).join();
107107
}
108-
else {
108+
else if (this.relType) {
109109
let avg = this.arguments.reduce((acc, a) => acc + a.anchor.cx, 0) / this.arguments.length;
110110
this.svgTexts[0].x(avg)
111111
.y(this.arguments[0].anchor.absoluteY - 10 - 7);

js2/main.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ const Main = (function() {
104104
//--------------------------------
105105
function buildWordsAndLinks() {
106106
// construct word objects and tags from tokens, entities, and triggers
107-
const words = parser.tokens.map((token, i) => new Word(token, i));
107+
const words = parser.tokens.map((token, i) => {
108+
let w = new Word(token.text, i);
109+
w.syntaxTag = token.type;
110+
w.syntaxId = token.id;
111+
return w;
112+
});
108113
const clusters = [];
109114

110115
[].concat(parser.data.entities, parser.data.triggers).forEach(el => {
@@ -165,6 +170,21 @@ const Main = (function() {
165170
links.push(link);
166171
});
167172

173+
parser.data.syntax.forEach(syn => {
174+
// create a link between the trigger and each of its arguments
175+
const trigger = entities.find(word => word.eventIds.indexOf(syn.trigger) > -1);
176+
const arguments = syn.arguments.map(arg => {
177+
let anchor = words.find(w => w.syntaxId === arg.id);
178+
return { anchor, type: arg.type };
179+
});
180+
181+
// create link
182+
const link = new Link(syn.id, trigger, arguments);
183+
184+
// push link to link array
185+
links.push(link);
186+
});
187+
168188
return [ words, links, clusters ];
169189
}
170190

js2/parser.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ const Parser = (function() {
1010
function parseData(data) {
1111
/* first get string tokens from the syntaxData */
1212
_text = data.syntaxData.text;
13-
1413
_tokens = data.syntaxData.entities
15-
.map(x => x[2][0])
16-
.sort((a, b) => a[0] - b[0])
17-
.map((interval, i) => {
14+
.sort((a, b) => a[2][0][0] - b[2][0][0])
15+
.map(x => {
1816
return {
19-
text: _text.substring(interval[0], interval[1]),
20-
startIndex: interval[0],
21-
endIndex: interval[1]
22-
};
17+
text: _text.substring(x[2][0][0], x[2][0][1]),
18+
id: x[0],
19+
type: x[1],
20+
startIndex: x[2][0][0],
21+
endIndex: x[2][0][1]
22+
}
2323
});
2424

2525
function findTokenByIndex([i1, i2]) {
@@ -28,6 +28,19 @@ const Parser = (function() {
2828
return [startToken, endToken];
2929
}
3030

31+
const syntax = data.syntaxData.relations.map(arr => {
32+
return {
33+
id: arr[0],
34+
trigger: arr[2][0][1],
35+
arguments: [
36+
{
37+
id: arr[2][1][1],
38+
type: arr[1]
39+
}
40+
]
41+
};
42+
});
43+
3144
/* parse the event data: entities, triggers, events, and relations */
3245
const e = data.eventData;
3346
const entities = e.entities.map(arr => {
@@ -78,9 +91,9 @@ const Parser = (function() {
7891
entities,
7992
triggers,
8093
events,
81-
relations
94+
relations,
95+
syntax
8296
};
83-
_tokens = _tokens.map(token => token.text);
8497
}
8598

8699
class Parser {

0 commit comments

Comments
 (0)