aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2009-07-28 16:33:36 -0700
committerJean-Baptiste Queru <jbq@google.com>2009-08-13 17:27:12 -0700
commitd67fe0e7583f1be18b35b33b7658e4427f1e3ded (patch)
treeb09382427b141d86b17d722dddac31dc221fa68e
parent4a7ff90d513f8b6cbf39688c08be0828a57e311b (diff)
downloadlatinime-d67fe0e7583f1be18b35b33b7658e4427f1e3ded.tar.gz
latinime-d67fe0e7583f1be18b35b33b7658e4427f1e3ded.tar.xz
latinime-d67fe0e7583f1be18b35b33b7658e4427f1e3ded.zip
Improve auto-add heuristics.
Also add auto-switch back to alphabet mode on pressing enter key.
-rw-r--r--src/com/android/inputmethod/latin/KeyboardSwitcher.java10
-rw-r--r--src/com/android/inputmethod/latin/LatinIME.java32
2 files changed, 27 insertions, 15 deletions
diff --git a/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/src/com/android/inputmethod/latin/KeyboardSwitcher.java
index a5aebfbfe..16dd7b9a7 100644
--- a/src/com/android/inputmethod/latin/KeyboardSwitcher.java
+++ b/src/com/android/inputmethod/latin/KeyboardSwitcher.java
@@ -245,14 +245,16 @@ public class KeyboardSwitcher {
* Returns true if the keyboard needs to switch back
*/
boolean onKey(int key) {
- // Switch back to alpha mode if user types one or more non-space characters followed by
- // a space.
+ // Switch back to alpha mode if user types one or more non-space/enter characters
+ // followed by a space/enter
switch (mSymbolsModeState) {
case SYMBOLS_MODE_STATE_BEGIN:
- if (key != ' ' && key > 0) mSymbolsModeState = SYMBOLS_MODE_STATE_SYMBOL;
+ if (key != LatinIME.KEYCODE_SPACE && key != LatinIME.KEYCODE_ENTER && key > 0) {
+ mSymbolsModeState = SYMBOLS_MODE_STATE_SYMBOL;
+ }
break;
case SYMBOLS_MODE_STATE_SYMBOL:
- if (key == ' ') return true;
+ if (key == LatinIME.KEYCODE_ENTER || key == LatinIME.KEYCODE_SPACE) return true;
break;
}
return false;
diff --git a/src/com/android/inputmethod/latin/LatinIME.java b/src/com/android/inputmethod/latin/LatinIME.java
index 3dfdc5f1f..5480c6780 100644
--- a/src/com/android/inputmethod/latin/LatinIME.java
+++ b/src/com/android/inputmethod/latin/LatinIME.java
@@ -76,10 +76,17 @@ public class LatinIME extends InputMethodService
// How many continuous deletes at which to start deleting at a higher speed.
private static final int DELETE_ACCELERATE_AT = 20;
// Key events coming any faster than this are long-presses.
- private static final int QUICK_PRESS = 200;
+ private static final int QUICK_PRESS = 200;
+ // Weight added to a user picking a new word from the suggestion strip
+ static final int FREQUENCY_FOR_PICKED = 3;
+ // Weight added to a user typing a new word that doesn't get corrected (or is reverted)
+ static final int FREQUENCY_FOR_TYPED = 1;
+ // A word that is frequently typed and get's promoted to the user dictionary, uses this
+ // frequency.
+ static final int FREQUENCY_FOR_AUTO_ADD = 250;
- private static final int KEYCODE_ENTER = 10;
- private static final int KEYCODE_SPACE = ' ';
+ static final int KEYCODE_ENTER = '\n';
+ static final int KEYCODE_SPACE = ' ';
// Contextual menu positions
private static final int POS_SETTINGS = 0;
@@ -481,7 +488,7 @@ public class LatinIME extends InputMethodService
}
mCommittedLength = mComposing.length();
TextEntryState.acceptedTyped(mComposing);
- mAutoDictionary.addWord(mComposing.toString(), 1);
+ mAutoDictionary.addWord(mComposing.toString(), FREQUENCY_FOR_TYPED);
}
updateSuggestions();
}
@@ -845,7 +852,7 @@ public class LatinIME extends InputMethodService
}
// Add the word to the auto dictionary if it's not a known word
if (mAutoDictionary.isValidWord(suggestion) || !mSuggest.isValidWord(suggestion)) {
- mAutoDictionary.addWord(suggestion.toString(), 1);
+ mAutoDictionary.addWord(suggestion.toString(), FREQUENCY_FOR_PICKED);
}
mPredicting = false;
mCommittedLength = suggestion.length();
@@ -1141,8 +1148,10 @@ public class LatinIME extends InputMethodService
}
class AutoDictionary extends ExpandableDictionary {
- private static final int VALIDITY_THRESHOLD = 3;
- private static final int PROMOTION_THRESHOLD = 6;
+ // If the user touches a typed word 2 times or more, it will become valid.
+ private static final int VALIDITY_THRESHOLD = 2 * FREQUENCY_FOR_PICKED;
+ // If the user touches a typed word 5 times or more, it will be added to the user dict.
+ private static final int PROMOTION_THRESHOLD = 5 * FREQUENCY_FOR_PICKED;
public AutoDictionary(Context context) {
super(context);
@@ -1155,10 +1164,11 @@ public class LatinIME extends InputMethodService
}
@Override
- public void addWord(String word, int frequency) {
- super.addWord(word, 1);
- if (getWordFrequency(word) > PROMOTION_THRESHOLD) {
- LatinIME.this.promoteToUserDictionary(word, frequency);
+ public void addWord(String word, int addFrequency) {
+ super.addWord(word, addFrequency);
+ final int freq = getWordFrequency(word);
+ if (freq > PROMOTION_THRESHOLD) {
+ LatinIME.this.promoteToUserDictionary(word, FREQUENCY_FOR_AUTO_ADD);
}
}
}