diff options
| author | Alon Levy <alon@pobox.com> | 2014-09-21 16:04:20 +0300 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-09-21 16:04:20 +0300 |
| commit | af27835be74279fe894318fe65d097ddff7384b0 (patch) | |
| tree | 723d07d023d3f92366ea0d434a5183916cc482b1 /scripts/textanalysis-ui.js | |
| parent | 9aa40fd4881538878fa68b035f79a72cfaf13b29 (diff) | |
textanalysis: multiple changes to autocomplete
1. move the sugg variable to textanalysis.js instead of the ui part
2. use a callback for the autocomplete widget (it supports three
options: array, string as url for a json returning service, or callback)
3. use a dictionary instead of an array to keep the list of suggestions.
We iterate on the dictionary instead of using a Trie or some other
datastructure in the callback. But the dictionary avoids iteration when
adding a word. Overall a loss in performance, but not noticeable.
Googling / memory suggests a Trie is what we want here, but I'm
postponing that for later. See:
http://ejohn.org/blog/javascript-trie-performance-analysis
Diffstat (limited to 'scripts/textanalysis-ui.js')
| -rw-r--r-- | scripts/textanalysis-ui.js | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/scripts/textanalysis-ui.js b/scripts/textanalysis-ui.js index b9e69ca7..6d6e2f5a 100644 --- a/scripts/textanalysis-ui.js +++ b/scripts/textanalysis-ui.js @@ -1,19 +1,15 @@ var text = ""; // Last text of sentence -var sugg = []; // suggestions for autocompletion of node names $('#textanalyser').autocompleteTrigger({ triggerStart: '#', triggerEnd: '', - source: sugg + source: autocompleteCallback }); // TODO - hide this in a scope function analyzeSentence(sentence, finalize) { var ret = TextAnalyser2(sentence, finalize); - for (var k in ret.sugg) { - sugg.push(ret.sugg[k]); - } switch (ret.state) { case ANALYSIS_NODE_START: $('.typeselection').css({top:window.innerHeight/2-115,left:window.innerWidth/2-325}); |
