annotate nounClasses.js @ 18:5fce4c8f3ebd

Preliminary version of date stuff added
author jonathandicarlo@jonathan-dicarlos-macbook-pro.local
date Tue, 15 Jul 2008 14:10:17 -0700
parents 21bb73c5d9e1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
1 function NounType( name, expectedWords ) {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
2 this._init( name, expectedWords );
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
3 }
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
4 NounType.prototype = {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
5 _init: function( name, expectedWords ) {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
6 this._name = name;
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
7 this._expectedWords = expectedWords; // an array
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
8 },
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
9
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
10 match: function( fragment ) {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
11 var suggs = this.suggest( fragment );
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
12 // klugy!
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
13 if ( suggs.length > 0 ) {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
14 return true;
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
15 }
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
16 return false;
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
17 },
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
18
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
19 suggest: function( fragment ) {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
20 // returns (ordered) array of suggestions
15
21bb73c5d9e1 Tiny fix to make nouns never match the empty string, so you don't get that weird thing where your input is empty and it's suggesting a list of cities.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 13
diff changeset
21 if (!fragment) {
21bb73c5d9e1 Tiny fix to make nouns never match the empty string, so you don't get that weird thing where your input is empty and it's suggesting a list of cities.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 13
diff changeset
22 return [];
21bb73c5d9e1 Tiny fix to make nouns never match the empty string, so you don't get that weird thing where your input is empty and it's suggesting a list of cities.
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 13
diff changeset
23 }
13
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
24 var suggestions = [];
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
25 for ( var x in this._expectedWords ) {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
26 word = this._expectedWords[x];
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
27 if ( word.indexOf( fragment ) > -1 ) {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
28 suggestions.push( word );
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
29 // TODO sort these in order of goodness
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
30 // todo if fragment is multiple words, search for each of them
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
31 // separately within the expected word.
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
32 }
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
33 }
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
34 return suggestions;
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
35 }
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
36 };
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
37
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
38 var anyWord = {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
39 // a singleton object which can be used in place of a NounType.
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
40 _name: "text",
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
41 match: function( fragment ) {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
42 return true;
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
43 },
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
44 suggest: function( fragment ) {
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
45 return [ fragment ];
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
46 }
8dcc88f93829 Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff changeset
47 };
18
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
48
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
49 var DateNounType = {
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
50 match: function( fragment ) {
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
51 return (this.suggest(fragment).length > 0 );
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
52 },
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
53 suggest: function( fragment ) {
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
54 if (!fragment) {
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
55 return [];
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
56 }
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
57 var date = Date.parse( fragment );
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
58 if (!date) {
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
59 return [];
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
60 }
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
61 return [ "parsed date: " + date.toString() ];
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
62 }
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
63 };
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
64
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
65 var AddressNounType = {
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
66 match: function( fragment ) {
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
67
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
68 },
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
69 suggest: function( fragment ) {
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
70
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
71 }
5fce4c8f3ebd Preliminary version of date stuff added
jonathandicarlo@jonathan-dicarlos-macbook-pro.local
parents: 15
diff changeset
72 };