summaryrefslogtreecommitdiff
path: root/scripts/textanalysis.js
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-10-06 15:04:37 +0300
committerAlon Levy <alon@pobox.com>2014-10-07 08:51:35 +0300
commit9b2394dafb28b870e0339fd3cc137cb80ccd6dd4 (patch)
treef45c30e62c611fdd2140f3439349d4bdcf23381b /scripts/textanalysis.js
parent764dbe75a254d5a40fdefbebfb529add1d9dfb90 (diff)
textanalysis: workaround undefined or double link addition
Diffstat (limited to 'scripts/textanalysis.js')
-rw-r--r--scripts/textanalysis.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/scripts/textanalysis.js b/scripts/textanalysis.js
index 744d7bd1..55283ece 100644
--- a/scripts/textanalysis.js
+++ b/scripts/textanalysis.js
@@ -77,11 +77,29 @@ var textAnalyser2 = function (newtext, finalize) {
var typesetter, abnormalGraph;
var verb;
var l, n, j;
+ var link_hash = {};
+ var yell_bug = false; // TODO: fix both issues
function addNode(id, type, state) {
ret.nodes.push({'id':id, 'type':type, 'state':state});
}
function addLink(src, dst, name, state) {
+ if (!src || !dst) {
+ if (yell_bug) {
+ console.log('bug - adding link (' + src + ', ' + dst + ')');
+ }
+ return;
+ }
+ if (link_hash[src] && link_hash[src][dst]) {
+ if (yell_bug) {
+ console.log('bug - adding link twice (' + src + ', ' + dst + ')');
+ }
+ return;
+ }
+ if (!link_hash[src]) {
+ link_hash[src] = {};
+ }
+ link_hash[src][dst] = 1;
ret.links.push({'sourceId':src, 'targetId':dst, 'name':name ? name.trim() : "", 'state':state});
}