changeset 12:aa56c4aa5b11

You can use pronouns to refer to your selection, which is pulled from a 'pretend this is your selection' input box.
author jonathandicarlo@jonathan-dicarlos-macbook-pro.local
date Thu, 29 May 2008 14:28:50 -0700
parents 9e18b8d8c936
children 8dcc88f93829
files hip.js
diffstat 1 files changed, 40 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/hip.js	Fri May 16 19:43:45 2008 -0700
+++ b/hip.js	Thu May 29 14:28:50 2008 -0700
@@ -14,7 +14,7 @@
   return $("#selection").attr( "value" );
 }
 
-var wordsThatReferToSelection = [ "this", "that", "it", "selection", "him", "her", "them"]; // not currently used (there's a hard-coded "this") but it easily could be
+var wordsThatReferToSelection = [ "this", "that", "it", "selection", "him", "her", "them"];
 
 function NounType( name, expectedWords ) {
     this._init( name, expectedWords );
@@ -51,7 +51,7 @@
 };
 
 // for example....
-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" ] );
+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", "beijing", "singapore", "shanghai", "hong kong", "seoul", "tokyo", "osaka" ] );
 
 var language = new NounType( "language", [ "english", "chinese", "hindi", "japanese", "klingon", "esperanto", "sanskrit", "pig latin", "tagalog", "portugese" ] );
 
@@ -91,7 +91,9 @@
       sentence = sentence + " " + this._DO;
     }
     for ( var x in this._modifiers ) {
-      sentence = sentence + " " + x + " " + this._modifiers[x];
+      if ( this._modifiers[x] ) {
+	sentence = sentence + " " + x + " " + this._modifiers[x];
+      }
     }
     return sentence;
   },
@@ -158,16 +160,11 @@
     var newCompletions = [];
     if ( dictKeys( unfilledMods ).length == 0 ) {
       // Done with modifiers, try to parse direct object.
-      if ( unusedWords.length == 0 ) {
-	// No words left, no direct object.  Try parsing sentence
-	// without them.
+      if ( unusedWords.length == 0 || this._DOType == null ) {
+	// No direct object, either because there are no words left,
+	// to use, or because the verb can't take a direct object.
+	// Try parsing sentence without them.
 	return [ new ParsedSentence( this, "", filledMods ) ];
-      }
-
-      if ( this._DOType == null ) {
-	// intransitive verb; no direct object, only modifiers.
-	// We can't use the extra words, so fail.
-	  return [];
       } else {
 	// Transitive verb, can have direct object.  Try to use the
 	// remaining words in that slot.
@@ -433,7 +430,7 @@
       }
     }
     // TODO sort in order of match quality
-    this._hilitedSuggestion = 0;
+    this._hilitedSuggestion = 1; // hilight the first suggestion by default
   },
 
  getSuggestionsAsHtml : function() {
@@ -442,11 +439,11 @@
 
  getDescriptionText: function() {
     if ( this._suggestionList.length == 0 ) {
-      return "Type some commands!";
+      return "Welcome to Ubiquity. Type some commands!";
     }
     var h = this._hilitedSuggestion;
     if ( h == 0 ) {
-      h = 0;
+      return "Executes your input literally, with no autocompletion.";
     } else {
       h = h - 1;
     }
@@ -508,11 +505,16 @@
   return result;
 }
 
-function updateDisplay( ) {
+function updateDisplay( number ) {
    var suggestions = gQs.getSuggestionsAsHtml();
    var hilitedSuggestion = gQs.getHilitedSuggestion();
    var description = gQs.getDescriptionText();
    $("#status-line").html( description );
+   if ( hilitedSuggestion == -1 ) {
+     // TODO set #search-box background to green, not sure how
+   } else {
+     // TODO set #search-box background to white, not sure how
+   }
    var ac = $("#autocomplete-popup");
    ac.html( makeSuggestionHtml( "div", suggestions, hilitedSuggestion ) );
    ac.show();
@@ -545,7 +547,7 @@
     gQs.execute();
     break;
   case 32: // spacebar
-    input = gQs.autocomplete( input );
+    //input = gQs.autocomplete( input );
     gQs.updateSuggestionList( input );
     break;
   default:
@@ -553,7 +555,7 @@
     break;
   }
 
-  updateDisplay();
+  updateDisplay( event.which );
 
 }
 
@@ -576,8 +578,10 @@
 fly from london
 nuke london
 
-
-3. Allow the possibility of a multiple-word indirect-object
+3. Allow the possibility of a multiple-word indirect-object.
+(Maybe pass the whole rest of the sentence past the preposition as an argument
+to the noun class, and as the noun class returns the list of suggestions,
+it also returns a count of how many words it has used.)
 
 4. Preview output of topmost or hilited command, as you type.
 
@@ -599,4 +603,20 @@
 and hit space.  Right now it's putting in prepositions that you haven't
 actually typed.
 
+9. Learn how frequently you use different completions (use the algorithm
+   we've already developed) and rank accordingly.
+
+10. Start sorting matches by goodness.
+
+11. Have nounTypes that can learn new entries!!!
+
+12. Make it so when hilite is 0, the literal input is hilited green
+    and an appropriate suggestion is displayed!
+
+13. Break this file into multiple files, it's getting really big.
+
+14. Use Tab to mean "copy hilited suggestion to input box"
+    (No, we can't do that!  Because tab changes focus away from the input
+    box.)
+
 */