annotate hip.js @ 6:98935af12b04

Debugged the recursive part of the parsing algorithm, so it now recognizes multiple prepositions in any order. Still some bugs.
author jonathandicarlo@jonathan-dicarlos-macbook-pro.local
date Wed, 14 May 2008 13:25:17 -0700
parents a049cb93db46
children aab0d14248f5
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
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
13 function NounType( name, expectedWords ) {
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
14 this._init( name, expectedWords );
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
15 }
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
16 NounType.prototype = {
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
17 _init: function( name, expectedWords ) {
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
18 this._name = name;
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
19 this._expectedWords = expectedWords; // an array
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
20 },
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 match: function( fragment ) {
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
23 var suggs = this.suggest( fragment );
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
24 // klugy!
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
25 if ( suggs.length > 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
26 return true;
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
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
28 return false;
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 },
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
30
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
31 suggest: function( fragment ) {
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
32 // returns (ordered) array of suggestions
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
33 var suggestions = [];
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
34 for ( var x in this._expectedWords ) {
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
35 word = this._expectedWords[x];
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
36 if ( word.indexOf( fragment ) > -1 ) {
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
37 suggestions.push( word );
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
38 // TODO sort these in order of goodness
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
39 // todo if fragment is multiple words, search for each of them
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
40 // separately within the expected word.
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
41 }
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
42 }
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
43 return suggestions;
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
44 }
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
45 };
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
46
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
47 // for example....
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
48 var city = new NounType( "city", [ "new york", "los angeles", "mexico city", "sao paulo", "rio de janeiro", "buenos aires", "london", "paris", "moscow", "cairo", "lagos", "tehran", "karachi", "mumbai", "delhi", "kolkata", "jakarta", "manila", "bejing", "singapore", "shanghai", "hong kong", "seoul", "tokyo", "osaka" ] );
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
49
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
50 var language = new NounType( "language", [ "english", "chinese", "hindi", "japanese", "klingon", "esperanto", "sanskrit", "pig latin", "tagalog", "portugese" ] );
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
51
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
52 var tab = new NounType( "tab", [ "gmail", "mozilla developer connection", "xulplanet", "evilbrainjono.net", "google calendar", "humanized enso forum" ] );
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
53
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
54 var person = new NounType( "person", ["atul@mozilla.com", "aza@mozilla.com", "thunder@mozilla.com", "chris@mozilla.com", "myk@mozilla.com" ] );
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
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
56 var anyWord = {
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
57 // a singleton object which can be used in place of a NounType.
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 _name: "text",
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
59 match: function( fragment ) {
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
60 return true;
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
61 },
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
62 suggest: function( fragment ) {
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
63 return [ fragment ];
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 };
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
66
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
67 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
68 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
69 }
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 ParsedSentence.prototype = {
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
71 _init: function( 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
72 /* 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
73 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
74 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
75 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
76 },
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
77
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
78 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
79 // 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
80 // 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
81 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
82 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
83 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
84 }
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
85 for ( var x in this._modifiers ) {
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
86 sentence = sentence + " " + x + " " + this._modifiers[x];
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
87 }
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
88 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
89 },
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
90
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
91 getDisplayText: function() {
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
92 // 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
93 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
94 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
95 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
96 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
97 } 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
98 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
99 }
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
100 }
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
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
102 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
103 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
104 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
105 } 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
106 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
107 }
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
108 }
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
109 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
110 },
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
111
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
112 getDescription: function() {
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
113 // 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
114 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
115 }
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
116
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
117 };
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
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
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 function Verb( name, DOLabel, DOType, modifiers ) {
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 this._init( name, DOLabel, DOType, modifiers );
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 Verb.prototype = {
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
124 _init: function( name, DOLabel, DOType, modifiers ) {
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._name = name;
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 this._DOLabel = DOLabel;
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._DOType = DOType; // must be a NounType.
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 this._modifiers = modifiers;
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 // modifiers should be a dictionary
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
130 // keys are prepositions
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
131 // values are NounTypes.
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 // example: { "from" : City, "to" : City, "on" : Day }
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 },
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
134
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
135 getDescription: function() {
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
136 // returns a string describing what the sentence will do if executed
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
137 return this._verb.getDescription( this._DO, this._modifiers );
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
138 }
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
139
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
140 recursiveParse: function( unusedWords, filledMods, unfilledMods ) {
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
141 var x;
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
142 var suggestions = [];
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
143 var completions = [];
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
144 var directObject = "";
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
145 if ( dictKeys( unfilledMods ).length == 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
146 // Done with modifiers, try to parse direct object.
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
147 if ( unusedWords.length == 0 ) {
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
148 // No words left, no direct object. Try parsing sentence
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
149 // without them.
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
150 return [ new ParsedSentence( this, "", filledMods ) ];
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
151 }
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
152
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
153 if ( this._DOType == null ) {
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
154 // intransitive verb; no direct object, only 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
155 // We can't use the extra words, so fail.
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
156 return [];
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
157 } 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
158 // Transitive verb, can have direct object. Try to use the
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
159 // remaining words in that slot.
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
160 directObject = unusedWords.join( " " );
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
161 if ( this._DOType.match( directObject ) ) {
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
162 // it's a valid direct object. Make a sentence for each
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
163 // possible noun completion based on it; return them all.
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
164 suggestions = this._DOType.suggest( unusedWords[0] );
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
165 for ( var x in suggestions ) {
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
166 completions.push( new ParsedSentence( this, suggestions[x],
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
167 filledMods ) );
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
168 }
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
169 return completions;
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
170 } 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
171 // word is invalid direct object. Fail!
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
172 return [];
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
173 }
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
174 }
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
175 } else {
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
176 // "pop" a preposition off of the properties of unfilledMods
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
177 var preposition = dictKeys( unfilledMods )[0];
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
178 // newUnfilledMods is the same as unfilledMods without preposition
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
179 var newUnfilledMods = dictDeepCopy( unfilledMods );
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
180 delete newUnfilledMods[preposition];
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
181
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
182 // Look for a match for this preposition
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
183 var nounType = unfilledMods[ preposition ];
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
184 var matchIndices = [];
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
185 for ( var x = 0; x < unusedWords.length - 1; x++ ) {
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
186 if ( preposition.indexOf( unusedWords[x] ) == 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
187 if ( nounType.match( unusedWords[ x + 1 ] ) ) {
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
188 // Match for the preposition at index x followed by
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
189 // an appropriate noun at index x+1
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
190 matchIndices.push( x );
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
191 }
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
192 }
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
193 }
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
194 if ( matchIndices.length == 0 ) {
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
195 // no match for this preposition.
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
196 // Leave it blank and try to parse the rest:
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
197 filledMods[preposition] = "";
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
198 var directObject = unusedWords.join( " " );
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
199 return [ new ParsedSentence( this, directObject, filledMods ) ];
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
200 //return this.recursiveParse( unusedWords, filledMods, newUnfilledMods );
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
201 } 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
202 // this is placeholder, destroy it.
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
203 for ( x in matchIndices ) {
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
204 var noun = unusedWords[ matchIndices[x]+1 ];
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
205 var newUnusedWords = unusedWords.slice();
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
206 newUnusedWords.splice( matchIndices[x], 2 );
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
207 var directObject = newUnusedWords.join( " " );
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
208
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
209 suggestions = nounType.suggest( 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
210 for ( var y in suggestions ) {
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
211 var newFilledMods = dictDeepCopy( filledMods );
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
212 newFilledMods[ preposition ] = suggestions[y];
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
213 var newCompletions = this.recursiveParse( newUnusedWords,
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
214 newFilledMods,
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
215 newUnfilledMods );
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
216 completions = completions.concat( newCompletions );
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
217 }
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
218 }
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
219 return completions;
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
220 }
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
221 }
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
222 },
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
223
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
224 getCompletions: function( words ) {
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
225 /* returns 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
226 /* words is an array of words that were space-separated.
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
227 The first word, which matched this verb, has already been removed.
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
228 Everything after that is either:
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
229 1. my direct object
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
230 2. a preposition
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
231 3. a noun following a preposition.
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
232 */
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
233 return this.recursiveParse( words, {}, this._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
234 },
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
235
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
236 match: function( sentence ) {
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
237 // returns a float from 0 to 1 telling how good of a match the input
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
238 // is to this verb.
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
239 if ( this._name.indexOf( sentence ) == 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
240 // verb starts with the sentence, i.e. you may be typing this
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
241 // verb but haven't typed the full thing yet.
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
242 return sentence.length / this._name.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
243 } 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
244 return 0.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
245 }
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
246 }
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
247 };
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
248
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
249 var fly = new Verb( "fly", null, null, { "from": city, "to": city } );
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
250 var define = new Verb( "define", "word", anyWord, {} );
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
251 var google = new Verb( "google", "word", anyWord, {} );
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
252 var go = new Verb( "go", "tab", tab, {} );
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
253 var close = new Verb( "close", null, 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
254 var translate = new Verb( "translate", "text", anyWord, { "from": language, "to": language } );
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
255 var nuke = new Verb( "nuke", "city", city, {} );
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
256 var open = new Verb( "open", "url", anyWord, {} );
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
257 var email = new Verb( "email", "text", anyWord, { "to": person, "subject": anyWord } );
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
258 var encrypt = new Verb( "encrypt", "text", anyWord, { "for": person } );
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
259 var wiki = new Verb( "wikipedia", "word", anyWord, { "language": language } );
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
260
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
261 var verbs = [ fly, define, google, go, close, open, translate, email, nuke, encrypt, wiki ];
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
262
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
263 /* Initial state: no verb determined.
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
264 After each keypress, update verb suggestion list.
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
265 After first spacebar: lock in top verb from suggestion list. Create
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
266 parsedSentence object based on verb. change state to sentence completion.
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
267 Non-keystroke spaces after that:
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
268 spacebar sends the lock-in-last-word message to lockedInSentence.
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
269
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
270 todo: add responder for arrow keys to hilight suggestions
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
271 and escape to clear text.
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
272 */
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
273
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
274
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
275 function QuerySource() {
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
276 this._init( );
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
277 }
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
278 QuerySource.prototype = {
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
279 _init: function( ) {
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
280 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
281 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
282 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
283 },
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
284
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
285 updateSuggestionList: function( query ) {
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
286 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
287 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
288 var words = query.split( " " );
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
289 for ( var x in verbs ) {
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
290 var verb = verbs[x];
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
291 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
292 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
293 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
294 }
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
295 }
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
296 // TODO sort in order of match quality
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
297 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
298 },
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
299
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
300 getSuggestionsAsHtml : function() {
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
301 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
302 },
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
303
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
304 indicationDown: function( ) {
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
305 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
306 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
307 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
308 }
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
309 },
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
310
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
311 indicationUp: function() {
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
312 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
313 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
314 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
315 }
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
316 },
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
317
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
318 getHilitedSuggestion: function() {
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
319 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
320 // 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
321 },
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
322
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
323 autocomplete: function( query ) {
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
324 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
325 if ( hilited > -1 ) {
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
326 var 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
327 } 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
328 newText = query;
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
329 }
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
330 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
331 },
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
332
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
333 clear: function() {
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
334 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
335 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
336 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
337 }
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
338 };
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
339
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
340 var gQs = new QuerySource();
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
341
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
342 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
343 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
344 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
345 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
346
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
347 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
348 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
349 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
350 } 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
351 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
352 }
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
353 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
354 }
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
355 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
356 }
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
357
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
358 function updateDisplay( ) {
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
359 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
360 var hilitedSuggestion = gQs.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
361 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
362 ac.html( makeSuggestionHtml( "div", suggestions, 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
363 ac.show();
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
364 }
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
365
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
366 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
367 // 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
368 // 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
369 // indication.
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
370
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
371 // 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
372 // 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
373 // 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
374 // 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
375 // 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
376 // space is 32
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
377 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
378 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
379 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
380 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
381 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
382 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
383 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
384 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
385 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
386 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
387 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
388 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
389 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
390 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
391 case 32: // spacebar
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
392 event.target.value = gQs.autocomplete( event.target.value );
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
393 gQs.updateSuggestionList( 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
394 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
395 default:
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
396 gQs.updateSuggestionList( 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
397 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
398 // todo: delete key "unlocks" if you delete past a space?
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
399 }
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
400
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
401 updateDisplay();
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
402
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
403 }
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
404
0
9e6054e41bdc Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
405 $(document).ready( 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
406 $("#status-line").html( "Welcome to Ubiquity." );
0
9e6054e41bdc Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
407 $("#search-box").focus();
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
408 $("#search-box").keyup( searchBoxQuery );
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
409 $("#autocomplete-popup").css(
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
410 "width",
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
411 $("#search-box").css("width")
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
412 );
0
9e6054e41bdc Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
413 });
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
414
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
415 /* Minor problems:
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
416 2. multiple word direct objects are truncated to single word
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
417 3. prepositional phrases past the first don't get matched?
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
418 4. sentences need to have descriptions
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
419 */