Mercurial > hip
annotate verbClasses.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 | a26372118854 |
children |
rev | line source |
---|---|
13
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
1 function Verb( name, DOLabel, DOType, modifiers ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
2 this._init( name, DOLabel, DOType, modifiers ); |
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 Verb.prototype = { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
5 _init: function( name, DOLabel, DOType, modifiers ) { |
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._DOLabel = DOLabel; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
8 this._DOType = DOType; // must be a NounType. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
9 this._modifiers = modifiers; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
10 // modifiers should be a dictionary |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
11 // keys are prepositions |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
12 // values are NounTypes. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
13 // example: { "from" : City, "to" : City, "on" : Day } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
14 }, |
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 getDescription: function( directObject, prepositionPhrases ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
17 // returns a string describing what the sentence will do if executed |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
18 var desc = "Hit enter to do " + this._name + " with direct object " + directObject; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
19 for ( var x in prepositionPhrases ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
20 desc = desc + ", " + x + " " + prepositionPhrases[x]; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
21 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
22 return desc; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
23 }, |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
24 |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
25 recursiveParse: function( unusedWords, filledMods, unfilledMods ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
26 var x; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
27 var suggestions = []; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
28 var completions = []; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
29 var newFilledMods = {}; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
30 var directObject = ""; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
31 var newCompletions = []; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
32 if ( dictKeys( unfilledMods ).length == 0 ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
33 // Done with modifiers, try to parse direct object. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
34 if ( unusedWords.length == 0 || this._DOType == null ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
35 // No direct object, either because there are no words left, |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
36 // to use, or because the verb can't take a direct object. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
37 // Try parsing sentence without them. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
38 return [ new ParsedSentence( this, "", filledMods ) ]; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
39 } else { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
40 // Transitive verb, can have direct object. Try to use the |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
41 // remaining words in that slot. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
42 directObject = unusedWords.join( " " ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
43 if ( this._DOType.match( directObject ) ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
44 // it's a valid direct object. Make a sentence for each |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
45 // possible noun completion based on it; return them all. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
46 suggestions = this._DOType.suggest( directObject ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
47 for ( var x in suggestions ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
48 completions.push( new ParsedSentence( this, suggestions[x], |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
49 filledMods ) ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
50 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
51 return completions; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
52 } else { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
53 // word is invalid direct object. Fail! |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
54 return []; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
55 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
56 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
57 } else { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
58 // "pop" a preposition off of the properties of unfilledMods |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
59 var preposition = dictKeys( unfilledMods )[0]; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
60 // newUnfilledMods is the same as unfilledMods without preposition |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
61 var newUnfilledMods = dictDeepCopy( unfilledMods ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
62 delete newUnfilledMods[preposition]; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
63 |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
64 // Look for a match for this preposition |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
65 var nounType = unfilledMods[ preposition ]; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
66 var matchIndices = []; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
67 for ( var x = 0; x < unusedWords.length - 1; x++ ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
68 if ( preposition.indexOf( unusedWords[x] ) == 0 ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
69 if ( nounType.match( unusedWords[ x + 1 ] ) ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
70 // Match for the preposition at index x followed by |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
71 // an appropriate noun at index x+1 |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
72 matchIndices.push( x ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
73 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
74 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
75 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
76 if ( matchIndices.length > 0 ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
77 // Matches found for this preposition! Add to the completions list |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
78 // all sentences that can be formed using these matches for this |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
79 // preposition. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
80 for ( x in matchIndices ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
81 var noun = unusedWords[ matchIndices[x]+1 ]; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
82 var newUnusedWords = unusedWords.slice(); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
83 newUnusedWords.splice( matchIndices[x], 2 ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
84 directObject = newUnusedWords.join( " " ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
85 |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
86 suggestions = nounType.suggest( noun ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
87 for ( var y in suggestions ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
88 newFilledMods = dictDeepCopy( filledMods ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
89 newFilledMods[ preposition ] = suggestions[y]; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
90 newCompletions = this.recursiveParse( newUnusedWords, |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
91 newFilledMods, |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
92 newUnfilledMods ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
93 completions = completions.concat( newCompletions ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
94 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
95 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
96 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
97 // If no match was found, all we'll return is one sentence formed by |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
98 // leaving that preposition blank. But even if a match was found, we |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
99 // still want to include this sentence as an additional possibility. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
100 newFilledMods = dictDeepCopy( filledMods ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
101 newFilledMods[preposition] = ""; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
102 directObject = unusedWords.join( " " ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
103 newCompletions = this.recursiveParse( unusedWords, |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
104 newFilledMods, |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
105 newUnfilledMods ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
106 completions = completions.concat( newCompletions ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
107 |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
108 return completions; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
109 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
110 }, |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
111 |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
112 getCompletions: function( words ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
113 /* returns a list of ParsedSentences. */ |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
114 /* words is an array of words that were space-separated. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
115 The first word, which matched this verb, has already been removed. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
116 Everything after that is either: |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
117 1. my direct object |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
118 2. a preposition |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
119 3. a noun following a preposition. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
120 */ |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
121 |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
122 /* Look for words that refer to selection: */ |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
123 var completions = []; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
124 var subbedWords = words.slice(); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
125 var selectionUsed = false; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
126 var selection = getSelection(); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
127 if ( selection ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
128 for ( var x in wordsThatReferToSelection ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
129 var index = subbedWords.indexOf( wordsThatReferToSelection[x] ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
130 if ( index > -1 ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
131 subbedWords.splice( index, 1, selection ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
132 // Notice the above line doesn't do what I want if selection |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
133 // is more than one word. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
134 selectionUsed = true; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
135 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
136 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
137 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
138 if ( selectionUsed ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
139 completions = this.recursiveParse( subbedWords, {}, this._modifiers ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
140 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
141 |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
142 /* Also parse without that substitution, return both ways: */ |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
143 var completionsNoSub = this.recursiveParse( words, {}, this._modifiers ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
144 completions = completions.concat( completionsNoSub ); |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
145 return completions; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
146 }, |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
147 |
14
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
148 canPossiblyUseNounType: function(nounType){ |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
149 //returns the words that would be implied before the noun could makes sense, |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
150 //i.e. put these words before the noun and try again. |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
151 if (this._DOType == nounType ) { |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
152 return this._name; |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
153 } |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
154 for( var prep in this._modifiers ) { |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
155 if (this._modifiers[prep] == nounType) { |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
156 return this._name + " " + prep; |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
157 // TODO returning multiple preps when more than one could use the |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
158 // nountype |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
159 } |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
160 } |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
161 return false; |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
162 }, |
a26372118854
Created a primitive form of noun-first suggestion.
jonathandicarlo@localhost
parents:
13
diff
changeset
|
163 |
13
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
164 match: function( sentence ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
165 // returns a float from 0 to 1 telling how good of a match the input |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
166 // is to this verb. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
167 if ( this._name.indexOf( sentence ) == 0 ) { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
168 // verb starts with the sentence, i.e. you may be typing this |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
169 // verb but haven't typed the full thing yet. |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
170 return sentence.length / this._name.length; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
171 } else { |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
172 return 0.0; |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
173 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
174 } |
8dcc88f93829
Broke up hip.js into some smaller js files
jonathandicarlo@localhost
parents:
diff
changeset
|
175 }; |