am 1cf4789b: Merge "Set header attributes for ExpandableBinaryDictionary."
* commit '1cf4789ba6abb5855392d542bb075c12d2d9b6a0': Set header attributes for ExpandableBinaryDictionary.main
commit
f2800fc6f4
|
@ -25,6 +25,7 @@ import com.android.inputmethod.latin.makedict.Ver3DictEncoder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
// TODO: Quit extending Dictionary after implementing dynamic binary dictionary.
|
// TODO: Quit extending Dictionary after implementing dynamic binary dictionary.
|
||||||
abstract public class AbstractDictionaryWriter extends Dictionary {
|
abstract public class AbstractDictionaryWriter extends Dictionary {
|
||||||
|
@ -50,16 +51,16 @@ abstract public class AbstractDictionaryWriter extends Dictionary {
|
||||||
|
|
||||||
abstract public void removeBigramWords(final String word0, final String word1);
|
abstract public void removeBigramWords(final String word0, final String word1);
|
||||||
|
|
||||||
abstract protected void writeDictionary(final DictEncoder dictEncoder)
|
abstract protected void writeDictionary(final DictEncoder dictEncoder,
|
||||||
throws IOException, UnsupportedFormatException;
|
final Map<String, String> attributeMap) throws IOException, UnsupportedFormatException;
|
||||||
|
|
||||||
public void write(final String fileName) {
|
public void write(final String fileName, final Map<String, String> attributeMap) {
|
||||||
final String tempFileName = fileName + ".temp";
|
final String tempFileName = fileName + ".temp";
|
||||||
final File file = new File(mContext.getFilesDir(), fileName);
|
final File file = new File(mContext.getFilesDir(), fileName);
|
||||||
final File tempFile = new File(mContext.getFilesDir(), tempFileName);
|
final File tempFile = new File(mContext.getFilesDir(), tempFileName);
|
||||||
try {
|
try {
|
||||||
final DictEncoder dictEncoder = new Ver3DictEncoder(tempFile);
|
final DictEncoder dictEncoder = new Ver3DictEncoder(tempFile);
|
||||||
writeDictionary(dictEncoder);
|
writeDictionary(dictEncoder, attributeMap);
|
||||||
tempFile.renameTo(file);
|
tempFile.renameTo(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "IO exception while writing file", e);
|
Log.e(TAG, "IO exception while writing file", e);
|
||||||
|
|
|
@ -31,6 +31,7 @@ import com.android.inputmethod.latin.utils.CollectionUtils;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An in memory dictionary for memorizing entries and writing a binary dictionary.
|
* An in memory dictionary for memorizing entries and writing a binary dictionary.
|
||||||
|
@ -84,8 +85,11 @@ public class DictionaryWriter extends AbstractDictionaryWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeDictionary(final DictEncoder dictEncoder)
|
protected void writeDictionary(final DictEncoder dictEncoder,
|
||||||
throws IOException, UnsupportedFormatException {
|
final Map<String, String> attributeMap) throws IOException, UnsupportedFormatException {
|
||||||
|
for (final Map.Entry<String, String> entry : attributeMap.entrySet()) {
|
||||||
|
mFusionDictionary.addOptionAttribute(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
dictEncoder.writeDictionary(mFusionDictionary, FORMAT_OPTIONS);
|
dictEncoder.writeDictionary(mFusionDictionary, FORMAT_OPTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -236,6 +236,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
HashMap<String, String> attributeMap = new HashMap<String, String>();
|
HashMap<String, String> attributeMap = new HashMap<String, String>();
|
||||||
attributeMap.put(FormatSpec.FileHeader.SUPPORTS_DYNAMIC_UPDATE_ATTRIBUTE,
|
attributeMap.put(FormatSpec.FileHeader.SUPPORTS_DYNAMIC_UPDATE_ATTRIBUTE,
|
||||||
SUPPORTS_DYNAMIC_UPDATE);
|
SUPPORTS_DYNAMIC_UPDATE);
|
||||||
|
attributeMap.put(FormatSpec.FileHeader.DICTIONARY_ID_ATTRIBUTE, mFilename);
|
||||||
return attributeMap;
|
return attributeMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,7 +497,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
if (needsToReloadBeforeWriting()) {
|
if (needsToReloadBeforeWriting()) {
|
||||||
mDictionaryWriter.clear();
|
mDictionaryWriter.clear();
|
||||||
loadDictionaryAsync();
|
loadDictionaryAsync();
|
||||||
mDictionaryWriter.write(mFilename);
|
mDictionaryWriter.write(mFilename, getHeaderAttributeMap());
|
||||||
} else {
|
} else {
|
||||||
if (ENABLE_BINARY_DICTIONARY_DYNAMIC_UPDATE) {
|
if (ENABLE_BINARY_DICTIONARY_DYNAMIC_UPDATE) {
|
||||||
if (mBinaryDictionary == null || !mBinaryDictionary.isValidDictionary()) {
|
if (mBinaryDictionary == null || !mBinaryDictionary.isValidDictionary()) {
|
||||||
|
@ -511,7 +512,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mDictionaryWriter.write(mFilename);
|
mDictionaryWriter.write(mFilename, getHeaderAttributeMap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ import com.android.inputmethod.latin.personalization.PersonalizationDictionary;
|
||||||
import com.android.inputmethod.latin.personalization.PersonalizationDictionarySessionRegister;
|
import com.android.inputmethod.latin.personalization.PersonalizationDictionarySessionRegister;
|
||||||
import com.android.inputmethod.latin.personalization.PersonalizationHelper;
|
import com.android.inputmethod.latin.personalization.PersonalizationHelper;
|
||||||
import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary;
|
import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary;
|
||||||
import com.android.inputmethod.latin.personalization.UserHistoryPredictionDictionary;
|
import com.android.inputmethod.latin.personalization.UserHistoryDictionary;
|
||||||
import com.android.inputmethod.latin.settings.Settings;
|
import com.android.inputmethod.latin.settings.Settings;
|
||||||
import com.android.inputmethod.latin.settings.SettingsActivity;
|
import com.android.inputmethod.latin.settings.SettingsActivity;
|
||||||
import com.android.inputmethod.latin.settings.SettingsValues;
|
import com.android.inputmethod.latin.settings.SettingsValues;
|
||||||
|
@ -179,7 +179,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
|
|
||||||
private boolean mIsMainDictionaryAvailable;
|
private boolean mIsMainDictionaryAvailable;
|
||||||
private UserBinaryDictionary mUserDictionary;
|
private UserBinaryDictionary mUserDictionary;
|
||||||
private UserHistoryPredictionDictionary mUserHistoryPredictionDictionary;
|
private UserHistoryDictionary mUserHistoryDictionary;
|
||||||
private PersonalizationPredictionDictionary mPersonalizationPredictionDictionary;
|
private PersonalizationPredictionDictionary mPersonalizationPredictionDictionary;
|
||||||
private PersonalizationDictionary mPersonalizationDictionary;
|
private PersonalizationDictionary mPersonalizationDictionary;
|
||||||
private boolean mIsUserDictionaryAvailable;
|
private boolean mIsUserDictionaryAvailable;
|
||||||
|
@ -623,9 +623,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
|
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
mUserHistoryPredictionDictionary = PersonalizationHelper
|
mUserHistoryDictionary = PersonalizationHelper.getUserHistoryDictionary(
|
||||||
.getUserHistoryPredictionDictionary(this, localeStr, prefs);
|
this, localeStr, prefs);
|
||||||
newSuggest.setUserHistoryPredictionDictionary(mUserHistoryPredictionDictionary);
|
newSuggest.setUserHistoryDictionary(mUserHistoryDictionary);
|
||||||
mPersonalizationDictionary = PersonalizationHelper
|
mPersonalizationDictionary = PersonalizationHelper
|
||||||
.getPersonalizationDictionary(this, localeStr, prefs);
|
.getPersonalizationDictionary(this, localeStr, prefs);
|
||||||
newSuggest.setPersonalizationDictionary(mPersonalizationDictionary);
|
newSuggest.setPersonalizationDictionary(mPersonalizationDictionary);
|
||||||
|
@ -2750,9 +2750,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
final SettingsValues currentSettings = mSettings.getCurrent();
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
||||||
if (!currentSettings.mCorrectionEnabled) return null;
|
if (!currentSettings.mCorrectionEnabled) return null;
|
||||||
|
|
||||||
final UserHistoryPredictionDictionary userHistoryPredictionDictionary =
|
final UserHistoryDictionary userHistoryDictionary = mUserHistoryDictionary;
|
||||||
mUserHistoryPredictionDictionary;
|
if (userHistoryDictionary == null) return null;
|
||||||
if (userHistoryPredictionDictionary == null) return null;
|
|
||||||
|
|
||||||
final String prevWord = mConnection.getNthPreviousWord(currentSettings.mWordSeparators, 2);
|
final String prevWord = mConnection.getNthPreviousWord(currentSettings.mWordSeparators, 2);
|
||||||
final String secondWord;
|
final String secondWord;
|
||||||
|
@ -2766,8 +2765,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
final int maxFreq = AutoCorrectionUtils.getMaxFrequency(
|
final int maxFreq = AutoCorrectionUtils.getMaxFrequency(
|
||||||
suggest.getUnigramDictionaries(), suggestion);
|
suggest.getUnigramDictionaries(), suggestion);
|
||||||
if (maxFreq == 0) return null;
|
if (maxFreq == 0) return null;
|
||||||
userHistoryPredictionDictionary
|
userHistoryDictionary.addToDictionary(prevWord, secondWord, maxFreq > 0);
|
||||||
.addToPersonalizationPredictionDictionary(prevWord, secondWord, maxFreq > 0);
|
|
||||||
return prevWord;
|
return prevWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2953,7 +2951,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
mConnection.deleteSurroundingText(deleteLength, 0);
|
mConnection.deleteSurroundingText(deleteLength, 0);
|
||||||
if (!TextUtils.isEmpty(previousWord) && !TextUtils.isEmpty(committedWord)) {
|
if (!TextUtils.isEmpty(previousWord) && !TextUtils.isEmpty(committedWord)) {
|
||||||
mUserHistoryPredictionDictionary.cancelAddingUserHistory(previousWord, committedWord);
|
mUserHistoryDictionary.cancelAddingUserHistory(previousWord, committedWord);
|
||||||
}
|
}
|
||||||
final String stringToCommit = originallyTypedWord + mLastComposedWord.mSeparatorString;
|
final String stringToCommit = originallyTypedWord + mLastComposedWord.mSeparatorString;
|
||||||
if (mSettings.getCurrent().mCurrentLanguageHasSpaces) {
|
if (mSettings.getCurrent().mCurrentLanguageHasSpaces) {
|
||||||
|
|
|
@ -26,7 +26,7 @@ import com.android.inputmethod.keyboard.ProximityInfo;
|
||||||
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
||||||
import com.android.inputmethod.latin.personalization.PersonalizationDictionary;
|
import com.android.inputmethod.latin.personalization.PersonalizationDictionary;
|
||||||
import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary;
|
import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary;
|
||||||
import com.android.inputmethod.latin.personalization.UserHistoryPredictionDictionary;
|
import com.android.inputmethod.latin.personalization.UserHistoryDictionary;
|
||||||
import com.android.inputmethod.latin.settings.Settings;
|
import com.android.inputmethod.latin.settings.Settings;
|
||||||
import com.android.inputmethod.latin.utils.AutoCorrectionUtils;
|
import com.android.inputmethod.latin.utils.AutoCorrectionUtils;
|
||||||
import com.android.inputmethod.latin.utils.BoundedTreeSet;
|
import com.android.inputmethod.latin.utils.BoundedTreeSet;
|
||||||
|
@ -190,10 +190,8 @@ public final class Suggest {
|
||||||
addOrReplaceDictionaryInternal(Dictionary.TYPE_CONTACTS, contactsDictionary);
|
addOrReplaceDictionaryInternal(Dictionary.TYPE_CONTACTS, contactsDictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserHistoryPredictionDictionary(
|
public void setUserHistoryDictionary(final UserHistoryDictionary userHistoryDictionary) {
|
||||||
final UserHistoryPredictionDictionary userHistoryPredictionDictionary) {
|
addOrReplaceDictionaryInternal(Dictionary.TYPE_USER_HISTORY, userHistoryDictionary);
|
||||||
addOrReplaceDictionaryInternal(Dictionary.TYPE_USER_HISTORY,
|
|
||||||
userHistoryPredictionDictionary);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPersonalizationPredictionDictionary(
|
public void setPersonalizationPredictionDictionary(
|
||||||
|
|
|
@ -331,9 +331,9 @@ public final class FormatSpec {
|
||||||
public static final String USES_FORGETTING_CURVE_ATTRIBUTE = "USES_FORGETTING_CURVE";
|
public static final String USES_FORGETTING_CURVE_ATTRIBUTE = "USES_FORGETTING_CURVE";
|
||||||
public static final String ATTRIBUTE_VALUE_TRUE = "1";
|
public static final String ATTRIBUTE_VALUE_TRUE = "1";
|
||||||
|
|
||||||
private static final String DICTIONARY_VERSION_ATTRIBUTE = "version";
|
public static final String DICTIONARY_VERSION_ATTRIBUTE = "version";
|
||||||
private static final String DICTIONARY_LOCALE_ATTRIBUTE = "locale";
|
public static final String DICTIONARY_LOCALE_ATTRIBUTE = "locale";
|
||||||
private static final String DICTIONARY_ID_ATTRIBUTE = "dictionary";
|
public static final String DICTIONARY_ID_ATTRIBUTE = "dictionary";
|
||||||
private static final String DICTIONARY_DESCRIPTION_ATTRIBUTE = "description";
|
private static final String DICTIONARY_DESCRIPTION_ATTRIBUTE = "description";
|
||||||
public FileHeader(final int headerSize, final DictionaryOptions dictionaryOptions,
|
public FileHeader(final int headerSize, final DictionaryOptions dictionaryOptions,
|
||||||
final FormatOptions formatOptions) {
|
final FormatOptions formatOptions) {
|
||||||
|
|
|
@ -94,6 +94,8 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
|
||||||
FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE);
|
FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE);
|
||||||
attributeMap.put(FormatSpec.FileHeader.USES_FORGETTING_CURVE_ATTRIBUTE,
|
attributeMap.put(FormatSpec.FileHeader.USES_FORGETTING_CURVE_ATTRIBUTE,
|
||||||
FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE);
|
FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE);
|
||||||
|
attributeMap.put(FormatSpec.FileHeader.DICTIONARY_ID_ATTRIBUTE, mFileName);
|
||||||
|
attributeMap.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_ATTRIBUTE, mLocale);
|
||||||
return attributeMap;
|
return attributeMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,15 +119,14 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pair will be added to the personalization prediction dictionary.
|
* Pair will be added to the decaying dictionary.
|
||||||
*
|
*
|
||||||
* The first word may be null. That means we don't know the context, in other words,
|
* The first word may be null. That means we don't know the context, in other words,
|
||||||
* it's only a unigram. The first word may also be an empty string : this means start
|
* it's only a unigram. The first word may also be an empty string : this means start
|
||||||
* context, as in beginning of a sentence for example.
|
* context, as in beginning of a sentence for example.
|
||||||
* The second word may not be null (a NullPointerException would be thrown).
|
* The second word may not be null (a NullPointerException would be thrown).
|
||||||
*/
|
*/
|
||||||
public void addToPersonalizationPredictionDictionary(
|
public void addToDictionary(final String word0, final String word1, final boolean isValid) {
|
||||||
final String word0, final String word1, final boolean isValid) {
|
|
||||||
if (word1.length() >= Constants.DICTIONARY_MAX_WORD_LENGTH ||
|
if (word1.length() >= Constants.DICTIONARY_MAX_WORD_LENGTH ||
|
||||||
(word0 != null && word0.length() >= Constants.DICTIONARY_MAX_WORD_LENGTH)) {
|
(word0 != null && word0.length() >= Constants.DICTIONARY_MAX_WORD_LENGTH)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -36,6 +36,7 @@ import com.android.inputmethod.latin.utils.UserHistoryForgettingCurveUtils.Forge
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
// Currently this class is used to implement dynamic prodiction dictionary.
|
// Currently this class is used to implement dynamic prodiction dictionary.
|
||||||
// TODO: Move to native code.
|
// TODO: Move to native code.
|
||||||
|
@ -113,8 +114,8 @@ public class DynamicPersonalizationDictionaryWriter extends AbstractDictionaryWr
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeDictionary(final DictEncoder dictEncoder)
|
protected void writeDictionary(final DictEncoder dictEncoder,
|
||||||
throws IOException, UnsupportedFormatException {
|
final Map<String, String> attributeMap) throws IOException, UnsupportedFormatException {
|
||||||
UserHistoryDictIOUtils.writeDictionary(dictEncoder,
|
UserHistoryDictIOUtils.writeDictionary(dictEncoder,
|
||||||
new FrequencyProvider(mBigramList, mExpandableDictionary, mMaxHistoryBigrams),
|
new FrequencyProvider(mBigramList, mExpandableDictionary, mMaxHistoryBigrams),
|
||||||
mBigramList, FORMAT_OPTIONS);
|
mBigramList, FORMAT_OPTIONS);
|
||||||
|
|
|
@ -110,7 +110,7 @@ public abstract class PersonalizationDictionaryUpdateSession {
|
||||||
if (dictionary == null) {
|
if (dictionary == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dictionary.addToPersonalizationPredictionDictionary(word0, word1, isValid);
|
dictionary.addToDictionary(word0, word1, isValid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bulk import
|
// Bulk import
|
||||||
|
@ -122,8 +122,7 @@ public abstract class PersonalizationDictionaryUpdateSession {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (final PersonalizationLanguageModelParam lmParam : lmParams) {
|
for (final PersonalizationLanguageModelParam lmParam : lmParams) {
|
||||||
dictionary.addToPersonalizationPredictionDictionary(
|
dictionary.addToDictionary(lmParam.mWord0, lmParam.mWord1, lmParam.mIsValid);
|
||||||
lmParam.mWord0, lmParam.mWord1, lmParam.mIsValid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class PersonalizationHelper {
|
||||||
private static final String TAG = PersonalizationHelper.class.getSimpleName();
|
private static final String TAG = PersonalizationHelper.class.getSimpleName();
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
private static final ConcurrentHashMap<String, SoftReference<UserHistoryPredictionDictionary>>
|
private static final ConcurrentHashMap<String, SoftReference<UserHistoryDictionary>>
|
||||||
sLangUserHistoryDictCache = CollectionUtils.newConcurrentHashMap();
|
sLangUserHistoryDictCache = CollectionUtils.newConcurrentHashMap();
|
||||||
|
|
||||||
private static final ConcurrentHashMap<String, SoftReference<PersonalizationDictionary>>
|
private static final ConcurrentHashMap<String, SoftReference<PersonalizationDictionary>>
|
||||||
|
@ -41,25 +41,23 @@ public class PersonalizationHelper {
|
||||||
sLangPersonalizationPredictionDictCache =
|
sLangPersonalizationPredictionDictCache =
|
||||||
CollectionUtils.newConcurrentHashMap();
|
CollectionUtils.newConcurrentHashMap();
|
||||||
|
|
||||||
public static UserHistoryPredictionDictionary getUserHistoryPredictionDictionary(
|
public static UserHistoryDictionary getUserHistoryDictionary(
|
||||||
final Context context, final String locale, final SharedPreferences sp) {
|
final Context context, final String locale, final SharedPreferences sp) {
|
||||||
synchronized (sLangUserHistoryDictCache) {
|
synchronized (sLangUserHistoryDictCache) {
|
||||||
if (sLangUserHistoryDictCache.containsKey(locale)) {
|
if (sLangUserHistoryDictCache.containsKey(locale)) {
|
||||||
final SoftReference<UserHistoryPredictionDictionary> ref =
|
final SoftReference<UserHistoryDictionary> ref =
|
||||||
sLangUserHistoryDictCache.get(locale);
|
sLangUserHistoryDictCache.get(locale);
|
||||||
final UserHistoryPredictionDictionary dict = ref == null ? null : ref.get();
|
final UserHistoryDictionary dict = ref == null ? null : ref.get();
|
||||||
if (dict != null) {
|
if (dict != null) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.w(TAG, "Use cached UserHistoryPredictionDictionary for " + locale);
|
Log.w(TAG, "Use cached UserHistoryDictionary for " + locale);
|
||||||
}
|
}
|
||||||
dict.reloadDictionaryIfRequired();
|
dict.reloadDictionaryIfRequired();
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final UserHistoryPredictionDictionary dict =
|
final UserHistoryDictionary dict = new UserHistoryDictionary(context, locale, sp);
|
||||||
new UserHistoryPredictionDictionary(context, locale, sp);
|
sLangUserHistoryDictCache.put(locale, new SoftReference<UserHistoryDictionary>(dict));
|
||||||
sLangUserHistoryDictCache.put(
|
|
||||||
locale, new SoftReference<UserHistoryPredictionDictionary>(dict));
|
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,10 @@ import android.content.SharedPreferences;
|
||||||
* Locally gathers stats about the words user types and various other signals like auto-correction
|
* Locally gathers stats about the words user types and various other signals like auto-correction
|
||||||
* cancellation or manual picks. This allows the keyboard to adapt to the typist over time.
|
* cancellation or manual picks. This allows the keyboard to adapt to the typist over time.
|
||||||
*/
|
*/
|
||||||
public class UserHistoryPredictionDictionary extends DecayingExpandableBinaryDictionaryBase {
|
public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBase {
|
||||||
/* package for tests */ static final String NAME =
|
/* package for tests */ static final String NAME =
|
||||||
UserHistoryPredictionDictionary.class.getSimpleName();
|
UserHistoryDictionary.class.getSimpleName();
|
||||||
/* package */ UserHistoryPredictionDictionary(final Context context, final String locale,
|
/* package */ UserHistoryDictionary(final Context context, final String locale,
|
||||||
final SharedPreferences sp) {
|
final SharedPreferences sp) {
|
||||||
super(context, locale, sp, Dictionary.TYPE_USER_HISTORY, getDictionaryFileName(locale));
|
super(context, locale, sp, Dictionary.TYPE_USER_HISTORY, getDictionaryFileName(locale));
|
||||||
}
|
}
|
|
@ -33,6 +33,8 @@
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
const int Dictionary::HEADER_ATTRIBUTE_BUFFER_SIZE = 32;
|
||||||
|
|
||||||
Dictionary::Dictionary(JNIEnv *env,
|
Dictionary::Dictionary(JNIEnv *env,
|
||||||
DictionaryStructureWithBufferPolicy *const dictionaryStructureWithBufferPolicy)
|
DictionaryStructureWithBufferPolicy *const dictionaryStructureWithBufferPolicy)
|
||||||
: mDictionaryStructureWithBufferPolicy(dictionaryStructureWithBufferPolicy),
|
: mDictionaryStructureWithBufferPolicy(dictionaryStructureWithBufferPolicy),
|
||||||
|
@ -131,27 +133,27 @@ void Dictionary::getProperty(const char *const query, char *const outResult,
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dictionary::logDictionaryInfo(JNIEnv *const env) const {
|
void Dictionary::logDictionaryInfo(JNIEnv *const env) const {
|
||||||
const int BUFFER_SIZE = 16;
|
int dictionaryIdCodePointBuffer[HEADER_ATTRIBUTE_BUFFER_SIZE];
|
||||||
int dictionaryIdCodePointBuffer[BUFFER_SIZE];
|
int versionStringCodePointBuffer[HEADER_ATTRIBUTE_BUFFER_SIZE];
|
||||||
int versionStringCodePointBuffer[BUFFER_SIZE];
|
int dateStringCodePointBuffer[HEADER_ATTRIBUTE_BUFFER_SIZE];
|
||||||
int dateStringCodePointBuffer[BUFFER_SIZE];
|
|
||||||
const DictionaryHeaderStructurePolicy *const headerPolicy =
|
const DictionaryHeaderStructurePolicy *const headerPolicy =
|
||||||
getDictionaryStructurePolicy()->getHeaderStructurePolicy();
|
getDictionaryStructurePolicy()->getHeaderStructurePolicy();
|
||||||
headerPolicy->readHeaderValueOrQuestionMark("dictionary", dictionaryIdCodePointBuffer,
|
headerPolicy->readHeaderValueOrQuestionMark("dictionary", dictionaryIdCodePointBuffer,
|
||||||
BUFFER_SIZE);
|
HEADER_ATTRIBUTE_BUFFER_SIZE);
|
||||||
headerPolicy->readHeaderValueOrQuestionMark("version", versionStringCodePointBuffer,
|
headerPolicy->readHeaderValueOrQuestionMark("version", versionStringCodePointBuffer,
|
||||||
BUFFER_SIZE);
|
HEADER_ATTRIBUTE_BUFFER_SIZE);
|
||||||
headerPolicy->readHeaderValueOrQuestionMark("date", dateStringCodePointBuffer, BUFFER_SIZE);
|
headerPolicy->readHeaderValueOrQuestionMark("date", dateStringCodePointBuffer,
|
||||||
|
HEADER_ATTRIBUTE_BUFFER_SIZE);
|
||||||
|
|
||||||
char dictionaryIdCharBuffer[BUFFER_SIZE];
|
char dictionaryIdCharBuffer[HEADER_ATTRIBUTE_BUFFER_SIZE];
|
||||||
char versionStringCharBuffer[BUFFER_SIZE];
|
char versionStringCharBuffer[HEADER_ATTRIBUTE_BUFFER_SIZE];
|
||||||
char dateStringCharBuffer[BUFFER_SIZE];
|
char dateStringCharBuffer[HEADER_ATTRIBUTE_BUFFER_SIZE];
|
||||||
intArrayToCharArray(dictionaryIdCodePointBuffer, BUFFER_SIZE,
|
intArrayToCharArray(dictionaryIdCodePointBuffer, HEADER_ATTRIBUTE_BUFFER_SIZE,
|
||||||
dictionaryIdCharBuffer, BUFFER_SIZE);
|
dictionaryIdCharBuffer, HEADER_ATTRIBUTE_BUFFER_SIZE);
|
||||||
intArrayToCharArray(versionStringCodePointBuffer, BUFFER_SIZE,
|
intArrayToCharArray(versionStringCodePointBuffer, HEADER_ATTRIBUTE_BUFFER_SIZE,
|
||||||
versionStringCharBuffer, BUFFER_SIZE);
|
versionStringCharBuffer, HEADER_ATTRIBUTE_BUFFER_SIZE);
|
||||||
intArrayToCharArray(dateStringCodePointBuffer, BUFFER_SIZE,
|
intArrayToCharArray(dateStringCodePointBuffer, HEADER_ATTRIBUTE_BUFFER_SIZE,
|
||||||
dateStringCharBuffer, BUFFER_SIZE);
|
dateStringCharBuffer, HEADER_ATTRIBUTE_BUFFER_SIZE);
|
||||||
|
|
||||||
LogUtils::logToJava(env,
|
LogUtils::logToJava(env,
|
||||||
"Dictionary info: dictionary = %s ; version = %s ; date = %s",
|
"Dictionary info: dictionary = %s ; version = %s ; date = %s",
|
||||||
|
|
|
@ -95,6 +95,8 @@ class Dictionary {
|
||||||
private:
|
private:
|
||||||
DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary);
|
DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary);
|
||||||
|
|
||||||
|
static const int HEADER_ATTRIBUTE_BUFFER_SIZE;
|
||||||
|
|
||||||
DictionaryStructureWithBufferPolicy *const mDictionaryStructureWithBufferPolicy;
|
DictionaryStructureWithBufferPolicy *const mDictionaryStructureWithBufferPolicy;
|
||||||
const BigramDictionary *const mBigramDictionary;
|
const BigramDictionary *const mBigramDictionary;
|
||||||
const SuggestInterface *const mGestureSuggest;
|
const SuggestInterface *const mGestureSuggest;
|
||||||
|
|
|
@ -75,10 +75,10 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
return new ArrayList<String>(wordSet);
|
return new ArrayList<String>(wordSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToDict(final UserHistoryPredictionDictionary dict, final List<String> words) {
|
private void addToDict(final UserHistoryDictionary dict, final List<String> words) {
|
||||||
String prevWord = null;
|
String prevWord = null;
|
||||||
for (String word : words) {
|
for (String word : words) {
|
||||||
dict.addToPersonalizationPredictionDictionary(prevWord, word, true);
|
dict.addToDictionary(prevWord, word, true);
|
||||||
prevWord = word;
|
prevWord = word;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,8 +90,8 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
private void addAndWriteRandomWords(final String testFilenameSuffix, final int numberOfWords,
|
private void addAndWriteRandomWords(final String testFilenameSuffix, final int numberOfWords,
|
||||||
final Random random, final boolean checkContents) {
|
final Random random, final boolean checkContents) {
|
||||||
final List<String> words = generateWords(numberOfWords, random);
|
final List<String> words = generateWords(numberOfWords, random);
|
||||||
final UserHistoryPredictionDictionary dict =
|
final UserHistoryDictionary dict =
|
||||||
PersonalizationHelper.getUserHistoryPredictionDictionary(getContext(),
|
PersonalizationHelper.getUserHistoryDictionary(getContext(),
|
||||||
testFilenameSuffix /* locale */, mPrefs);
|
testFilenameSuffix /* locale */, mPrefs);
|
||||||
// Add random words to the user history dictionary.
|
// Add random words to the user history dictionary.
|
||||||
addToDict(dict, words);
|
addToDict(dict, words);
|
||||||
|
@ -122,8 +122,8 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
true /* checksContents */);
|
true /* checksContents */);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
final UserHistoryPredictionDictionary dict =
|
final UserHistoryDictionary dict =
|
||||||
PersonalizationHelper.getUserHistoryPredictionDictionary(getContext(),
|
PersonalizationHelper.getUserHistoryDictionary(getContext(),
|
||||||
testFilenameSuffix, mPrefs);
|
testFilenameSuffix, mPrefs);
|
||||||
Log.d(TAG, "waiting for writing ...");
|
Log.d(TAG, "waiting for writing ...");
|
||||||
dict.shutdownExecutorForTests();
|
dict.shutdownExecutorForTests();
|
||||||
|
@ -134,7 +134,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
Log.d(TAG, "InterruptedException: " + e);
|
Log.d(TAG, "InterruptedException: " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String fileName = UserHistoryPredictionDictionary.NAME + "." + testFilenameSuffix
|
final String fileName = UserHistoryDictionary.NAME + "." + testFilenameSuffix
|
||||||
+ ExpandableBinaryDictionary.DICT_FILE_EXTENSION;
|
+ ExpandableBinaryDictionary.DICT_FILE_EXTENSION;
|
||||||
dictFile = new File(getContext().getFilesDir(), fileName);
|
dictFile = new File(getContext().getFilesDir(), fileName);
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
// Create filename suffixes for this test.
|
// Create filename suffixes for this test.
|
||||||
for (int i = 0; i < numberOfLanguages; i++) {
|
for (int i = 0; i < numberOfLanguages; i++) {
|
||||||
testFilenameSuffixes[i] = "testSwitchingLanguages" + i;
|
testFilenameSuffixes[i] = "testSwitchingLanguages" + i;
|
||||||
final String fileName = UserHistoryPredictionDictionary.NAME + "." +
|
final String fileName = UserHistoryDictionary.NAME + "." +
|
||||||
testFilenameSuffixes[i] + ExpandableBinaryDictionary.DICT_FILE_EXTENSION;
|
testFilenameSuffixes[i] + ExpandableBinaryDictionary.DICT_FILE_EXTENSION;
|
||||||
dictFiles[i] = new File(getContext().getFilesDir(), fileName);
|
dictFiles[i] = new File(getContext().getFilesDir(), fileName);
|
||||||
}
|
}
|
||||||
|
@ -181,8 +181,8 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
try {
|
try {
|
||||||
Log.d(TAG, "waiting for writing ...");
|
Log.d(TAG, "waiting for writing ...");
|
||||||
for (int i = 0; i < numberOfLanguages; i++) {
|
for (int i = 0; i < numberOfLanguages; i++) {
|
||||||
final UserHistoryPredictionDictionary dict =
|
final UserHistoryDictionary dict =
|
||||||
PersonalizationHelper.getUserHistoryPredictionDictionary(getContext(),
|
PersonalizationHelper.getUserHistoryDictionary(getContext(),
|
||||||
testFilenameSuffixes[i], mPrefs);
|
testFilenameSuffixes[i], mPrefs);
|
||||||
dict.shutdownExecutorForTests();
|
dict.shutdownExecutorForTests();
|
||||||
while (!dict.isTerminatedForTests()) {
|
while (!dict.isTerminatedForTests()) {
|
||||||
|
@ -210,8 +210,8 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
10000 : 1000;
|
10000 : 1000;
|
||||||
final Random random = new Random(123456);
|
final Random random = new Random(123456);
|
||||||
|
|
||||||
UserHistoryPredictionDictionary dict =
|
UserHistoryDictionary dict =
|
||||||
PersonalizationHelper.getUserHistoryPredictionDictionary(getContext(),
|
PersonalizationHelper.getUserHistoryDictionary(getContext(),
|
||||||
testFilenameSuffix, mPrefs);
|
testFilenameSuffix, mPrefs);
|
||||||
try {
|
try {
|
||||||
addAndWriteRandomWords(testFilenameSuffix, numberOfWords, random,
|
addAndWriteRandomWords(testFilenameSuffix, numberOfWords, random,
|
||||||
|
@ -227,7 +227,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Log.d(TAG, "InterruptedException: ", e);
|
Log.d(TAG, "InterruptedException: ", e);
|
||||||
}
|
}
|
||||||
final String fileName = UserHistoryPredictionDictionary.NAME + "." + testFilenameSuffix
|
final String fileName = UserHistoryDictionary.NAME + "." + testFilenameSuffix
|
||||||
+ ExpandableBinaryDictionary.DICT_FILE_EXTENSION;
|
+ ExpandableBinaryDictionary.DICT_FILE_EXTENSION;
|
||||||
dictFile = new File(getContext().getFilesDir(), fileName);
|
dictFile = new File(getContext().getFilesDir(), fileName);
|
||||||
if (dictFile != null) {
|
if (dictFile != null) {
|
||||||
|
|
Loading…
Reference in New Issue