Skip to content

Commit d8ce894

Browse files
committed
initial attempt at link2link graph
1 parent e316f71 commit d8ce894

File tree

2 files changed

+116
-17
lines changed

2 files changed

+116
-17
lines changed

index.html

Lines changed: 102 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
wordObjs.forEach(w => w.tag = w.data.syntaxData.tag);
191191
}
192192
else {
193-
wordObjs.forEach(w => w.tag = '');
193+
wordObjs.forEach(w => w.tag = w.data.bioData.tag);
194194
}
195195
redrawWords(wordObjs);
196196
}
@@ -251,6 +251,9 @@
251251
charLocationInSentence: sentence.startOffsets[k],
252252
syntaxData: {
253253
tag: sentence.tags[k]
254+
},
255+
bioData: {
256+
tag: ''
254257
}
255258
};
256259

@@ -292,6 +295,7 @@
292295
words: wordDataArray.slice(start, end),
293296
label: mention.displayLabel,
294297
id: mention.id,
298+
charOffset: mention.characterStartOffset,
295299
type: mention.type
296300
};
297301
mentionDataArray.push(link);
@@ -306,25 +310,43 @@
306310
}
307311
var link = {
308312
sourceId: mention.arguments.controller.map(arg => arg.id),
309-
destinationId: {
313+
destinationId: [{
310314
name: "controlled",
311315
id: mention.arguments.controlled.map(arg => arg.id)
312-
},
316+
}],
313317
label: mention.displayLabel,
314318
id: mention.id,
319+
charOffset: mention.characterStartOffset,
315320
type: mention.type
316321
};
317322

318323
mentionDataArray.push(link);
319324
return link;
320325
case "CorefEventMention":
321326
// has a trigger & argument(s)
327+
328+
if (mention.trigger.type == "TextBoundMention") {
329+
let start = wordDataMap[[mention.trigger.document, mention.trigger.sentence, mention.trigger.tokenInterval.start].join('-')];
330+
let end = wordDataMap[[mention.trigger.document, mention.trigger.sentence, mention.trigger.tokenInterval.end].join('-')];
331+
332+
var link = {
333+
sourceId: null,
334+
destinationId: null,
335+
words: wordDataArray.slice(start, end),
336+
label: mention.trigger.labels[0],
337+
id: mention.trigger.id,
338+
charOffset: mention.trigger.characterStartOffset,
339+
type: mention.trigger.type
340+
};
341+
mentionDataArray.push(link);
342+
}
322343
var link = {
323344
sourceId: [mention.trigger.id],
324345
destinationId: Object.keys(mention.arguments).map(key => {
325346

326347
return {
327348
name: key,
349+
charOffset: mention.characterStartOffset,
328350
id: mention.arguments[key].map(arg => arg.id)
329351
}
330352

@@ -344,7 +366,9 @@
344366

345367
// done parsing into semi-flat datasets...
346368

347-
console.log(wordDataArray, syntaxDataArray, mentionDataArray);
369+
console.log('words',wordDataArray);
370+
console.log('pos',syntaxDataArray);
371+
console.log('events',mentionDataArray);
348372

349373
wordDataArray.forEach(function(word) {
350374
let idx = wordObjs.length;
@@ -355,29 +379,93 @@
355379
else {
356380
w.tag = '';
357381
}
382+
// create circular reference between data object and Word instance
383+
word.object = w;
358384
w.data = word;
359385
wordObjs.push(w);
360386
})
361387

362388
linkObjs = [];
363389
if (State.annotationStyle == 'POS') {
364390
// syntaxDataArray.forEach
365-
}
366-
else {
391+
// }
392+
// else {
367393
mentionDataArray.forEach(function(link) {
394+
if (link.words) {
395+
396+
// TODO: bundle words in a textbound annotation
397+
let linkObject = new Link(
398+
link.words[0].object,
399+
link.words[link.words.length-1].object,
400+
directions.NONE,
401+
styles.simpleLine,
402+
link.label,
403+
texts.linkText
404+
);
405+
406+
// create circular reference to link and data
407+
linkObject.data = link;
408+
link.object = linkObject;
409+
linkObjs.push( linkObject );
410+
createLink(linkObject);
411+
}
412+
else {
413+
// TODO: bundle links
414+
link.sourceId.forEach(function(source) {
415+
link.destinationId.forEach(function(destination) {
416+
417+
let sourceData = mentionDataArray.find(l => l.id == source);
418+
let destinationData = mentionDataArray.find(l => l.id == destination.id);
419+
420+
let ltr = sourceData.charOffset < destinationData.charOffset;
421+
let style;
422+
switch (link.label) {
423+
case "Positive_regulation":
424+
style = ltr ? styles.gradientLine2 : styles.gradientLine2r;
425+
break;
426+
case "Negative_regulation":
427+
style = ltr ? styles.gradientLine1 : styles.gradientLine1r;
428+
break;
429+
default:
430+
style = styles.noneLine;
431+
break;
432+
}
368433

369-
})
370-
}
434+
if (sourceData.object && destinationData.object) {
435+
let linkObject = new Link(
436+
sourceData.object,
437+
destinationData.object,
438+
ltr ? 1 : -1,
439+
style,
440+
link.label,
441+
texts.linkText
442+
);
443+
444+
// create circular reference to link and data
445+
linkObject.data = link;
446+
link.object = linkObject;
447+
linkObjs.push( linkObject );
448+
createLink(linkObject);
449+
}
450+
else {
451+
console.log(':(')
452+
}
371453

372454

455+
});
456+
});
457+
}
458+
});
459+
}
460+
373461
// draw
374-
linkObjs.sort(function(a, b) {
375-
var d1 = Math.abs(a.s.idx - a.e.idx);
376-
var d2 = Math.abs(b.s.idx - b.e.idx);
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);
377465

378-
return d1 - d2;
379-
});
380-
linkObjs.forEach(createLink);
466+
// return d1 - d2;
467+
// });
468+
// linkObjs.forEach(createLink);
381469

