Mercurial > hip
view nounClasses.js @ 13:8dcc88f93829
Broke up hip.js into some smaller js files
author | jonathandicarlo@localhost |
---|---|
date | Wed, 02 Jul 2008 12:04:46 -0700 |
parents | |
children | 21bb73c5d9e1 |
line wrap: on
line source
function NounType( name, expectedWords ) { this._init( name, expectedWords ); } NounType.prototype = { _init: function( name, expectedWords ) { this._name = name; this._expectedWords = expectedWords; // an array }, match: function( fragment ) { var suggs = this.suggest( fragment ); // klugy! if ( suggs.length > 0 ) { return true; } return false; }, suggest: function( fragment ) { // returns (ordered) array of suggestions var suggestions = []; for ( var x in this._expectedWords ) { word = this._expectedWords[x]; if ( word.indexOf( fragment ) > -1 ) { suggestions.push( word ); // TODO sort these in order of goodness // todo if fragment is multiple words, search for each of them // separately within the expected word. } } return suggestions; } }; var anyWord = { // a singleton object which can be used in place of a NounType. _name: "text", match: function( fragment ) { return true; }, suggest: function( fragment ) { return [ fragment ]; } };