diff options
| author | Alon Levy <alon@pobox.com> | 2014-10-08 18:41:47 +0300 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-10-08 18:41:47 +0300 |
| commit | ac30b3ef25aa92ca501c82a94dd38679eca93c0c (patch) | |
| tree | ec8fd12613f9f5ef37101b2e7ebcf18f0da551f9 /tests/test_analyzer.js | |
| parent | 3c86c9dd12ea0be0d353020db7a3d0582944a5cd (diff) | |
add tests_analyzer
node test_analyzer.js '#a and #b and #c are cool' | dot -Tpng > /tmp/temp.png; xdg-open /tmp/temp.png
Todo: use stdin, then it will be a total pipe
Todo: make this a rhizi debug feature that displays the image in the
browser?
Diffstat (limited to 'tests/test_analyzer.js')
| -rw-r--r-- | tests/test_analyzer.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/test_analyzer.js b/tests/test_analyzer.js new file mode 100644 index 00000000..9aede596 --- /dev/null +++ b/tests/test_analyzer.js @@ -0,0 +1,67 @@ +var fs = require('fs'), + jsdom = require('jsdom'); + +var script_filenames = [ + "external/scripts/d3/d3.js", + "external/scripts/jquery.js", + "external/scripts/jquery-ui.js", + "external/scripts/autocomplete.js", + + "scripts/caret.js", + "scripts/history.js", + "scripts/rhizicore.js", + "scripts/textanalysis.js", + "scripts/textanalysis-ui.js", + "scripts/buttons.js", + "scripts/drag_n_drop.js", + "scripts/robot.js", + "scripts/watchdog.js", + "scripts/gant.js"].map(function(x) { return "../" + x; }); + +function dump_nodes(window) { + var nodes = window.force.nodes(); + for(var i = 0 ; i < nodes.length; ++i) { + console.log('nodes[' + nodes[i].id + '/' + nodes[i].type + '].[xy] = (' + nodes[i].x + ',' + nodes[i].y + ')'); + } +} + +function dump_graphviz(window) { + var i; + var nodes = window.force.nodes(); + var links = window.force.links(); + var q = function(s) { + if (s.search(' ') == -1) { + return s; + } + return '"' + s + '"'; + }; + + console.log('digraph {'); + for (i = 0 ; i < nodes.length; ++i) { + if (nodes[i].type == 'bubble') { + console.log(' BUBBLE;'); + } else { + console.log(' ' + q(nodes[i].name) + ';'); + } + } + for (i = 0 ; i < links.length; ++i) { + var link = links[i]; + console.log(' ' + q(link.source.name) + ' -> ' + q(link.target.name) + ';'); + } + console.log('}'); +} + +var done = function (errors, window) { + window.analyzeSentence(process.argv.join(" "), true); + dump_graphviz(window); + process.exit(); +} + +var env = jsdom.env({ + scripts: script_filenames, + html: "<html><body></body></html>", + created: function(errors, window) { + window.console.log = console.log; // slightly evil + window.process = process; // more evil + }, + done: done}); |
