parent
606a056b53
commit
8aaae56cf6
|
@ -84,6 +84,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
/** Controls access to the local binary dictionary for this instance. */
|
||||
private final DictionaryController mLocalDictionaryController = new DictionaryController();
|
||||
|
||||
/* A extension for a binary dictionary file. */
|
||||
public static final String DICT_FILE_EXTENSION = ".dict";
|
||||
|
||||
/**
|
||||
* Abstract method for loading the unigrams and bigrams of a given dictionary in a background
|
||||
* thread.
|
||||
|
@ -129,7 +132,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
}
|
||||
|
||||
protected static String getFilenameWithLocale(final String name, final String localeStr) {
|
||||
return name + "." + localeStr + ".dict";
|
||||
return name + "." + localeStr + DICT_FILE_EXTENSION;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package com.android.inputmethod.latin.personalization;
|
||||
|
||||
import com.android.inputmethod.latin.Dictionary;
|
||||
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -31,6 +32,6 @@ public class PersonalizationPredictionDictionary extends DynamicPredictionDictio
|
|||
|
||||
@Override
|
||||
protected String getDictionaryFileName() {
|
||||
return NAME + "." + getLocale() + ".dict";
|
||||
return NAME + "." + getLocale() + ExpandableBinaryDictionary.DICT_FILE_EXTENSION;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package com.android.inputmethod.latin.personalization;
|
||||
|
||||
import com.android.inputmethod.latin.Dictionary;
|
||||
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -35,6 +36,6 @@ public class UserHistoryPredictionDictionary extends DynamicPredictionDictionary
|
|||
|
||||
@Override
|
||||
protected String getDictionaryFileName() {
|
||||
return NAME + "." + getLocale() + ".dict";
|
||||
return NAME + "." + getLocale() + ExpandableBinaryDictionary.DICT_FILE_EXTENSION;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,6 +71,8 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
|
|||
private static final FormatSpec.FormatOptions VERSION3_WITH_DYNAMIC_UPDATE =
|
||||
new FormatSpec.FormatOptions(3, true /* supportsDynamicUpdate */);
|
||||
|
||||
private static final String TEST_DICT_FILE_EXTENSION = ".testDict";
|
||||
|
||||
public BinaryDictDecoderEncoderTests() {
|
||||
this(System.currentTimeMillis(), DEFAULT_MAX_UNIGRAMS);
|
||||
}
|
||||
|
@ -293,7 +295,8 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
|
|||
final String message) {
|
||||
File file = null;
|
||||
try {
|
||||
file = File.createTempFile("runReadAndWrite", ".dict", getContext().getCacheDir());
|
||||
file = File.createTempFile("runReadAndWrite", TEST_DICT_FILE_EXTENSION,
|
||||
getContext().getCacheDir());
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "IOException", e);
|
||||
}
|
||||
|
@ -435,7 +438,8 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
|
|||
final FormatSpec.FormatOptions formatOptions, final String message) {
|
||||
File file = null;
|
||||
try {
|
||||
file = File.createTempFile("runReadUnigrams", ".dict", getContext().getCacheDir());
|
||||
file = File.createTempFile("runReadUnigrams", TEST_DICT_FILE_EXTENSION,
|
||||
getContext().getCacheDir());
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "IOException", e);
|
||||
}
|
||||
|
@ -533,7 +537,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
|
|||
public void testGetTerminalPosition() {
|
||||
File file = null;
|
||||
try {
|
||||
file = File.createTempFile("testGetTerminalPosition", ".dict",
|
||||
file = File.createTempFile("testGetTerminalPosition", TEST_DICT_FILE_EXTENSION,
|
||||
getContext().getCacheDir());
|
||||
} catch (IOException e) {
|
||||
// do nothing
|
||||
|
@ -593,7 +597,8 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
|
|||
public void testDeleteWord() {
|
||||
File file = null;
|
||||
try {
|
||||
file = File.createTempFile("testDeleteWord", ".dict", getContext().getCacheDir());
|
||||
file = File.createTempFile("testDeleteWord", TEST_DICT_FILE_EXTENSION,
|
||||
getContext().getCacheDir());
|
||||
} catch (IOException e) {
|
||||
// do nothing
|
||||
}
|
||||
|
|
|
@ -48,6 +48,8 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
|
|||
public static final int DEFAULT_MAX_UNIGRAMS = 1500;
|
||||
private final int mMaxUnigrams;
|
||||
|
||||
private static final String TEST_DICT_FILE_EXTENSION = ".testDict";
|
||||
|
||||
private static final String[] CHARACTERS = {
|
||||
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
|
||||
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
|
||||
|
@ -234,7 +236,8 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
|
|||
public void testInsertWord() {
|
||||
File file = null;
|
||||
try {
|
||||
file = File.createTempFile("testInsertWord", ".dict", getContext().getCacheDir());
|
||||
file = File.createTempFile("testInsertWord", TEST_DICT_FILE_EXTENSION,
|
||||
getContext().getCacheDir());
|
||||
} catch (IOException e) {
|
||||
fail("IOException while creating temporary file: " + e);
|
||||
}
|
||||
|
@ -284,7 +287,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
|
|||
public void testInsertWordWithBigrams() {
|
||||
File file = null;
|
||||
try {
|
||||
file = File.createTempFile("testInsertWordWithBigrams", ".dict",
|
||||
file = File.createTempFile("testInsertWordWithBigrams", TEST_DICT_FILE_EXTENSION,
|
||||
getContext().getCacheDir());
|
||||
} catch (IOException e) {
|
||||
fail("IOException while creating temporary file: " + e);
|
||||
|
@ -322,7 +325,8 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
|
|||
public void testRandomWords() {
|
||||
File file = null;
|
||||
try {
|
||||
file = File.createTempFile("testRandomWord", ".dict", getContext().getCacheDir());
|
||||
file = File.createTempFile("testRandomWord", TEST_DICT_FILE_EXTENSION,
|
||||
getContext().getCacheDir());
|
||||
} catch (IOException e) {
|
||||
}
|
||||
assertNotNull(file);
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.test.AndroidTestCase;
|
|||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
|
||||
import com.android.inputmethod.latin.utils.CollectionUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -81,12 +82,12 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
private void addAndWriteRandomWords(final String locale, final int numberOfWords,
|
||||
private void addAndWriteRandomWords(final String testFilenameSuffix, final int numberOfWords,
|
||||
final Random random) {
|
||||
final List<String> words = generateWords(numberOfWords, random);
|
||||
final UserHistoryPredictionDictionary dict =
|
||||
PersonalizationDictionaryHelper.getUserHistoryPredictionDictionary(getContext(),
|
||||
locale, mPrefs);
|
||||
testFilenameSuffix /* locale */, mPrefs);
|
||||
// Add random words to the user history dictionary.
|
||||
addToDict(dict, words);
|
||||
// write to file.
|
||||
|
@ -97,12 +98,12 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
|||
File dictFile = null;
|
||||
Log.d(TAG, "This test can be used for profiling.");
|
||||
Log.d(TAG, "Usage: please set UserHistoryDictionary.PROFILE_SAVE_RESTORE to true.");
|
||||
final String locale = "testRandomWords" + System.currentTimeMillis();
|
||||
final String testFilenameSuffix = "testRandomWords" + System.currentTimeMillis();
|
||||
final int numberOfWords = 1000;
|
||||
final Random random = new Random(123456);
|
||||
|
||||
try {
|
||||
addAndWriteRandomWords(locale, numberOfWords, random);
|
||||
addAndWriteRandomWords(testFilenameSuffix, numberOfWords, random);
|
||||
} finally {
|
||||
try {
|
||||
Log.d(TAG, "waiting for writing ...");
|
||||
|
@ -111,7 +112,8 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
|||
Log.d(TAG, "InterruptedException: " + e);
|
||||
}
|
||||
|
||||
final String fileName = UserHistoryPredictionDictionary.NAME + "." + locale + ".dict";
|
||||
final String fileName = UserHistoryPredictionDictionary.NAME + "." + testFilenameSuffix
|
||||
+ ExpandableBinaryDictionary.DICT_FILE_EXTENSION;
|
||||
dictFile = new File(getContext().getFilesDir(), fileName);
|
||||
|
||||
if (dictFile != null) {
|
||||
|
@ -135,8 +137,8 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
|||
String testFilenameSuffixes[] = new String[numberOfLanguages];
|
||||
for (int i = 0; i < numberOfLanguages; i++) {
|
||||
testFilenameSuffixes[i] = "testSwitchingLanguages" + i;
|
||||
final String fileName = "UserHistoryDictionary." + testFilenameSuffixes[i]
|
||||
+ ".dict";
|
||||
final String fileName = UserHistoryPredictionDictionary.NAME + "." +
|
||||
testFilenameSuffixes[i] + ExpandableBinaryDictionary.DICT_FILE_EXTENSION;
|
||||
dictFiles[i] = new File(getContext().getFilesDir(), fileName);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ public class UserHistoryDictIOUtilsTests extends AndroidTestCase
|
|||
private static final int BIGRAM_FREQUENCY = 100;
|
||||
private static final ArrayList<String> NOT_HAVE_BIGRAM = new ArrayList<String>();
|
||||
private static final FormatSpec.FormatOptions FORMAT_OPTIONS = new FormatSpec.FormatOptions(2);
|
||||
private static final String TEST_DICT_FILE_EXTENSION = ".testDict";
|
||||
|
||||
/**
|
||||
* Return same frequency for all words and bigrams
|
||||
|
@ -177,7 +178,8 @@ public class UserHistoryDictIOUtilsTests extends AndroidTestCase
|
|||
|
||||
File file = null;
|
||||
try {
|
||||
file = File.createTempFile("testReadAndWrite", ".dict", getContext().getCacheDir());
|
||||
file = File.createTempFile("testReadAndWrite", TEST_DICT_FILE_EXTENSION,
|
||||
getContext().getCacheDir());
|
||||
} catch (IOException e) {
|
||||
Log.d(TAG, "IOException while creating a temporary file", e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue