|
190 | 190 | wordObjs.forEach(w => w.tag = w.data.syntaxData.tag); |
191 | 191 | } |
192 | 192 | else { |
193 | | - wordObjs.forEach(w => w.tag = ''); |
| 193 | + wordObjs.forEach(w => w.tag = w.data.bioData.tag); |
194 | 194 | } |
195 | 195 | redrawWords(wordObjs); |
196 | 196 | } |
|
251 | 251 | charLocationInSentence: sentence.startOffsets[k], |
252 | 252 | syntaxData: { |
253 | 253 | tag: sentence.tags[k] |
| 254 | + }, |
| 255 | + bioData: { |
| 256 | + tag: '' |
254 | 257 | } |
255 | 258 | }; |
256 | 259 |
|
|
292 | 295 | words: wordDataArray.slice(start, end), |
293 | 296 | label: mention.displayLabel, |
294 | 297 | id: mention.id, |
| 298 | + charOffset: mention.characterStartOffset, |
295 | 299 | type: mention.type |
296 | 300 | }; |
297 | 301 | mentionDataArray.push(link); |
|
306 | 310 | } |
307 | 311 | var link = { |
308 | 312 | sourceId: mention.arguments.controller.map(arg => arg.id), |
309 | | - destinationId: { |
| 313 | + destinationId: [{ |
310 | 314 | name: "controlled", |
311 | 315 | id: mention.arguments.controlled.map(arg => arg.id) |
312 | | - }, |
| 316 | + }], |
313 | 317 | label: mention.displayLabel, |
314 | 318 | id: mention.id, |
| 319 | + charOffset: mention.characterStartOffset, |
315 | 320 | type: mention.type |
316 | 321 | }; |
317 | 322 |
|
318 | 323 | mentionDataArray.push(link); |
319 | 324 | return link; |
320 | 325 | case "CorefEventMention": |
321 | 326 | // 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 | + } |
322 | 343 | var link = { |
323 | 344 | sourceId: [mention.trigger.id], |
324 | 345 | destinationId: Object.keys(mention.arguments).map(key => { |
325 | 346 |
|
326 | 347 | return { |
327 | 348 | name: key, |
| 349 | + charOffset: mention.characterStartOffset, |
328 | 350 | id: mention.arguments[key].map(arg => arg.id) |
329 | 351 | } |
330 | 352 |
|
|
344 | 366 |
|
345 | 367 | // done parsing into semi-flat datasets... |
346 | 368 |
|
347 | | - console.log(wordDataArray, syntaxDataArray, mentionDataArray); |
| 369 | + console.log('words',wordDataArray); |
| 370 | + console.log('pos',syntaxDataArray); |
| 371 | + console.log('events',mentionDataArray); |
348 | 372 |
|
349 | 373 | wordDataArray.forEach(function(word) { |
350 | 374 | let idx = wordObjs.length; |
|
355 | 379 | else { |
356 | 380 | w.tag = ''; |
357 | 381 | } |
| 382 | + // create circular reference between data object and Word instance |
| 383 | + word.object = w; |
358 | 384 | w.data = word; |
359 | 385 | wordObjs.push(w); |
360 | 386 | }) |
361 | 387 |
|
362 | 388 | linkObjs = []; |
363 | 389 | if (State.annotationStyle == 'POS') { |
364 | 390 | // syntaxDataArray.forEach |
365 | | - } |
366 | | - else { |
| 391 | + // } |
| 392 | + // else { |
367 | 393 | 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 | + } |
368 | 433 |
|
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 | + } |
371 | 453 |
|
372 | 454 |
|
| 455 | + }); |
| 456 | + }); |
| 457 | + } |
| 458 | + }); |
| 459 | + } |
| 460 | + |
373 | 461 | // 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); |
377 | 465 |
|
378 | | - return d1 - d2; |
379 | | - }); |
380 | | - linkObjs.forEach(createLink); |
| 466 | + // return d1 - d2; |
| 467 | + // }); |
| 468 | + // linkObjs.forEach(createLink); |
381 | 469 |
|
382 | 470 | drawWords(wordObjs); |
383 | 471 | drawLinks(linkObjs); |
|
0 commit comments