382470
drawWords(wordObjs);
383471
drawLinks(linkObjs);

js/style.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,13 @@ function setupStyles(svg) {
320320
var styleArr = {};
321321

322322
var ng_f = new LinearGradient(svg, '#ffff00', '#ff00ff');
323+
var ng_f2 = new LinearGradient(svg, '#ff00ff', '#ffff00');
324+
323325
var ng_b = new LinearGradient(svg, '#00ff00', '#0000ff');
326+
var ng_b2 = new LinearGradient(svg, '#0000ff', '#00ff00');
324327

328+
// var ng_f2 = new LinearGradient(svg, '#fc0', '#f88');
329+
// var ng_b2 = new LinearGradient(svg, '#f88', '#fc0');
325330

326331
//this is how you create a linear gradient, which can be used for fills and strokes (and can also be applied to text fills and strokes)
327332
//var ng_f = new LinearGradient(draw, (stop) => { stop.at(0, '#f00'); stop.at(1.0, '#00f') } );
@@ -335,17 +340,23 @@ function setupStyles(svg) {
335340
styleArr.gradientLine1 = new LineStyle(ng_f, 4, 0.5);
336341
styleArr.gradientLine1.hovering(ng_f, 8, 0.5);
337342

343+
styleArr.gradientLine1r = new LineStyle(ng_f2, 4, 0.5);
344+
styleArr.gradientLine1r.hovering(ng_f2, 8, 0.5);
345+
338346
styleArr.gradientLine2 = new LineStyle(ng_b, 4, 0.5);
339347
styleArr.gradientLine2.hovering(ng_b, 8, 0.5);
340348

349+
styleArr.gradientLine2r = new LineStyle(ng_b2, 4, 0.5);
350+
styleArr.gradientLine2r.hovering(ng_b2, 8, 0.5);
351+
341352
styleArr.bothLine = new LineStyle("#ff0000", 1, 0.5, "2,5,2");
342353
styleArr.bothLine.hovering("#ff0000", 4, 0.5, "2,5,2");
343354

344355
styleArr.noneLine = new LineStyle("#0000ff", 1, 0.5, "2,2");
345-
styleArr.noneLine.hovering("#0000ff", 4, 0.5, "2,2");
356+
styleArr.noneLine.hovering("#0000ff", 2, 0.5, "2,2");
346357

347-
styleArr.simpleLine = new LineStyle("#000000", 4, 0.5);
348-
styleArr.simpleLine.hovering("#000000", 8, 0.5);
358+
styleArr.simpleLine = new LineStyle("#000000", 2, 0.5);
359+
styleArr.simpleLine.hovering("#000000", 4, 0.5);
349360

350361
styleArr.hiddenLine = new LineStyle("#ffffff", 6, 0.0);
351362

0 commit comments

Comments
 (0)