aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java
diff options
context:
space:
mode:
authorSatoshi Kataoka <satok@google.com>2013-10-25 17:12:15 -0700
committerSatoshi Kataoka <satok@google.com>2013-10-28 11:25:38 -0700
commitba212e9d76b021dfb99239e55f860693dac6723b (patch)
treed1c4679f695fae8c90c0907c0c8a7d3295b52f1f /java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java
parent45d5d1e589771b68c4bc635e81b184bc52d65d36 (diff)
downloadlatinime-ba212e9d76b021dfb99239e55f860693dac6723b.tar.gz
latinime-ba212e9d76b021dfb99239e55f860693dac6723b.tar.xz
latinime-ba212e9d76b021dfb99239e55f860693dac6723b.zip
Add a facility to dump the dictionary contents while closing
Change-Id: I02e920e0512f2b46a778f0b23f7ca03f8d5dabe6
Diffstat (limited to 'java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java')
-rw-r--r--java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java
index 1de15a333..c817d3eb5 100644
--- a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java
+++ b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java
@@ -46,6 +46,7 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
private static final String TAG = DecayingExpandableBinaryDictionaryBase.class.getSimpleName();
public static final boolean DBG_SAVE_RESTORE = false;
private static final boolean DBG_STRESS_TEST = false;
+ private static final boolean DBG_DUMP_ON_CLOSE = false;
private static final boolean PROFILE_SAVE_RESTORE = LatinImeLogger.sDBG;
/** Any pair being typed or picked */
@@ -82,6 +83,9 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
@Override
public void close() {
+ if (DBG_DUMP_ON_CLOSE) {
+ dumpAllWordsForDebug();
+ }
if (!ExpandableBinaryDictionary.ENABLE_BINARY_DICTIONARY_DYNAMIC_UPDATE) {
closeBinaryDictionary();
}
@@ -222,6 +226,55 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
}
@UsedForTesting
+ public void dumpAllWordsForDebug() {
+ runAfterGcForDebug(new Runnable() {
+ @Override
+ public void run() {
+ dumpAllWordsForDebugLocked();
+ }
+ });
+ }
+
+ private void dumpAllWordsForDebugLocked() {
+ Log.d(TAG, "dumpAllWordsForDebug started.");
+ final OnAddWordListener listener = new OnAddWordListener() {
+ @Override
+ public void setUnigram(final String word, final String shortcutTarget,
+ final int frequency, final int shortcutFreq) {
+ Log.d(TAG, "load unigram: " + word + "," + frequency);
+ }
+
+ @Override
+ public void setBigram(final String word0, final String word1, final int frequency) {
+ if (word0.length() < Constants.DICTIONARY_MAX_WORD_LENGTH
+ && word1.length() < Constants.DICTIONARY_MAX_WORD_LENGTH) {
+ Log.d(TAG, "load bigram: " + word0 + "," + word1 + "," + frequency);
+ } else {
+ Log.d(TAG, "Skip inserting a too long bigram: " + word0 + "," + word1 + ","
+ + frequency);
+ }
+ }
+ };
+
+ // Load the dictionary from binary file
+ final File dictFile = new File(mContext.getFilesDir(), mFileName);
+ final DictDecoder dictDecoder = FormatSpec.getDictDecoder(dictFile,
+ DictDecoder.USE_BYTEARRAY);
+ if (dictDecoder == null) {
+ // This is an expected condition: we don't have a user history dictionary for this
+ // language yet. It will be created sometime later.
+ return;
+ }
+
+ try {
+ dictDecoder.openDictBuffer();
+ UserHistoryDictIOUtils.readDictionaryBinary(dictDecoder, listener);
+ } catch (IOException e) {
+ Log.d(TAG, "IOException on opening a bytebuffer", e);
+ }
+ }
+
+ @UsedForTesting
public void clearAndFlushDictionary() {
// Clear the node structure on memory
clear();