annotate hip.js @ 13:8dcc88f93829

Broke up hip.js into some smaller js files
author jonathandicarlo@localhost
date Wed, 02 Jul 2008 12:04:46 -0700
parents aa56c4aa5b11
children a26372118854
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
1 function dictDeepCopy( dict ) {
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
2 var newDict = {};
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
3 for (var i in dict ) {
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
4 newDict[i] = dict[i];
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
5 }
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
6 return newDict;
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
7 };
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
8
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
9 function dictKeys( dict ) {
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
10 return [ key for ( key in dict ) ];
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
11 }
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
12
11
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
13 function getSelection () {
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
14 return $("#fake-selection").attr( "value" );
11
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
15 }
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
16
12
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
17 var wordsThatReferToSelection = [ "this", "that", "it", "selection", "him", "her", "them"];
11
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
18
5
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
19 function ParsedSentence( verb, DO, modifiers ) {
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
20 this._init( verb, DO, modifiers );
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
21 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
22 ParsedSentence.prototype = {
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
23 _init: function( verb, DO, modifiers ) {
5
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
24 /* modifiers is dictionary of preposition: noun */
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
25 this._verb = verb;
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
26 this._DO = DO;
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
27 this._modifiers = modifiers;
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
28 },
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
29
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
30 getCompletionText: function() {
6
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
31 // return plain text that we should set the input box to if user hits
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
32 // space bar on this sentence.
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
33 var sentence = this._verb._name;
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
34 if ( this._DO ) {
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
35 sentence = sentence + " " + this._DO;
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
36 }
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
37 for ( var x in this._modifiers ) {
12
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
38 if ( this._modifiers[x] ) {
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
39 sentence = sentence + " " + x + " " + this._modifiers[x];
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
40 }
6
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
41 }
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
42 return sentence;
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
43 },
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
44
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
45 getDisplayText: function() {
6
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
46 // returns html formatted sentence for display in suggestion list
5
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
47 var sentence = this._verb._name;
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
48 if ( this._verb._DOType ) {
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
49 if ( this._DO ) {
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
50 sentence = sentence + " " + this._DO;
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
51 } else {
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
52 sentence = sentence + " <span class=\"needarg\">(" + this._verb._DOLabel + ")</span>";
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
53 }
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
54 }
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
55
6
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
56 for ( var x in this._verb._modifiers ) { // was this._verb._modifiers
5
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
57 if ( this._modifiers[ x ] ) {
6
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
58 sentence = sentence + " <b>" + x + " " + this._modifiers[x] + "</b>";
5
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
59 } else {
6
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
60 sentence = sentence + " <span class=\"needarg\">(" + x + " " + this._verb._modifiers[x]._name + ")</span>";
5
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
61 }
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
62 }
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
63 return sentence;
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
64 },
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
65
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
66 getDescription: function() {
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
67 // returns a string describing what the sentence will do if executed
6
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
68 return this._verb.getDescription( this._DO, this._modifiers );
5
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
69 }
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
70
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
71 };
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
72
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
73 function QuerySource(verbList) {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
74 this._init(verbList);
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
75 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
76 QuerySource.prototype = {
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
77 _init: function(verbList) {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
78 this._verbList = verbList; //arrayof Verb objects to use for completions
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
79 this._lockedInSentence = null;
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
80 this._hilitedSuggestion = 0;
6
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
81 this._suggestionList = []; // a list of ParsedSentences.
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
82 },
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
83
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
84 updateSuggestionList: function( query ) {
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
85 this._suggestionList = [];
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
86 var completions = [];
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
87 var words = query.split( " " );
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
88 for ( var x in this._verbList ) {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
89 var verb = this._verbList[x];
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
90 if ( verb.match( words[0] ) ) {
5
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
91 completions = verb.getCompletions( words.slice(1) );
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
92 this._suggestionList = this._suggestionList.concat( completions );
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
93 }
6
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
94 }
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
95 // TODO sort in order of match quality
12
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
96 this._hilitedSuggestion = 1; // hilight the first suggestion by default
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
97 },
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
98
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
99 getSuggestionsAsHtml : function() {
6
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
100 return [ this._suggestionList[x].getDisplayText() for ( x in this._suggestionList ) ];
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
101 },
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
102
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
103 getDescriptionText: function() {
7
aab0d14248f5 All suggested completions now return sensible descriptions of what they would do if executed.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 6
diff changeset
104 if ( this._suggestionList.length == 0 ) {
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
105 return "You got the magic stick. Type some commands!";
7
aab0d14248f5 All suggested completions now return sensible descriptions of what they would do if executed.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 6
diff changeset
106 }
aab0d14248f5 All suggested completions now return sensible descriptions of what they would do if executed.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 6
diff changeset
107 var h = this._hilitedSuggestion;
aab0d14248f5 All suggested completions now return sensible descriptions of what they would do if executed.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 6
diff changeset
108 if ( h == 0 ) {
12
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
109 return "Executes your input literally, with no autocompletion.";
7
aab0d14248f5 All suggested completions now return sensible descriptions of what they would do if executed.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 6
diff changeset
110 } else {
aab0d14248f5 All suggested completions now return sensible descriptions of what they would do if executed.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 6
diff changeset
111 h = h - 1;
aab0d14248f5 All suggested completions now return sensible descriptions of what they would do if executed.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 6
diff changeset
112 }
aab0d14248f5 All suggested completions now return sensible descriptions of what they would do if executed.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 6
diff changeset
113 var sentence = this._suggestionList[h];
aab0d14248f5 All suggested completions now return sensible descriptions of what they would do if executed.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 6
diff changeset
114 return sentence.getDescription();
aab0d14248f5 All suggested completions now return sensible descriptions of what they would do if executed.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 6
diff changeset
115 },
aab0d14248f5 All suggested completions now return sensible descriptions of what they would do if executed.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 6
diff changeset
116
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
117 indicationDown: function( ) {
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
118 this._hilitedSuggestion ++;
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
119 if ( this._hilitedSuggestion > this._suggestionList.length ) {
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
120 this._hilitedSuggestion = 0;
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
121 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
122 },
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
123
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
124 indicationUp: function() {
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
125 this._hilitedSuggestion --;
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
126 if ( this._hilitedSuggestion < 0 ) {
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
127 this._hilitedSuggestion = this._suggestionList.length;
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
128 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
129 },
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
130
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
131 getHilitedSuggestion: function() {
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
132 return this._hilitedSuggestion - 1; // because 0 means no hilite
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
133 // and the suggestion list starts at 1... fencepost!
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
134 },
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
135
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
136 autocomplete: function( query ) {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
137 var newText;
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
138 var hilited = this.getHilitedSuggestion();
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
139 if ( hilited > -1 ) {
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
140 newText = this._suggestionList[ hilited ].getCompletionText() + " ";
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
141 } else {
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
142 newText = query;
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
143 }
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
144 return newText;
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
145 },
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
146
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
147 clear: function() {
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
148 this._suggestionList = [];
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
149 this._hilitedSuggestion = 0;
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
150 this._lockedInSentence = null;
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
151 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
152 };
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
153
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
154 var gQs = new QuerySource([ fly, define, google, go, close, open, translate, email, nuke, encrypt, wiki ]);
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
155
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
156 function makeSuggestionHtml( tagName, list, hilitedNumber ) {
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
157 var result = "";
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
158 var openingTag = "";
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
159 var closingTag = "</" + tagName + ">";
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
160
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
161 for (var i = 0; i < list.length; i++) {
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
162 if ( i == hilitedNumber ) {
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
163 openingTag = "<" + tagName + " class=\"hilited\">";
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
164 } else {
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
165 openingTag = "<" + tagName + ">";
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
166 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
167 result += (openingTag + list[i] + closingTag );
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
168 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
169 return result;
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
170 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
171
12
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
172 function updateDisplay( number ) {
6
98935af12b04 Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 5
diff changeset
173 var suggestions = gQs.getSuggestionsAsHtml();
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
174 var hilitedSuggestion = gQs.getHilitedSuggestion();
7
aab0d14248f5 All suggested completions now return sensible descriptions of what they would do if executed.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 6
diff changeset
175 var description = gQs.getDescriptionText();
aab0d14248f5 All suggested completions now return sensible descriptions of what they would do if executed.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 6
diff changeset
176 $("#status-line").html( description );
12
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
177 if ( hilitedSuggestion == -1 ) {
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
178 // TODO set #search-box background to green, not sure how
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
179 } else {
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
180 // TODO set #search-box background to white, not sure how
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
181 }
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
182 var ac = $("#autocomplete-popup");
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
183 ac.html( makeSuggestionHtml( "div", suggestions, hilitedSuggestion ) );
7
aab0d14248f5 All suggested completions now return sensible descriptions of what they would do if executed.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 6
diff changeset
184 ac.show();
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
185 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
186
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
187 function searchBoxQuery( event ) {
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
188 // TODO: if the event is an 'esc' key, clear the input field.
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
189 // If the event is an 'up arrow' or 'down arrow' key, change the
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
190 // indication.
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
191
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
192 // key is event.which
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
193 // esc is 27
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
194 // up arrow is 38
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
195 // down arrow is 40
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
196 // enter is 13
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
197 // space is 32
11
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
198 var input = event.target.value;
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
199 switch( event.which ) {
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
200 case 27: //esc
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
201 event.target.value = "";
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
202 gQs.clear();
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
203 break;
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
204 case 38: // up arrow
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
205 gQs.indicationUp();
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
206 break;
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
207 case 40: // down arrow
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
208 gQs.indicationDown();
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
209 break;
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
210 case 13: // enter
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
211 gQs.execute();
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
212 break;
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
213 case 32: // spacebar
12
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
214 //input = gQs.autocomplete( input );
11
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
215 gQs.updateSuggestionList( input );
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
216 break;
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
217 default:
11
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
218 gQs.updateSuggestionList( input );
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
219 break;
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
220 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
221
12
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
222 updateDisplay( event.which );
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
223
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
224 }
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
225
0
9e6054e41bdc Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
226 $(document).ready( function() {
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents: 12
diff changeset
227 $("#status-line").html( "All you gotta do is rub that lamp." );
0
9e6054e41bdc Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
228 $("#search-box").focus();
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
229 $("#search-box").keyup( searchBoxQuery );
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
230 $("#autocomplete-popup").css(
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
231 "width",
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
232 $("#search-box").css("width")
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
233 );
0
9e6054e41bdc Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
234 });
5
a049cb93db46 Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 4
diff changeset
235
10
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
236 /* Where to go next:
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
237
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
238 1. Noun-first completions. If you type "london", it matches no verb, so
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
239 the parser looks at the known noun categories, sees that "london" could be
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
240 a city, and then looks for verbs that take cities and suggests
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
241 fly to london
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
242 fly from london
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
243 nuke london
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
244
12
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
245 3. Allow the possibility of a multiple-word indirect-object.
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
246 (Maybe pass the whole rest of the sentence past the preposition as an argument
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
247 to the noun class, and as the noun class returns the list of suggestions,
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
248 it also returns a count of how many words it has used.)
10
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
249
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
250 4. Preview output of topmost or hilited command, as you type.
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
251
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
252 5. When a command is executed, put its output in a special buffer that forms
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
253 the implicit selection for the next command. In this way commands can be
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
254 chained conversationally, without the need for a special word or key to
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
255 link them together.
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
256
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
257 6. More complex datatypes, like dates, that allow for multiple input formats.
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
258 ( see http://www.datejs.com/ )
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
259
11
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
260 7. Make verbs more tolerant of text that doesn't match the direct object.
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
261 First of all, if the direct object text is just spaces (and how does that
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
262 happen?) it should be discarded. And then, if there's input that can't
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
263 be used, maybe discard it or put it in red or something, rather than
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
264 rejecting it.
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
265
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
266 8. Tweak what text gets autocompleted when you arrow down to something
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
267 and hit space. Right now it's putting in prepositions that you haven't
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
268 actually typed.
9e18b8d8c936 Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
jonathandicarlo@localhost
parents: 10
diff changeset
269
12
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
270 9. Learn how frequently you use different completions (use the algorithm
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
271 we've already developed) and rank accordingly.
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
272
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
273 10. Start sorting matches by goodness.
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
274
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
275 11. Have nounTypes that can learn new entries!!!
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
276
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
277 12. Make it so when hilite is 0, the literal input is hilited green
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
278 and an appropriate suggestion is displayed!
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
279
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
280 13. Break this file into multiple files, it's getting really big.
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
281
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
282 14. Use Tab to mean "copy hilited suggestion to input box"
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
283 (No, we can't do that! Because tab changes focus away from the input
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
284 box.)
aa56c4aa5b11 You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 11
diff changeset
285
10
8f6b1c89d8de With the basic demo functionality ready to go, I added a list of What To Do Next.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 9
diff changeset
286 */