summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-08-19 19:50:02 +0300
committerAlon Levy <alon@pobox.com>2014-08-19 19:50:02 +0300
commitb7723546a8b9b07c724e4be062c0c0c58501478f (patch)
treec35f65440fc3a2ac0dd62a97f33d3ae49f58d9fd /scripts
parentcca5a2dbc2e0a92bee72b56d9a708a641d4153a9 (diff)
textanalysis: remove usage of $
Diffstat (limited to 'scripts')
-rw-r--r--scripts/textanalysis-ui.js19
-rw-r--r--scripts/textanalysis.js14
2 files changed, 24 insertions, 9 deletions
diff --git a/scripts/textanalysis-ui.js b/scripts/textanalysis-ui.js
index de163056..f5d2d5fe 100644
--- a/scripts/textanalysis-ui.js
+++ b/scripts/textanalysis-ui.js
@@ -7,11 +7,22 @@ $('#textanalyser').autocompleteTrigger({
source: sugg
});
+// TODO - hide this in a scope
function analyzeSentence(sentence, finalize)
{
var d = TextAnalyser2(graph, sentence, finalize);
- for (var k in d.suggestions) {
- sugg[k] = k;
+ for (var k in d.sugg) {
+ sugg.push(k);
+ }
+ switch (d.state) {
+ case ANALYSIS_NODE_START:
+ $('.typeselection').css({top:window.innerHeight/2-115,left:window.innerWidth/2-325});
+ $('.typeselection').html('<table><tr><td style="height:28px"></td></tr><tr><td>Use [TAB] key to pick a type</td></tr></table>');
+ break;
+ case ANALYSIS_LINK:
+ $('.typeselection').css('top', -300);
+ $('.typeselection').css('left', 0);
+ break;
}
}
@@ -24,7 +35,7 @@ $("#textanalyser").keypress(function(e) {
if(!suggestionChange){
text = $('#textanalyser').val();
$('#textanalyser').val("");
- TextAnalyser2(graph, text, true);
+ analyzeSentence(text, true);
typeStack=[];
} else {
suggestionChange=false;
@@ -116,7 +127,7 @@ window.setInterval(function() {
if(text.length*8>500)$('#textanalyser').css('width',text.length*8+20);
// text changed
text = $('#textanalyser').val();
- TextAnalyser2(graph, text, false);
+ analyzeSentence(text, false);
suggestionChange=false;
}
}, 5);
diff --git a/scripts/textanalysis.js b/scripts/textanalysis.js
index 3f50387a..5c69edb9 100644
--- a/scripts/textanalysis.js
+++ b/scripts/textanalysis.js
@@ -10,6 +10,8 @@ var ExecutionStack = [];
var lastnode;
+var ANALYSIS_NODE_START = 'ANALYSIS_NODE_START';
+var ANALYSIS_LINK = 'ANALYSIS_LINK';
function TextAnalyser2(graph, newtext, finalize) {
var segment = [],
@@ -24,6 +26,7 @@ function TextAnalyser2(graph, newtext, finalize) {
var ANDcase = false;
var ANDcount = 0;
var prefix = "";
+ var ret = {};
//Sentence Sequencing
//Build the words and cuts the main elements
@@ -120,6 +123,7 @@ function TextAnalyser2(graph, newtext, finalize) {
var typesetter = "";
if (finalize === true) {
typesetter = "perm";
+ var sugg = []
for (var n = 0; n < newnodes.length; n++) {
if (Unique(newnodes[n])) {
if(newnodes[n].split(" ").length>1){
@@ -131,6 +135,7 @@ function TextAnalyser2(graph, newtext, finalize) {
}
}
sugg.push(text);
+ ret.sugg = sugg;
} else {
typesetter = "temp";
}
@@ -172,8 +177,7 @@ function TextAnalyser2(graph, newtext, finalize) {
graph.addNode("new node", typeStack[nodeindex], "temp");
if (!abnormalGraph){graph.addLink(newnodes[nodeindex - 1], "new node", newlinks[linkindex], "temp");
ANDconnect("new node");}
- $('.typeselection').css({top:window.innerHeight/2-115,left:window.innerWidth/2-325});
- $('.typeselection').html('<table><tr><td style="height:28px"></td></tr><tr><td>Use [TAB] key to pick a type</td></tr></table>');
+ ret.state = ANALYSIS_NODE_START;
break;
case "NODE":
@@ -189,9 +193,7 @@ function TextAnalyser2(graph, newtext, finalize) {
graph.addNode("new node", "empty", "temp");
if (!abnormalGraph){ graph.addLink(newnodes[nodeindex - 1], "new node", newlinks[linkindex], "temp");
ANDconnect("new node");}
-
- $('.typeselection').css('top', -300);
- $('.typeselection').css('left', 0);
+ ret.state = ANALYSIS_LINK;
break;
}
@@ -243,6 +245,8 @@ function TextAnalyser2(graph, newtext, finalize) {
//UPDATE GRAPH ONCE
graph.update();
+
+ return ret;
}