diff 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 diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nounClasses.js	Wed Jul 02 12:04:46 2008 -0700
@@ -0,0 +1,44 @@
+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 ];
+  }
+};