From 9b2394dafb28b870e0339fd3cc137cb80ccd6dd4 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 6 Oct 2014 15:04:37 +0300 Subject: textanalysis: workaround undefined or double link addition --- scripts/textanalysis.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'scripts') 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}); } -- cgit v1.3.1