annotate hip.js @ 5:a049cb93db46

Now doing a much smarter parsing of the rest of the sentence after the verb, and describing expected arguments in (italics).
author jonathandicarlo@jonathan-dicarlos-macbook-pro.local
date Tue, 13 May 2008 18:57:55 -0700
parents 4ea09b7ce820
children 98935af12b04
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
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
2 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
3 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
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
5 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
6 _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
7 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
8 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
9 },
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
10
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
11 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
12 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
13 // 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
14 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
15 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
16 }
4ea09b7ce820 Added verbs and nouns and 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 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
18 },
4ea09b7ce820 Added verbs and nouns and 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
4ea09b7ce820 Added verbs and nouns and 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 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
21 // 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
22 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
23 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
24 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
25 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
26 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
27 // 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
28 // 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
29 // 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
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 }
4ea09b7ce820 Added verbs and nouns and 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 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
33 }
4ea09b7ce820 Added verbs and nouns and 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 };
4ea09b7ce820 Added verbs and nouns and 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
4ea09b7ce820 Added verbs and nouns and 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 // 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
37 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
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
39 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
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
41 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
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 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
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 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
46 // a singleton object which can be used in place of 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
47 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
48 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
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 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
51 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
52 }
4ea09b7ce820 Added verbs and nouns and 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
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
55 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
56 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
57 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
58 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
59 _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
60 /* 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
61 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
62 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
63 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
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
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
66 getCompletionText: function() {
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 // returns completed and canonicalized 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
68 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
69 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
70 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
71 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
72 } 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
73 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
74 }
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 }
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
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
77 for ( var x in this._verb._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
78 if ( this._modifiers[ 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
79 sentence = sentence + " " + x + " " + this._modifiers[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
80 } 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
81 sentence = sentence + " <span class=\"needarg\">(" + this._verb._modifiers[x]._name + ")</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
82 }
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
83 }
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
84 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
85 },
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
86
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
87 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
88 // returns a string describing what the sentence will do if executed
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
89 }
4
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
90
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
91 };
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
92
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
93
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
94 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
95 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
96 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
97 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
98 _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
99 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
100 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
101 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
102 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
103 // 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
104 // 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
105 // 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
106 // 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
107 },
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
108
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
109 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
110 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
111 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
112 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
113 var 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
114 if ( [key for (key in unfilledMods)].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
115 // 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
116 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
117 // 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
118 // 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
119 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
120 }
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
121
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
122 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
123 // 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
124 // 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
125 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
126 } 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
127 // 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
128 // 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
129 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
130 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
131 // 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
132 // 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
133 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
134 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
135 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
136 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
137 }
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
138 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
139 } 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
140 // 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
141 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
142 }
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 }
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 }
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
145 },
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
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 /*
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 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
149 // "pop" a preposition off of the properties of 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
150 var preposition = [key for (key in unfilledMods)][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
151 var newUnfilledMods = unfilledMods.splice();
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 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
153
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 // 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
155 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
156 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
157 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
158 if ( preposition.indexOf( unusedWords[x] ) == 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
159 if ( nounType.match( unusedWords[ x + 1 ] ) == 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
160 // 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
161 // 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
162 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
163 }
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 }
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 }
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 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
167 // 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
168 // 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
169 filledMods[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
170 return recursiveParse( unusedWords, filledMods, newUnfilledMods );
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 } 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
172 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
173 // remove the words that matched the preposition and following
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 // 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
175 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
176 var newUnusedWords = unusedWords.slice();
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
177 newUnusedWords.splice( possibilities[x], 2 );
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
178 // add every noun completion from every possibility...
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
179 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
180 for ( var y 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
181 var newFilledMods = filledMods.slice();
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 newFilledMods[ preposition ] = suggestions[y];
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 newCompletions = recursiveParse( newUnusedWords,
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 newFilledMods,
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 newUnfilledMods );
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 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
187 }
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 }
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 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
190 }
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 parse: function( words ) {
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 /* 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
196 /* 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
197 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
198 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
199 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
200 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
201 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
202 */
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 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
204 },
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
205
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
206 getCompletions: function( words ) {
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
207 var sentences = this.parse( words );
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
208 return [ sentences[x].getCompletionText() for ( x in sentences ) ];
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
209 },
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
210
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
211 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
212 // 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
213 // 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
214 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
215 // 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
216 // 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
217 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
218 } 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
219 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
220 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
221 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
222 };
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
223
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
224 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
225 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
226 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
227 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
228 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
229 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
230 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
231 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
232 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
233 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
234 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
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 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
237
4ea09b7ce820 Added verbs and nouns and 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 /* 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
239 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
240 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
241 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
242 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
243 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
244
4ea09b7ce820 Added verbs and nouns and 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 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
246 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
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
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
249
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
250 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
251 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
252 }
4ea09b7ce820 Added verbs and nouns and 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 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
254 _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
255 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
256 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
257 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
258 },
4ea09b7ce820 Added verbs and nouns and 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
4ea09b7ce820 Added verbs and nouns and 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 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
261 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
262 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
263 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
264 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
265 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
266 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
267 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
268 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
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 sort in order of match quality
4ea09b7ce820 Added verbs and nouns and 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 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
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
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
274 getSuggestions : 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
275 return 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
276 },
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
277
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
278 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
279 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
280 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
281 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
282 }
4ea09b7ce820 Added verbs and nouns and 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 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
286 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
287 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
288 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
289 }
4ea09b7ce820 Added verbs and nouns and 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 },
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
291
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
292 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
293 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
294 // 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
295 },
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
296
4ea09b7ce820 Added verbs and nouns and 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 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
298 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
299 if ( hilited > -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
300 var newText = this._suggestionList[ 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
301 } 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
302 newText = query;
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 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
305 },
4ea09b7ce820 Added verbs and nouns and 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
4ea09b7ce820 Added verbs and nouns and 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 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
308 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
309 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
310 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
311 }
4ea09b7ce820 Added verbs and nouns and 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 };
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
313
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
314 var gQs = new QuerySource();
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
315
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
316 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
317 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
318 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
319 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
320
4ea09b7ce820 Added verbs and nouns and 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 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
322 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
323 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
324 } 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
325 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
326 }
4ea09b7ce820 Added verbs and nouns and 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 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
328 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
329 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
330 }
4ea09b7ce820 Added verbs and nouns and 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 function 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
333 var suggestions = gQs.getSuggestions();
4ea09b7ce820 Added verbs and nouns and 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 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
335 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
336 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
337 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
338 }
4ea09b7ce820 Added verbs and nouns and up/down arrows and space-to-autocomplete and suggestion list and escape-to-clear.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 1
diff changeset
339
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
340 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
341 // 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
342 // 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
343 // 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
344
4ea09b7ce820 Added verbs and nouns and 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 // 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
346 // 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
347 // 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
348 // 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
349 // 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
350 // 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
351 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
352 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
353 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
354 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
355 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
356 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
357 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
358 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
359 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
360 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
361 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
362 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
363 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
364 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
365 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
366 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
367 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
368 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
369 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
370 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
371 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
372 // 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
373 }
4ea09b7ce820 Added verbs and nouns and 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
4ea09b7ce820 Added verbs and nouns and 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 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
376
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
377 }
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
378
0
9e6054e41bdc Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
379 $(document).ready( function() {
9e6054e41bdc Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
380 $("#search-box").focus();
1
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
381 $("#search-box").keyup( searchBoxQuery );
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
382 $("#autocomplete-popup").css(
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
383 "width",
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
384 $("#search-box").css("width")
a31bdc4de955 Added autocomplete popup and querysource class
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
385 );
0
9e6054e41bdc Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
386 });
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
387
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
388 /* 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
389 1. verbs with indirect objects are returning empty completion lists
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
390 2. multiple word direct objects are truncated to single word
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
391 */