aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/UserBigramDictionary.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/UserBigramDictionary.java')
-rw-r--r--java/src/com/android/inputmethod/latin/UserBigramDictionary.java40
1 files changed, 19 insertions, 21 deletions
diff --git a/java/src/com/android/inputmethod/latin/UserBigramDictionary.java b/java/src/com/android/inputmethod/latin/UserBigramDictionary.java
index 67d9c0bcf..5b615ca29 100644
--- a/java/src/com/android/inputmethod/latin/UserBigramDictionary.java
+++ b/java/src/com/android/inputmethod/latin/UserBigramDictionary.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 Google Inc.
+ * Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
@@ -16,10 +16,6 @@
package com.android.inputmethod.latin;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
@@ -30,6 +26,10 @@ import android.os.AsyncTask;
import android.provider.BaseColumns;
import android.util.Log;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+
/**
* Stores all the pairs user types in databases. Prune the database if the size
* gets too big. Unlike AutoDictionary, it even stores the pairs that are already
@@ -44,12 +44,6 @@ public class UserBigramDictionary extends ExpandableDictionary {
/** Maximum frequency for all pairs */
private static final int FREQUENCY_MAX = 127;
- /**
- * If this pair is typed 6 times, it would be suggested.
- * Should be smaller than ContactsDictionary.FREQUENCY_FOR_CONTACTS_BIGRAM
- */
- protected static final int SUGGEST_THRESHOLD = 6 * FREQUENCY_FOR_TYPED;
-
/** Maximum number of pairs. Pruning will start when databases goes above this number. */
private static int sMaxUserBigrams = 10000;
@@ -108,25 +102,25 @@ public class UserBigramDictionary extends ExpandableDictionary {
private static DatabaseHelper sOpenHelper = null;
private static class Bigram {
- String word1;
- String word2;
- int frequency;
+ public final String mWord1;
+ public final String mWord2;
+ public final int frequency;
Bigram(String word1, String word2, int frequency) {
- this.word1 = word1;
- this.word2 = word2;
+ this.mWord1 = word1;
+ this.mWord2 = word2;
this.frequency = frequency;
}
@Override
public boolean equals(Object bigram) {
Bigram bigram2 = (Bigram) bigram;
- return (word1.equals(bigram2.word1) && word2.equals(bigram2.word2));
+ return (mWord1.equals(bigram2.mWord1) && mWord2.equals(bigram2.mWord2));
}
@Override
public int hashCode() {
- return (word1 + " " + word2).hashCode();
+ return (mWord1 + " " + mWord2).hashCode();
}
}
@@ -164,10 +158,14 @@ public class UserBigramDictionary extends ExpandableDictionary {
* Pair will be added to the userbigram database.
*/
public int addBigrams(String word1, String word2) {
- // remove caps
+ // remove caps if second word is autocapitalized
if (mIme != null && mIme.getCurrentWord().isAutoCapitalized()) {
word2 = Character.toLowerCase(word2.charAt(0)) + word2.substring(1);
}
+ // Do not insert a word as a bigram of itself
+ if (word1.equals(word2)) {
+ return 0;
+ }
int freq = super.addBigram(word1, word2, FREQUENCY_FOR_TYPED);
if (freq > FREQUENCY_MAX) freq = FREQUENCY_MAX;
@@ -357,7 +355,7 @@ public class UserBigramDictionary extends ExpandableDictionary {
Cursor c = db.query(MAIN_TABLE_NAME, new String[] { MAIN_COLUMN_ID },
MAIN_COLUMN_WORD1 + "=? AND " + MAIN_COLUMN_WORD2 + "=? AND "
+ MAIN_COLUMN_LOCALE + "=?",
- new String[] { bi.word1, bi.word2, mLocale }, null, null, null);
+ new String[] { bi.mWord1, bi.mWord2, mLocale }, null, null, null);
int pairId;
if (c.moveToFirst()) {
@@ -368,7 +366,7 @@ public class UserBigramDictionary extends ExpandableDictionary {
} else {
// new pair
Long pairIdLong = db.insert(MAIN_TABLE_NAME, null,
- getContentValues(bi.word1, bi.word2, mLocale));
+ getContentValues(bi.mWord1, bi.mWord2, mLocale));
pairId = pairIdLong.intValue();
}
c.close();