From 112257e40f6f6d914fac1c3a45f39a770693b386 Mon Sep 17 00:00:00 2001 From: Yuichiro Hanada Date: Tue, 20 Aug 2013 15:48:16 +0900 Subject: [PATCH] Rename BinaryDictDecoder to Ver3DictDecoder. Change-Id: Ibf9b95b658df6e2c2218bdb62e2380f326a03832 --- .../latin/BinaryDictionaryGetter.java | 11 +++------- .../makedict/BinaryDictDecoderUtils.java | 6 ++--- .../latin/makedict/BinaryDictIOUtils.java | 12 +++++----- .../makedict/DynamicBinaryDictIOUtils.java | 4 ++-- ...yDictDecoder.java => Ver3DictDecoder.java} | 6 ++--- .../DynamicPredictionDictionaryBase.java | 6 ++--- .../latin/utils/UserHistoryDictIOUtils.java | 4 ++-- native/jni/Android.mk | 2 +- ...method_latin_makedict_Ver3DictDecoder.cpp} | 12 +++++----- ...utmethod_latin_makedict_Ver3DictDecoder.h} | 8 +++---- native/jni/jni_common.cpp | 6 ++--- .../core/dictionary/probability_utils.h | 2 +- .../BinaryDictDecoderEncoderTests.java | 22 +++++++++---------- .../makedict/BinaryDictIOUtilsTests.java | 22 +++++++++---------- ...erTests.java => Ver3DictDecoderTests.java} | 18 +++++++-------- .../utils/UserHistoryDictIOUtilsTests.java | 6 ++--- tools/dicttool/NativeLib.mk | 2 +- .../dicttool/BinaryDictOffdeviceUtils.java | 6 ++--- .../latin/dicttool/DictionaryMaker.java | 6 ++--- .../BinaryDictOffdeviceUtilsTests.java | 6 ++--- 20 files changed, 81 insertions(+), 86 deletions(-) rename java/src/com/android/inputmethod/latin/makedict/{BinaryDictDecoder.java => Ver3DictDecoder.java} (97%) rename native/jni/{com_android_inputmethod_latin_makedict_BinaryDictDecoder.cpp => com_android_inputmethod_latin_makedict_Ver3DictDecoder.cpp} (76%) rename native/jni/{com_android_inputmethod_latin_makedict_BinaryDictDecoder.h => com_android_inputmethod_latin_makedict_Ver3DictDecoder.h} (73%) rename tests/src/com/android/inputmethod/latin/makedict/{BinaryDictDecoderTests.java => Ver3DictDecoderTests.java} (88%) diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index 0f5fc71cb..8f6b848bb 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -21,21 +21,16 @@ import android.content.SharedPreferences; import android.content.res.AssetFileDescriptor; import android.util.Log; -import com.android.inputmethod.latin.makedict.BinaryDictDecoder; -import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils; -import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer; -import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader; import com.android.inputmethod.latin.makedict.UnsupportedFormatException; +import com.android.inputmethod.latin.makedict.Ver3DictDecoder; import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.DictionaryInfoUtils; import com.android.inputmethod.latin.utils.LocaleUtils; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.nio.BufferUnderflowException; -import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.HashMap; import java.util.Locale; @@ -233,9 +228,9 @@ final public class BinaryDictionaryGetter { private static boolean hackCanUseDictionaryFile(final Locale locale, final File f) { try { // Read the version of the file - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(f); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(f); dictDecoder.openDictBuffer( - new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); + new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); final FileHeader header = dictDecoder.readHeader(); final String version = header.mDictionaryOptions.mAttributes.get(VERSION_KEY); diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java index d1974c8d4..995f061f3 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java @@ -40,7 +40,7 @@ import java.util.TreeMap; * * All the methods in this class are static. * - * TODO: Remove calls from classes except BinaryDictDecoder + * TODO: Remove calls from classes except Ver3DictDecoder * TODO: Move this file to makedict/internal. */ public final class BinaryDictDecoderUtils { @@ -649,13 +649,13 @@ public final class BinaryDictDecoderUtils { * @return the created (or merged) dictionary. */ @UsedForTesting - public static FusionDictionary readDictionaryBinary(final BinaryDictDecoder dictDecoder, + public static FusionDictionary readDictionaryBinary(final Ver3DictDecoder dictDecoder, final FusionDictionary dict) throws FileNotFoundException, IOException, UnsupportedFormatException { // if the buffer has not been opened, open the buffer with bytebuffer. if (dictDecoder.getDictBuffer() == null) dictDecoder.openDictBuffer( - new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); + new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); if (dictDecoder.getDictBuffer() == null) { MakedictLog.e("Cannot open the buffer"); } diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java index 1abc779d0..2539313c2 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java @@ -148,7 +148,7 @@ public final class BinaryDictIOUtils { * @throws IOException if the file can't be read. * @throws UnsupportedFormatException if the format of the file is not recognized. */ - public static void readUnigramsAndBigramsBinary(final BinaryDictDecoder dictDecoder, + public static void readUnigramsAndBigramsBinary(final Ver3DictDecoder dictDecoder, final Map words, final Map frequencies, final Map> bigrams) throws IOException, UnsupportedFormatException { @@ -169,7 +169,7 @@ public final class BinaryDictIOUtils { * @throws UnsupportedFormatException if the format of the file is not recognized. */ @UsedForTesting - public static int getTerminalPosition(final BinaryDictDecoder dictDecoder, + public static int getTerminalPosition(final Ver3DictDecoder dictDecoder, final String word) throws IOException, UnsupportedFormatException { final DictBuffer dictBuffer = dictDecoder.getDictBuffer(); if (word == null) return FormatSpec.NOT_VALID_WORD; @@ -508,7 +508,7 @@ public final class BinaryDictIOUtils { } /** - * Find a word using the BinaryDictDecoder. + * Find a word using the Ver3DictDecoder. * * @param dictDecoder the dict reader * @param word the word searched @@ -517,7 +517,7 @@ public final class BinaryDictIOUtils { * @throws UnsupportedFormatException */ @UsedForTesting - public static CharGroupInfo findWordByBinaryDictReader(final BinaryDictDecoder dictDecoder, + public static CharGroupInfo findWordByBinaryDictReader(final Ver3DictDecoder dictDecoder, final String word) throws IOException, UnsupportedFormatException { int position = getTerminalPosition(dictDecoder, word); final DictBuffer dictBuffer = dictDecoder.getDictBuffer(); @@ -545,8 +545,8 @@ public final class BinaryDictIOUtils { final File file, final long offset, final long length) throws FileNotFoundException, IOException, UnsupportedFormatException { final byte[] buffer = new byte[HEADER_READING_BUFFER_SIZE]; - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); - dictDecoder.openDictBuffer(new BinaryDictDecoder.DictionaryBufferFactory() { + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); + dictDecoder.openDictBuffer(new Ver3DictDecoder.DictionaryBufferFactory() { @Override public DictBuffer getDictionaryBuffer(File file) throws FileNotFoundException, IOException { diff --git a/java/src/com/android/inputmethod/latin/makedict/DynamicBinaryDictIOUtils.java b/java/src/com/android/inputmethod/latin/makedict/DynamicBinaryDictIOUtils.java index 6c1e75cbb..99deaa4f9 100644 --- a/java/src/com/android/inputmethod/latin/makedict/DynamicBinaryDictIOUtils.java +++ b/java/src/com/android/inputmethod/latin/makedict/DynamicBinaryDictIOUtils.java @@ -55,7 +55,7 @@ public final class DynamicBinaryDictIOUtils { * @throws UnsupportedFormatException */ @UsedForTesting - public static void deleteWord(final BinaryDictDecoder dictDecoder, final String word) + public static void deleteWord(final Ver3DictDecoder dictDecoder, final String word) throws IOException, UnsupportedFormatException { final DictBuffer dictBuffer = dictDecoder.getDictBuffer(); dictBuffer.position(0); @@ -253,7 +253,7 @@ public final class DynamicBinaryDictIOUtils { // TODO: Support batch insertion. // TODO: Remove @UsedForTesting once UserHistoryDictionary is implemented by BinaryDictionary. @UsedForTesting - public static void insertWord(final BinaryDictDecoder dictDecoder, + public static void insertWord(final Ver3DictDecoder dictDecoder, final OutputStream destination, final String word, final int frequency, final ArrayList bigramStrings, final ArrayList shortcuts, final boolean isNotAWord, diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java similarity index 97% rename from java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java rename to java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java index 2007b6284..7c18c8caa 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java +++ b/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java @@ -33,9 +33,9 @@ import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.HashMap; -// TODO: Rename this class to "Ver3DictDecoder" or something, and make an interface "DictDecoder". +// TODO: Make an interface "DictDecoder". @UsedForTesting -public class BinaryDictDecoder { +public class Ver3DictDecoder { static { JniUtils.loadNativeLibrary(); @@ -166,7 +166,7 @@ public class BinaryDictDecoder { private final File mDictionaryBinaryFile; private DictBuffer mDictBuffer; - public BinaryDictDecoder(final File file) { + public Ver3DictDecoder(final File file) { mDictionaryBinaryFile = file; mDictBuffer = null; } diff --git a/java/src/com/android/inputmethod/latin/personalization/DynamicPredictionDictionaryBase.java b/java/src/com/android/inputmethod/latin/personalization/DynamicPredictionDictionaryBase.java index 8160501a9..b565b2f9f 100644 --- a/java/src/com/android/inputmethod/latin/personalization/DynamicPredictionDictionaryBase.java +++ b/java/src/com/android/inputmethod/latin/personalization/DynamicPredictionDictionaryBase.java @@ -28,8 +28,8 @@ import com.android.inputmethod.latin.ExpandableDictionary; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.WordComposer; -import com.android.inputmethod.latin.makedict.BinaryDictDecoder; import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions; +import com.android.inputmethod.latin.makedict.Ver3DictDecoder; import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils; @@ -241,10 +241,10 @@ public abstract class DynamicPredictionDictionaryBase extends ExpandableDictiona }; // Load the dictionary from binary file - final BinaryDictDecoder reader = new BinaryDictDecoder( + final Ver3DictDecoder reader = new Ver3DictDecoder( new File(getContext().getFilesDir(), fileName)); try { - reader.openDictBuffer(new BinaryDictDecoder.DictionaryBufferFromByteArrayFactory()); + reader.openDictBuffer(new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory()); UserHistoryDictIOUtils.readDictionaryBinary(reader, listener); } catch (FileNotFoundException e) { // This is an expected condition: we don't have a user history dictionary for this diff --git a/java/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtils.java b/java/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtils.java index dd7f534dc..768d68cb3 100644 --- a/java/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtils.java @@ -19,7 +19,6 @@ package com.android.inputmethod.latin.utils; import android.util.Log; import com.android.inputmethod.annotations.UsedForTesting; -import com.android.inputmethod.latin.makedict.BinaryDictDecoder; import com.android.inputmethod.latin.makedict.BinaryDictEncoder; import com.android.inputmethod.latin.makedict.BinaryDictIOUtils; import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions; @@ -27,6 +26,7 @@ import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray; import com.android.inputmethod.latin.makedict.PendingAttribute; import com.android.inputmethod.latin.makedict.UnsupportedFormatException; +import com.android.inputmethod.latin.makedict.Ver3DictDecoder; import com.android.inputmethod.latin.personalization.UserHistoryDictionaryBigramList; import java.io.IOException; @@ -118,7 +118,7 @@ public final class UserHistoryDictIOUtils { /** * Reads dictionary from file. */ - public static void readDictionaryBinary(final BinaryDictDecoder dictDecoder, + public static void readDictionaryBinary(final Ver3DictDecoder dictDecoder, final OnAddWordListener dict) { final Map unigrams = CollectionUtils.newTreeMap(); final Map frequencies = CollectionUtils.newTreeMap(); diff --git a/native/jni/Android.mk b/native/jni/Android.mk index 9e7407abd..a51fe3c03 100644 --- a/native/jni/Android.mk +++ b/native/jni/Android.mk @@ -43,7 +43,7 @@ LATIN_IME_JNI_SRC_FILES := \ com_android_inputmethod_keyboard_ProximityInfo.cpp \ com_android_inputmethod_latin_BinaryDictionary.cpp \ com_android_inputmethod_latin_DicTraverseSession.cpp \ - com_android_inputmethod_latin_makedict_BinaryDictDecoder.cpp \ + com_android_inputmethod_latin_makedict_Ver3DictDecoder.cpp \ jni_common.cpp LATIN_IME_CORE_SRC_FILES := \ diff --git a/native/jni/com_android_inputmethod_latin_makedict_BinaryDictDecoder.cpp b/native/jni/com_android_inputmethod_latin_makedict_Ver3DictDecoder.cpp similarity index 76% rename from native/jni/com_android_inputmethod_latin_makedict_BinaryDictDecoder.cpp rename to native/jni/com_android_inputmethod_latin_makedict_Ver3DictDecoder.cpp index 457b226b6..15088b65a 100644 --- a/native/jni/com_android_inputmethod_latin_makedict_BinaryDictDecoder.cpp +++ b/native/jni/com_android_inputmethod_latin_makedict_Ver3DictDecoder.cpp @@ -14,16 +14,16 @@ * limitations under the License. */ -#define LOG_TAG "LatinIME: jni: BinaryDictDecoder" +#define LOG_TAG "LatinIME: jni: Ver3DictDecoder" -#include "com_android_inputmethod_latin_makedict_BinaryDictDecoder.h" +#include "com_android_inputmethod_latin_makedict_Ver3DictDecoder.h" #include "defines.h" #include "jni.h" #include "jni_common.h" namespace latinime { -static int latinime_BinaryDictDecoder_doNothing(JNIEnv *env, jclass clazz) { +static int latinime_Ver3DictDecoder_doNothing(JNIEnv *env, jclass clazz) { // This is a phony method for test - it does nothing. It just returns some value // unlikely to be in memory by chance for testing purposes. // TODO: remove this method. @@ -35,13 +35,13 @@ static const JNINativeMethod sMethods[] = { // TODO: remove this entry when we have one useful method in here const_cast("doNothing"), const_cast("()I"), - reinterpret_cast(latinime_BinaryDictDecoder_doNothing) + reinterpret_cast(latinime_Ver3DictDecoder_doNothing) }, }; -int register_BinaryDictDecoder(JNIEnv *env) { +int register_Ver3DictDecoder(JNIEnv *env) { const char *const kClassPathName = - "com/android/inputmethod/latin/makedict/BinaryDictDecoder"; + "com/android/inputmethod/latin/makedict/Ver3DictDecoder"; return registerNativeMethods(env, kClassPathName, sMethods, NELEMS(sMethods)); } } // namespace latinime diff --git a/native/jni/com_android_inputmethod_latin_makedict_BinaryDictDecoder.h b/native/jni/com_android_inputmethod_latin_makedict_Ver3DictDecoder.h similarity index 73% rename from native/jni/com_android_inputmethod_latin_makedict_BinaryDictDecoder.h rename to native/jni/com_android_inputmethod_latin_makedict_Ver3DictDecoder.h index 7f3cb67e6..07e80f1d8 100644 --- a/native/jni/com_android_inputmethod_latin_makedict_BinaryDictDecoder.h +++ b/native/jni/com_android_inputmethod_latin_makedict_Ver3DictDecoder.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef _COM_ANDROID_INPUTMETHOD_LATIN_MAKEDICT_BINARYDICTDECODER_H -#define _COM_ANDROID_INPUTMETHOD_LATIN_MAKEDICT_BINARYDICTDECODER_H +#ifndef _COM_ANDROID_INPUTMETHOD_LATIN_MAKEDICT_VER3DICTDECODER_H +#define _COM_ANDROID_INPUTMETHOD_LATIN_MAKEDICT_VER3DICTDECODER_H #include "jni.h" namespace latinime { -int register_BinaryDictDecoder(JNIEnv *env); +int register_Ver3DictDecoder(JNIEnv *env); } // namespace latinime -#endif // _COM_ANDROID_INPUTMETHOD_LATIN_MAKEDICT_BINARYDICTDECODER_H +#endif // _COM_ANDROID_INPUTMETHOD_LATIN_MAKEDICT_VER3DICTDECODER_H diff --git a/native/jni/jni_common.cpp b/native/jni/jni_common.cpp index d44be6705..3a8f4362d 100644 --- a/native/jni/jni_common.cpp +++ b/native/jni/jni_common.cpp @@ -23,7 +23,7 @@ #include "com_android_inputmethod_latin_BinaryDictionary.h" #include "com_android_inputmethod_latin_DicTraverseSession.h" #endif -#include "com_android_inputmethod_latin_makedict_BinaryDictDecoder.h" +#include "com_android_inputmethod_latin_makedict_Ver3DictDecoder.h" #include "defines.h" /* @@ -55,8 +55,8 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) { return -1; } #endif - if (!latinime::register_BinaryDictDecoder(env)) { - AKLOGE("ERROR: BinaryDictDecoder native registration failed"); + if (!latinime::register_Ver3DictDecoder(env)) { + AKLOGE("ERROR: Ver3DictDecoder native registration failed"); return -1; } /* success -- return valid version number */ diff --git a/native/jni/src/suggest/core/dictionary/probability_utils.h b/native/jni/src/suggest/core/dictionary/probability_utils.h index 219213574..21fe355b8 100644 --- a/native/jni/src/suggest/core/dictionary/probability_utils.h +++ b/native/jni/src/suggest/core/dictionary/probability_utils.h @@ -41,7 +41,7 @@ class ProbabilityUtils { // the unigram probability to be the median value of the 17th step from the top. A value of // 0 for the bigram probability represents the middle of the 16th step from the top, // while a value of 15 represents the middle of the top step. - // See makedict.BinaryDictDecoder for details. + // See makedict.BinaryDictEncoder#makeBigramFlags for details. const float stepSize = static_cast(MAX_PROBABILITY - unigramProbability) / (1.5f + MAX_BIGRAM_ENCODED_PROBABILITY); return unigramProbability diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java index 028e089f8..f3ca2b147 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java @@ -120,14 +120,14 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { /** * Makes new DictBuffer according to BUFFER_TYPE. */ - private void getDictBuffer(final BinaryDictDecoder dictDecoder, final int bufferType) + private void getDictBuffer(final Ver3DictDecoder dictDecoder, final int bufferType) throws FileNotFoundException, IOException { if (bufferType == USE_BYTE_BUFFER) { dictDecoder.openDictBuffer( - new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); + new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); } else if (bufferType == USE_BYTE_ARRAY) { dictDecoder.openDictBuffer( - new BinaryDictDecoder.DictionaryBufferFromByteArrayFactory()); + new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory()); } } @@ -271,7 +271,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { final SparseArray> bigrams, final Map> shortcutMap, final int bufferType) { long now, diff = -1; - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); FusionDictionary dict = null; try { @@ -409,7 +409,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { final Map resultFreqs = CollectionUtils.newTreeMap(); long now = -1, diff = -1; - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); try { getDictBuffer(dictDecoder, bufferType); assertNotNull("Can't get buffer.", dictDecoder.getDictBuffer()); @@ -499,7 +499,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { } // Tests for getTerminalPosition - private String getWordFromBinary(final BinaryDictDecoder dictDecoder, final int address) { + private String getWordFromBinary(final Ver3DictDecoder dictDecoder, final int address) { final DictBuffer dictBuffer = dictDecoder.getDictBuffer(); if (dictBuffer.position() != 0) dictBuffer.position(0); @@ -516,7 +516,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { address - fileHeader.mHeaderSize, fileHeader.mFormatOptions).mWord; } - private long runGetTerminalPosition(final BinaryDictDecoder dictDecoder, final String word, + private long runGetTerminalPosition(final Ver3DictDecoder dictDecoder, final String word, int index, boolean contained) { final int expectedFrequency = (UNIGRAM_FREQ + index) % 255; long diff = -1; @@ -552,10 +552,10 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { addUnigrams(sWords.size(), dict, sWords, null /* shortcutMap */); timeWritingDictToFile(file, dict, VERSION3_WITH_DYNAMIC_UPDATE); - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); try { dictDecoder.openDictBuffer( - new BinaryDictDecoder.DictionaryBufferFromByteArrayFactory()); + new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory()); } catch (IOException e) { // ignore Log.e(TAG, "IOException while opening the buffer", e); @@ -613,10 +613,10 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { addUnigrams(sWords.size(), dict, sWords, null /* shortcutMap */); timeWritingDictToFile(file, dict, VERSION3_WITH_DYNAMIC_UPDATE); - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); try { dictDecoder.openDictBuffer( - new BinaryDictDecoder.DictionaryBufferFromByteArrayFactory()); + new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory()); } catch (IOException e) { // ignore Log.e(TAG, "IOException while opening the buffer", e); diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java index b6e439561..f0ad58fea 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java @@ -22,12 +22,12 @@ import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer; -import com.android.inputmethod.latin.makedict.BinaryDictDecoder. - DictionaryBufferFromWritableByteBufferFactory; import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader; import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray; import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString; import com.android.inputmethod.latin.utils.CollectionUtils; +import com.android.inputmethod.latin.makedict.Ver3DictDecoder. + DictionaryBufferFromWritableByteBufferFactory; import java.io.BufferedOutputStream; import java.io.File; @@ -128,7 +128,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { } } - private static void printBinaryFile(final BinaryDictDecoder dictDecoder) + private static void printBinaryFile(final Ver3DictDecoder dictDecoder) throws IOException, UnsupportedFormatException { final FileHeader fileHeader = dictDecoder.readHeader(); final DictBuffer buffer = dictDecoder.getDictBuffer(); @@ -139,12 +139,12 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { private int getWordPosition(final File file, final String word) { int position = FormatSpec.NOT_VALID_WORD; - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); FileInputStream inStream = null; try { inStream = new FileInputStream(file); dictDecoder.openDictBuffer( - new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); + new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); position = BinaryDictIOUtils.getTerminalPosition(dictDecoder, word); } catch (IOException e) { } catch (UnsupportedFormatException e) { @@ -161,11 +161,11 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { } private CharGroupInfo findWordFromFile(final File file, final String word) { - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); CharGroupInfo info = null; try { dictDecoder.openDictBuffer( - new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); + new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); info = BinaryDictIOUtils.findWordByBinaryDictReader(dictDecoder, word); } catch (IOException e) { } catch (UnsupportedFormatException e) { @@ -177,7 +177,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { private long insertAndCheckWord(final File file, final String word, final int frequency, final boolean exist, final ArrayList bigrams, final ArrayList shortcuts) { - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); BufferedOutputStream outStream = null; long amountOfTime = -1; try { @@ -211,7 +211,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { } private void deleteWord(final File file, final String word) { - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); try { dictDecoder.openDictBuffer(new DictionaryBufferFromWritableByteBufferFactory()); DynamicBinaryDictIOUtils.deleteWord(dictDecoder, word); @@ -221,10 +221,10 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { } private void checkReverseLookup(final File file, final String word, final int position) { - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); try { final DictBuffer dictBuffer = dictDecoder.openAndGetDictBuffer( - new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); + new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); final FileHeader fileHeader = dictDecoder.readHeader(); assertEquals(word, BinaryDictDecoderUtils.getWordAtAddress(dictDecoder.getDictBuffer(), diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/Ver3DictDecoderTests.java similarity index 88% rename from tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderTests.java rename to tests/src/com/android/inputmethod/latin/makedict/Ver3DictDecoderTests.java index 03742c4c1..43c9b919b 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/Ver3DictDecoderTests.java @@ -17,12 +17,12 @@ package com.android.inputmethod.latin.makedict; import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer; -import com.android.inputmethod.latin.makedict.BinaryDictDecoder.DictionaryBufferFactory; -import com.android.inputmethod.latin.makedict.BinaryDictDecoder. +import com.android.inputmethod.latin.makedict.Ver3DictDecoder.DictionaryBufferFactory; +import com.android.inputmethod.latin.makedict.Ver3DictDecoder. DictionaryBufferFromByteArrayFactory; -import com.android.inputmethod.latin.makedict.BinaryDictDecoder. +import com.android.inputmethod.latin.makedict.Ver3DictDecoder. DictionaryBufferFromReadOnlyByteBufferFactory; -import com.android.inputmethod.latin.makedict.BinaryDictDecoder. +import com.android.inputmethod.latin.makedict.Ver3DictDecoder. DictionaryBufferFromWritableByteBufferFactory; import android.test.AndroidTestCase; @@ -33,10 +33,10 @@ import java.io.FileOutputStream; import java.io.IOException; /** - * Unit tests for BinaryDictDecoder + * Unit tests for Ver3DictDecoder */ -public class BinaryDictDecoderTests extends AndroidTestCase { - private static final String TAG = BinaryDictDecoderTests.class.getSimpleName(); +public class Ver3DictDecoderTests extends AndroidTestCase { + private static final String TAG = Ver3DictDecoderTests.class.getSimpleName(); private final byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; @@ -70,7 +70,7 @@ public class BinaryDictDecoderTests extends AndroidTestCase { } assertNotNull(testFile); - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(testFile); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(testFile); try { dictDecoder.openDictBuffer(factory); } catch (Exception e) { @@ -113,7 +113,7 @@ public class BinaryDictDecoderTests extends AndroidTestCase { Log.e(TAG, "IOException while the creating temporary file", e); } - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(testFile); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(testFile); // the default return value of getBuffer() must be null. assertNull("the default return value of getBuffer() is not null", diff --git a/tests/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtilsTests.java index 83d9c2122..eca12c0d8 100644 --- a/tests/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtilsTests.java @@ -21,10 +21,10 @@ import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; -import com.android.inputmethod.latin.makedict.BinaryDictDecoder; import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup; +import com.android.inputmethod.latin.makedict.Ver3DictDecoder; import com.android.inputmethod.latin.personalization.UserHistoryDictionaryBigramList; import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils.BigramDictionaryInterface; import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils.OnAddWordListener; @@ -147,10 +147,10 @@ public class UserHistoryDictIOUtilsTests extends AndroidTestCase } private void readDictFromFile(final File file, final OnAddWordListener listener) { - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); try { dictDecoder.openDictBuffer( - new BinaryDictDecoder.DictionaryBufferFromByteArrayFactory()); + new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory()); } catch (FileNotFoundException e) { Log.e(TAG, "file not found", e); } catch (IOException e) { diff --git a/tools/dicttool/NativeLib.mk b/tools/dicttool/NativeLib.mk index 84e54a931..a3d3c0295 100644 --- a/tools/dicttool/NativeLib.mk +++ b/tools/dicttool/NativeLib.mk @@ -34,7 +34,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(LATINIME_NATIVE_SRC_DIR) # Used in jni_common.cpp to avoid registering useless methods. LATIN_IME_JNI_SRC_FILES := \ - com_android_inputmethod_latin_makedict_BinaryDictDecoder.cpp \ + com_android_inputmethod_latin_makedict_Ver3DictDecoder.cpp \ jni_common.cpp LATIN_IME_CORE_SRC_FILES := diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java index 39ba69b1f..d8fcbeeaf 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java @@ -17,9 +17,9 @@ package com.android.inputmethod.latin.dicttool; import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils; -import com.android.inputmethod.latin.makedict.BinaryDictDecoder; import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.UnsupportedFormatException; +import com.android.inputmethod.latin.makedict.Ver3DictDecoder; import org.xml.sax.SAXException; @@ -184,9 +184,9 @@ public final class BinaryDictOffdeviceUtils { crash(filename, new RuntimeException( filename + " does not seem to be a dictionary file")); } else { - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(decodedSpec.mFile); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(decodedSpec.mFile); dictDecoder.openDictBuffer( - new BinaryDictDecoder.DictionaryBufferFromByteArrayFactory()); + new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory()); if (report) { System.out.println("Format : Binary dictionary format"); System.out.println("Packaging : " + decodedSpec.describeChain()); diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/DictionaryMaker.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/DictionaryMaker.java index f87e9722c..a0fcaabd0 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/DictionaryMaker.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/DictionaryMaker.java @@ -18,11 +18,11 @@ package com.android.inputmethod.latin.dicttool; import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils; import com.android.inputmethod.latin.makedict.BinaryDictEncoder; -import com.android.inputmethod.latin.makedict.BinaryDictDecoder; import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.MakedictLog; import com.android.inputmethod.latin.makedict.UnsupportedFormatException; +import com.android.inputmethod.latin.makedict.Ver3DictDecoder; import java.io.BufferedWriter; import java.io.File; @@ -266,9 +266,9 @@ public class DictionaryMaker { private static FusionDictionary readBinaryFile(final String binaryFilename) throws FileNotFoundException, IOException, UnsupportedFormatException { final File file = new File(binaryFilename); - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); dictDecoder.openDictBuffer( - new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); + new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); return BinaryDictDecoderUtils.readDictionaryBinary(dictDecoder, null); } diff --git a/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java b/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java index b960b035d..451b145e9 100644 --- a/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java +++ b/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java @@ -16,7 +16,6 @@ package com.android.inputmethod.latin.dicttool; -import com.android.inputmethod.latin.makedict.BinaryDictDecoder; import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils; import com.android.inputmethod.latin.makedict.BinaryDictEncoder; import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions; @@ -24,6 +23,7 @@ import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions; import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray; import com.android.inputmethod.latin.makedict.UnsupportedFormatException; +import com.android.inputmethod.latin.makedict.Ver3DictDecoder; import junit.framework.TestCase; @@ -67,9 +67,9 @@ public class BinaryDictOffdeviceUtilsTests extends TestCase { assertEquals("Wrong decode spec", BinaryDictOffdeviceUtils.COMPRESSION, step); } assertEquals("Wrong decode spec", 3, decodeSpec.mDecoderSpec.size()); - final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(decodeSpec.mFile); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(decodeSpec.mFile); dictDecoder.openDictBuffer( - new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); + new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); final FusionDictionary resultDict = BinaryDictDecoderUtils.readDictionaryBinary(dictDecoder, null /* dict : an optional dictionary to add words to, or null */); assertEquals("Dictionary can't be read back correctly",