Rename BinaryDictDecoder to Ver3DictDecoder.

Change-Id: Ibf9b95b658df6e2c2218bdb62e2380f326a03832
main
Yuichiro Hanada 2013-08-20 15:48:16 +09:00
parent 66004ce2de
commit 112257e40f
20 changed files with 81 additions and 86 deletions

View File

@ -21,21 +21,16 @@ import android.content.SharedPreferences;
import android.content.res.AssetFileDescriptor; import android.content.res.AssetFileDescriptor;
import android.util.Log; 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.FormatSpec.FileHeader;
import com.android.inputmethod.latin.makedict.UnsupportedFormatException; 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.CollectionUtils;
import com.android.inputmethod.latin.utils.DictionaryInfoUtils; import com.android.inputmethod.latin.utils.DictionaryInfoUtils;
import com.android.inputmethod.latin.utils.LocaleUtils; import com.android.inputmethod.latin.utils.LocaleUtils;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.BufferUnderflowException; import java.nio.BufferUnderflowException;
import java.nio.channels.FileChannel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
@ -233,9 +228,9 @@ final public class BinaryDictionaryGetter {
private static boolean hackCanUseDictionaryFile(final Locale locale, final File f) { private static boolean hackCanUseDictionaryFile(final Locale locale, final File f) {
try { try {
// Read the version of the file // Read the version of the file
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(f); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(f);
dictDecoder.openDictBuffer( dictDecoder.openDictBuffer(
new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory());
final FileHeader header = dictDecoder.readHeader(); final FileHeader header = dictDecoder.readHeader();
final String version = header.mDictionaryOptions.mAttributes.get(VERSION_KEY); final String version = header.mDictionaryOptions.mAttributes.get(VERSION_KEY);

View File

@ -40,7 +40,7 @@ import java.util.TreeMap;
* *
* All the methods in this class are static. * 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. * TODO: Move this file to makedict/internal.
*/ */
public final class BinaryDictDecoderUtils { public final class BinaryDictDecoderUtils {
@ -649,13 +649,13 @@ public final class BinaryDictDecoderUtils {
* @return the created (or merged) dictionary. * @return the created (or merged) dictionary.
*/ */
@UsedForTesting @UsedForTesting
public static FusionDictionary readDictionaryBinary(final BinaryDictDecoder dictDecoder, public static FusionDictionary readDictionaryBinary(final Ver3DictDecoder dictDecoder,
final FusionDictionary dict) throws FileNotFoundException, IOException, final FusionDictionary dict) throws FileNotFoundException, IOException,
UnsupportedFormatException { UnsupportedFormatException {
// if the buffer has not been opened, open the buffer with bytebuffer. // if the buffer has not been opened, open the buffer with bytebuffer.
if (dictDecoder.getDictBuffer() == null) dictDecoder.openDictBuffer( if (dictDecoder.getDictBuffer() == null) dictDecoder.openDictBuffer(
new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory());
if (dictDecoder.getDictBuffer() == null) { if (dictDecoder.getDictBuffer() == null) {
MakedictLog.e("Cannot open the buffer"); MakedictLog.e("Cannot open the buffer");
} }

View File

@ -148,7 +148,7 @@ public final class BinaryDictIOUtils {
* @throws IOException if the file can't be read. * @throws IOException if the file can't be read.
* @throws UnsupportedFormatException if the format of the file is not recognized. * @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<Integer, String> words, final Map<Integer, Integer> frequencies, final Map<Integer, String> words, final Map<Integer, Integer> frequencies,
final Map<Integer, ArrayList<PendingAttribute>> bigrams) throws IOException, final Map<Integer, ArrayList<PendingAttribute>> bigrams) throws IOException,
UnsupportedFormatException { UnsupportedFormatException {
@ -169,7 +169,7 @@ public final class BinaryDictIOUtils {
* @throws UnsupportedFormatException if the format of the file is not recognized. * @throws UnsupportedFormatException if the format of the file is not recognized.
*/ */
@UsedForTesting @UsedForTesting
public static int getTerminalPosition(final BinaryDictDecoder dictDecoder, public static int getTerminalPosition(final Ver3DictDecoder dictDecoder,
final String word) throws IOException, UnsupportedFormatException { final String word) throws IOException, UnsupportedFormatException {
final DictBuffer dictBuffer = dictDecoder.getDictBuffer(); final DictBuffer dictBuffer = dictDecoder.getDictBuffer();
if (word == null) return FormatSpec.NOT_VALID_WORD; 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 dictDecoder the dict reader
* @param word the word searched * @param word the word searched
@ -517,7 +517,7 @@ public final class BinaryDictIOUtils {
* @throws UnsupportedFormatException * @throws UnsupportedFormatException
*/ */
@UsedForTesting @UsedForTesting
public static CharGroupInfo findWordByBinaryDictReader(final BinaryDictDecoder dictDecoder, public static CharGroupInfo findWordByBinaryDictReader(final Ver3DictDecoder dictDecoder,
final String word) throws IOException, UnsupportedFormatException { final String word) throws IOException, UnsupportedFormatException {
int position = getTerminalPosition(dictDecoder, word); int position = getTerminalPosition(dictDecoder, word);
final DictBuffer dictBuffer = dictDecoder.getDictBuffer(); final DictBuffer dictBuffer = dictDecoder.getDictBuffer();
@ -545,8 +545,8 @@ public final class BinaryDictIOUtils {
final File file, final long offset, final long length) final File file, final long offset, final long length)
throws FileNotFoundException, IOException, UnsupportedFormatException { throws FileNotFoundException, IOException, UnsupportedFormatException {
final byte[] buffer = new byte[HEADER_READING_BUFFER_SIZE]; final byte[] buffer = new byte[HEADER_READING_BUFFER_SIZE];
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file);
dictDecoder.openDictBuffer(new BinaryDictDecoder.DictionaryBufferFactory() { dictDecoder.openDictBuffer(new Ver3DictDecoder.DictionaryBufferFactory() {
@Override @Override
public DictBuffer getDictionaryBuffer(File file) public DictBuffer getDictionaryBuffer(File file)
throws FileNotFoundException, IOException { throws FileNotFoundException, IOException {

View File

@ -55,7 +55,7 @@ public final class DynamicBinaryDictIOUtils {
* @throws UnsupportedFormatException * @throws UnsupportedFormatException
*/ */
@UsedForTesting @UsedForTesting
public static void deleteWord(final BinaryDictDecoder dictDecoder, final String word) public static void deleteWord(final Ver3DictDecoder dictDecoder, final String word)
throws IOException, UnsupportedFormatException { throws IOException, UnsupportedFormatException {
final DictBuffer dictBuffer = dictDecoder.getDictBuffer(); final DictBuffer dictBuffer = dictDecoder.getDictBuffer();
dictBuffer.position(0); dictBuffer.position(0);
@ -253,7 +253,7 @@ public final class DynamicBinaryDictIOUtils {
// TODO: Support batch insertion. // TODO: Support batch insertion.
// TODO: Remove @UsedForTesting once UserHistoryDictionary is implemented by BinaryDictionary. // TODO: Remove @UsedForTesting once UserHistoryDictionary is implemented by BinaryDictionary.
@UsedForTesting @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 OutputStream destination, final String word, final int frequency,
final ArrayList<WeightedString> bigramStrings, final ArrayList<WeightedString> bigramStrings,
final ArrayList<WeightedString> shortcuts, final boolean isNotAWord, final ArrayList<WeightedString> shortcuts, final boolean isNotAWord,

View File

@ -33,9 +33,9 @@ import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.util.HashMap; import java.util.HashMap;
// TODO: Rename this class to "Ver3DictDecoder" or something, and make an interface "DictDecoder". // TODO: Make an interface "DictDecoder".
@UsedForTesting @UsedForTesting
public class BinaryDictDecoder { public class Ver3DictDecoder {
static { static {
JniUtils.loadNativeLibrary(); JniUtils.loadNativeLibrary();
@ -166,7 +166,7 @@ public class BinaryDictDecoder {
private final File mDictionaryBinaryFile; private final File mDictionaryBinaryFile;
private DictBuffer mDictBuffer; private DictBuffer mDictBuffer;
public BinaryDictDecoder(final File file) { public Ver3DictDecoder(final File file) {
mDictionaryBinaryFile = file; mDictionaryBinaryFile = file;
mDictBuffer = null; mDictBuffer = null;
} }

View File

@ -28,8 +28,8 @@ import com.android.inputmethod.latin.ExpandableDictionary;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.WordComposer; 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.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.Ver3DictDecoder;
import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils; import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils;
@ -241,10 +241,10 @@ public abstract class DynamicPredictionDictionaryBase extends ExpandableDictiona
}; };
// Load the dictionary from binary file // Load the dictionary from binary file
final BinaryDictDecoder reader = new BinaryDictDecoder( final Ver3DictDecoder reader = new Ver3DictDecoder(
new File(getContext().getFilesDir(), fileName)); new File(getContext().getFilesDir(), fileName));
try { try {
reader.openDictBuffer(new BinaryDictDecoder.DictionaryBufferFromByteArrayFactory()); reader.openDictBuffer(new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory());
UserHistoryDictIOUtils.readDictionaryBinary(reader, listener); UserHistoryDictIOUtils.readDictionaryBinary(reader, listener);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// This is an expected condition: we don't have a user history dictionary for this // This is an expected condition: we don't have a user history dictionary for this

View File

@ -19,7 +19,6 @@ package com.android.inputmethod.latin.utils;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.annotations.UsedForTesting; 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.BinaryDictEncoder;
import com.android.inputmethod.latin.makedict.BinaryDictIOUtils; import com.android.inputmethod.latin.makedict.BinaryDictIOUtils;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions; 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.FusionDictionary.PtNodeArray;
import com.android.inputmethod.latin.makedict.PendingAttribute; import com.android.inputmethod.latin.makedict.PendingAttribute;
import com.android.inputmethod.latin.makedict.UnsupportedFormatException; import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
import com.android.inputmethod.latin.makedict.Ver3DictDecoder;
import com.android.inputmethod.latin.personalization.UserHistoryDictionaryBigramList; import com.android.inputmethod.latin.personalization.UserHistoryDictionaryBigramList;
import java.io.IOException; import java.io.IOException;
@ -118,7 +118,7 @@ public final class UserHistoryDictIOUtils {
/** /**
* Reads dictionary from file. * Reads dictionary from file.
*/ */
public static void readDictionaryBinary(final BinaryDictDecoder dictDecoder, public static void readDictionaryBinary(final Ver3DictDecoder dictDecoder,
final OnAddWordListener dict) { final OnAddWordListener dict) {
final Map<Integer, String> unigrams = CollectionUtils.newTreeMap(); final Map<Integer, String> unigrams = CollectionUtils.newTreeMap();
final Map<Integer, Integer> frequencies = CollectionUtils.newTreeMap(); final Map<Integer, Integer> frequencies = CollectionUtils.newTreeMap();

View File

@ -43,7 +43,7 @@ LATIN_IME_JNI_SRC_FILES := \
com_android_inputmethod_keyboard_ProximityInfo.cpp \ com_android_inputmethod_keyboard_ProximityInfo.cpp \
com_android_inputmethod_latin_BinaryDictionary.cpp \ com_android_inputmethod_latin_BinaryDictionary.cpp \
com_android_inputmethod_latin_DicTraverseSession.cpp \ com_android_inputmethod_latin_DicTraverseSession.cpp \
com_android_inputmethod_latin_makedict_BinaryDictDecoder.cpp \ com_android_inputmethod_latin_makedict_Ver3DictDecoder.cpp \
jni_common.cpp jni_common.cpp
LATIN_IME_CORE_SRC_FILES := \ LATIN_IME_CORE_SRC_FILES := \

View File

@ -14,16 +14,16 @@
* limitations under the License. * 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 "defines.h"
#include "jni.h" #include "jni.h"
#include "jni_common.h" #include "jni_common.h"
namespace latinime { 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 // 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. // unlikely to be in memory by chance for testing purposes.
// TODO: remove this method. // TODO: remove this method.
@ -35,13 +35,13 @@ static const JNINativeMethod sMethods[] = {
// TODO: remove this entry when we have one useful method in here // TODO: remove this entry when we have one useful method in here
const_cast<char *>("doNothing"), const_cast<char *>("doNothing"),
const_cast<char *>("()I"), const_cast<char *>("()I"),
reinterpret_cast<void *>(latinime_BinaryDictDecoder_doNothing) reinterpret_cast<void *>(latinime_Ver3DictDecoder_doNothing)
}, },
}; };
int register_BinaryDictDecoder(JNIEnv *env) { int register_Ver3DictDecoder(JNIEnv *env) {
const char *const kClassPathName = const char *const kClassPathName =
"com/android/inputmethod/latin/makedict/BinaryDictDecoder"; "com/android/inputmethod/latin/makedict/Ver3DictDecoder";
return registerNativeMethods(env, kClassPathName, sMethods, NELEMS(sMethods)); return registerNativeMethods(env, kClassPathName, sMethods, NELEMS(sMethods));
} }
} // namespace latinime } // namespace latinime

View File

@ -14,12 +14,12 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef _COM_ANDROID_INPUTMETHOD_LATIN_MAKEDICT_BINARYDICTDECODER_H #ifndef _COM_ANDROID_INPUTMETHOD_LATIN_MAKEDICT_VER3DICTDECODER_H
#define _COM_ANDROID_INPUTMETHOD_LATIN_MAKEDICT_BINARYDICTDECODER_H #define _COM_ANDROID_INPUTMETHOD_LATIN_MAKEDICT_VER3DICTDECODER_H
#include "jni.h" #include "jni.h"
namespace latinime { namespace latinime {
int register_BinaryDictDecoder(JNIEnv *env); int register_Ver3DictDecoder(JNIEnv *env);
} // namespace latinime } // namespace latinime
#endif // _COM_ANDROID_INPUTMETHOD_LATIN_MAKEDICT_BINARYDICTDECODER_H #endif // _COM_ANDROID_INPUTMETHOD_LATIN_MAKEDICT_VER3DICTDECODER_H

View File

@ -23,7 +23,7 @@
#include "com_android_inputmethod_latin_BinaryDictionary.h" #include "com_android_inputmethod_latin_BinaryDictionary.h"
#include "com_android_inputmethod_latin_DicTraverseSession.h" #include "com_android_inputmethod_latin_DicTraverseSession.h"
#endif #endif
#include "com_android_inputmethod_latin_makedict_BinaryDictDecoder.h" #include "com_android_inputmethod_latin_makedict_Ver3DictDecoder.h"
#include "defines.h" #include "defines.h"
/* /*
@ -55,8 +55,8 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) {
return -1; return -1;
} }
#endif #endif
if (!latinime::register_BinaryDictDecoder(env)) { if (!latinime::register_Ver3DictDecoder(env)) {
AKLOGE("ERROR: BinaryDictDecoder native registration failed"); AKLOGE("ERROR: Ver3DictDecoder native registration failed");
return -1; return -1;
} }
/* success -- return valid version number */ /* success -- return valid version number */

View File

@ -41,7 +41,7 @@ class ProbabilityUtils {
// the unigram probability to be the median value of the 17th step from the top. A value of // 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, // 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. // 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<float>(MAX_PROBABILITY - unigramProbability) const float stepSize = static_cast<float>(MAX_PROBABILITY - unigramProbability)
/ (1.5f + MAX_BIGRAM_ENCODED_PROBABILITY); / (1.5f + MAX_BIGRAM_ENCODED_PROBABILITY);
return unigramProbability return unigramProbability

View File

@ -120,14 +120,14 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
/** /**
* Makes new DictBuffer according to BUFFER_TYPE. * 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 { throws FileNotFoundException, IOException {
if (bufferType == USE_BYTE_BUFFER) { if (bufferType == USE_BYTE_BUFFER) {
dictDecoder.openDictBuffer( dictDecoder.openDictBuffer(
new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory());
} else if (bufferType == USE_BYTE_ARRAY) { } else if (bufferType == USE_BYTE_ARRAY) {
dictDecoder.openDictBuffer( dictDecoder.openDictBuffer(
new BinaryDictDecoder.DictionaryBufferFromByteArrayFactory()); new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory());
} }
} }
@ -271,7 +271,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
final SparseArray<List<Integer>> bigrams, final Map<String, List<String>> shortcutMap, final SparseArray<List<Integer>> bigrams, final Map<String, List<String>> shortcutMap,
final int bufferType) { final int bufferType) {
long now, diff = -1; long now, diff = -1;
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file);
FusionDictionary dict = null; FusionDictionary dict = null;
try { try {
@ -409,7 +409,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
final Map<Integer, Integer> resultFreqs = CollectionUtils.newTreeMap(); final Map<Integer, Integer> resultFreqs = CollectionUtils.newTreeMap();
long now = -1, diff = -1; long now = -1, diff = -1;
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file);
try { try {
getDictBuffer(dictDecoder, bufferType); getDictBuffer(dictDecoder, bufferType);
assertNotNull("Can't get buffer.", dictDecoder.getDictBuffer()); assertNotNull("Can't get buffer.", dictDecoder.getDictBuffer());
@ -499,7 +499,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
} }
// Tests for getTerminalPosition // 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(); final DictBuffer dictBuffer = dictDecoder.getDictBuffer();
if (dictBuffer.position() != 0) dictBuffer.position(0); if (dictBuffer.position() != 0) dictBuffer.position(0);
@ -516,7 +516,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
address - fileHeader.mHeaderSize, fileHeader.mFormatOptions).mWord; 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) { int index, boolean contained) {
final int expectedFrequency = (UNIGRAM_FREQ + index) % 255; final int expectedFrequency = (UNIGRAM_FREQ + index) % 255;
long diff = -1; long diff = -1;
@ -552,10 +552,10 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
addUnigrams(sWords.size(), dict, sWords, null /* shortcutMap */); addUnigrams(sWords.size(), dict, sWords, null /* shortcutMap */);
timeWritingDictToFile(file, dict, VERSION3_WITH_DYNAMIC_UPDATE); timeWritingDictToFile(file, dict, VERSION3_WITH_DYNAMIC_UPDATE);
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file);
try { try {
dictDecoder.openDictBuffer( dictDecoder.openDictBuffer(
new BinaryDictDecoder.DictionaryBufferFromByteArrayFactory()); new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory());
} catch (IOException e) { } catch (IOException e) {
// ignore // ignore
Log.e(TAG, "IOException while opening the buffer", e); 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 */); addUnigrams(sWords.size(), dict, sWords, null /* shortcutMap */);
timeWritingDictToFile(file, dict, VERSION3_WITH_DYNAMIC_UPDATE); timeWritingDictToFile(file, dict, VERSION3_WITH_DYNAMIC_UPDATE);
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file);
try { try {
dictDecoder.openDictBuffer( dictDecoder.openDictBuffer(
new BinaryDictDecoder.DictionaryBufferFromByteArrayFactory()); new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory());
} catch (IOException e) { } catch (IOException e) {
// ignore // ignore
Log.e(TAG, "IOException while opening the buffer", e); Log.e(TAG, "IOException while opening the buffer", e);

View File

@ -22,12 +22,12 @@ import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer; 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.FormatSpec.FileHeader;
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray; import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString; import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.makedict.Ver3DictDecoder.
DictionaryBufferFromWritableByteBufferFactory;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; 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 { throws IOException, UnsupportedFormatException {
final FileHeader fileHeader = dictDecoder.readHeader(); final FileHeader fileHeader = dictDecoder.readHeader();
final DictBuffer buffer = dictDecoder.getDictBuffer(); final DictBuffer buffer = dictDecoder.getDictBuffer();
@ -139,12 +139,12 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
private int getWordPosition(final File file, final String word) { private int getWordPosition(final File file, final String word) {
int position = FormatSpec.NOT_VALID_WORD; int position = FormatSpec.NOT_VALID_WORD;
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file);
FileInputStream inStream = null; FileInputStream inStream = null;
try { try {
inStream = new FileInputStream(file); inStream = new FileInputStream(file);
dictDecoder.openDictBuffer( dictDecoder.openDictBuffer(
new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory());
position = BinaryDictIOUtils.getTerminalPosition(dictDecoder, word); position = BinaryDictIOUtils.getTerminalPosition(dictDecoder, word);
} catch (IOException e) { } catch (IOException e) {
} catch (UnsupportedFormatException e) { } catch (UnsupportedFormatException e) {
@ -161,11 +161,11 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
} }
private CharGroupInfo findWordFromFile(final File file, final String word) { private CharGroupInfo findWordFromFile(final File file, final String word) {
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file);
CharGroupInfo info = null; CharGroupInfo info = null;
try { try {
dictDecoder.openDictBuffer( dictDecoder.openDictBuffer(
new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory());
info = BinaryDictIOUtils.findWordByBinaryDictReader(dictDecoder, word); info = BinaryDictIOUtils.findWordByBinaryDictReader(dictDecoder, word);
} catch (IOException e) { } catch (IOException e) {
} catch (UnsupportedFormatException 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, private long insertAndCheckWord(final File file, final String word, final int frequency,
final boolean exist, final ArrayList<WeightedString> bigrams, final boolean exist, final ArrayList<WeightedString> bigrams,
final ArrayList<WeightedString> shortcuts) { final ArrayList<WeightedString> shortcuts) {
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file);
BufferedOutputStream outStream = null; BufferedOutputStream outStream = null;
long amountOfTime = -1; long amountOfTime = -1;
try { try {
@ -211,7 +211,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
} }
private void deleteWord(final File file, final String word) { private void deleteWord(final File file, final String word) {
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file);
try { try {
dictDecoder.openDictBuffer(new DictionaryBufferFromWritableByteBufferFactory()); dictDecoder.openDictBuffer(new DictionaryBufferFromWritableByteBufferFactory());
DynamicBinaryDictIOUtils.deleteWord(dictDecoder, word); 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) { 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 { try {
final DictBuffer dictBuffer = dictDecoder.openAndGetDictBuffer( final DictBuffer dictBuffer = dictDecoder.openAndGetDictBuffer(
new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory());
final FileHeader fileHeader = dictDecoder.readHeader(); final FileHeader fileHeader = dictDecoder.readHeader();
assertEquals(word, assertEquals(word,
BinaryDictDecoderUtils.getWordAtAddress(dictDecoder.getDictBuffer(), BinaryDictDecoderUtils.getWordAtAddress(dictDecoder.getDictBuffer(),

View File

@ -17,12 +17,12 @@
package com.android.inputmethod.latin.makedict; package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer; import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer;
import com.android.inputmethod.latin.makedict.BinaryDictDecoder.DictionaryBufferFactory; import com.android.inputmethod.latin.makedict.Ver3DictDecoder.DictionaryBufferFactory;
import com.android.inputmethod.latin.makedict.BinaryDictDecoder. import com.android.inputmethod.latin.makedict.Ver3DictDecoder.
DictionaryBufferFromByteArrayFactory; DictionaryBufferFromByteArrayFactory;
import com.android.inputmethod.latin.makedict.BinaryDictDecoder. import com.android.inputmethod.latin.makedict.Ver3DictDecoder.
DictionaryBufferFromReadOnlyByteBufferFactory; DictionaryBufferFromReadOnlyByteBufferFactory;
import com.android.inputmethod.latin.makedict.BinaryDictDecoder. import com.android.inputmethod.latin.makedict.Ver3DictDecoder.
DictionaryBufferFromWritableByteBufferFactory; DictionaryBufferFromWritableByteBufferFactory;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;
@ -33,10 +33,10 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
/** /**
* Unit tests for BinaryDictDecoder * Unit tests for Ver3DictDecoder
*/ */
public class BinaryDictDecoderTests extends AndroidTestCase { public class Ver3DictDecoderTests extends AndroidTestCase {
private static final String TAG = BinaryDictDecoderTests.class.getSimpleName(); private static final String TAG = Ver3DictDecoderTests.class.getSimpleName();
private final byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; 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); assertNotNull(testFile);
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(testFile); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(testFile);
try { try {
dictDecoder.openDictBuffer(factory); dictDecoder.openDictBuffer(factory);
} catch (Exception e) { } catch (Exception e) {
@ -113,7 +113,7 @@ public class BinaryDictDecoderTests extends AndroidTestCase {
Log.e(TAG, "IOException while the creating temporary file", e); 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. // the default return value of getBuffer() must be null.
assertNull("the default return value of getBuffer() is not null", assertNull("the default return value of getBuffer() is not null",

View File

@ -21,10 +21,10 @@ import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.latin.makedict.BinaryDictDecoder;
import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup; 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.personalization.UserHistoryDictionaryBigramList;
import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils.BigramDictionaryInterface; import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils.BigramDictionaryInterface;
import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils.OnAddWordListener; 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) { private void readDictFromFile(final File file, final OnAddWordListener listener) {
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file);
try { try {
dictDecoder.openDictBuffer( dictDecoder.openDictBuffer(
new BinaryDictDecoder.DictionaryBufferFromByteArrayFactory()); new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory());
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.e(TAG, "file not found", e); Log.e(TAG, "file not found", e);
} catch (IOException e) { } catch (IOException e) {

View File

@ -34,7 +34,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(LATINIME_NATIVE_SRC_DIR)
# Used in jni_common.cpp to avoid registering useless methods. # Used in jni_common.cpp to avoid registering useless methods.
LATIN_IME_JNI_SRC_FILES := \ LATIN_IME_JNI_SRC_FILES := \
com_android_inputmethod_latin_makedict_BinaryDictDecoder.cpp \ com_android_inputmethod_latin_makedict_Ver3DictDecoder.cpp \
jni_common.cpp jni_common.cpp
LATIN_IME_CORE_SRC_FILES := LATIN_IME_CORE_SRC_FILES :=

View File

@ -17,9 +17,9 @@
package com.android.inputmethod.latin.dicttool; package com.android.inputmethod.latin.dicttool;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils; 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.FusionDictionary;
import com.android.inputmethod.latin.makedict.UnsupportedFormatException; import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
import com.android.inputmethod.latin.makedict.Ver3DictDecoder;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -184,9 +184,9 @@ public final class BinaryDictOffdeviceUtils {
crash(filename, new RuntimeException( crash(filename, new RuntimeException(
filename + " does not seem to be a dictionary file")); filename + " does not seem to be a dictionary file"));
} else { } else {
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(decodedSpec.mFile); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(decodedSpec.mFile);
dictDecoder.openDictBuffer( dictDecoder.openDictBuffer(
new BinaryDictDecoder.DictionaryBufferFromByteArrayFactory()); new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory());
if (report) { if (report) {
System.out.println("Format : Binary dictionary format"); System.out.println("Format : Binary dictionary format");
System.out.println("Packaging : " + decodedSpec.describeChain()); System.out.println("Packaging : " + decodedSpec.describeChain());

View File

@ -18,11 +18,11 @@ package com.android.inputmethod.latin.dicttool;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils; import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils;
import com.android.inputmethod.latin.makedict.BinaryDictEncoder; 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.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.MakedictLog; import com.android.inputmethod.latin.makedict.MakedictLog;
import com.android.inputmethod.latin.makedict.UnsupportedFormatException; import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
import com.android.inputmethod.latin.makedict.Ver3DictDecoder;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
@ -266,9 +266,9 @@ public class DictionaryMaker {
private static FusionDictionary readBinaryFile(final String binaryFilename) private static FusionDictionary readBinaryFile(final String binaryFilename)
throws FileNotFoundException, IOException, UnsupportedFormatException { throws FileNotFoundException, IOException, UnsupportedFormatException {
final File file = new File(binaryFilename); final File file = new File(binaryFilename);
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file);
dictDecoder.openDictBuffer( dictDecoder.openDictBuffer(
new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory());
return BinaryDictDecoderUtils.readDictionaryBinary(dictDecoder, null); return BinaryDictDecoderUtils.readDictionaryBinary(dictDecoder, null);
} }

View File

@ -16,7 +16,6 @@
package com.android.inputmethod.latin.dicttool; 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.BinaryDictDecoderUtils;
import com.android.inputmethod.latin.makedict.BinaryDictEncoder; import com.android.inputmethod.latin.makedict.BinaryDictEncoder;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions; 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.DictionaryOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray; import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
import com.android.inputmethod.latin.makedict.UnsupportedFormatException; import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
import com.android.inputmethod.latin.makedict.Ver3DictDecoder;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -67,9 +67,9 @@ public class BinaryDictOffdeviceUtilsTests extends TestCase {
assertEquals("Wrong decode spec", BinaryDictOffdeviceUtils.COMPRESSION, step); assertEquals("Wrong decode spec", BinaryDictOffdeviceUtils.COMPRESSION, step);
} }
assertEquals("Wrong decode spec", 3, decodeSpec.mDecoderSpec.size()); assertEquals("Wrong decode spec", 3, decodeSpec.mDecoderSpec.size());
final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(decodeSpec.mFile); final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(decodeSpec.mFile);
dictDecoder.openDictBuffer( dictDecoder.openDictBuffer(
new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory());
final FusionDictionary resultDict = BinaryDictDecoderUtils.readDictionaryBinary(dictDecoder, final FusionDictionary resultDict = BinaryDictDecoderUtils.readDictionaryBinary(dictDecoder,
null /* dict : an optional dictionary to add words to, or null */); null /* dict : an optional dictionary to add words to, or null */);
assertEquals("Dictionary can't be read back correctly", assertEquals("Dictionary can't be read back correctly",