2013-07-26 05:38:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin.personalization;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2013-07-31 05:42:50 +00:00
|
|
|
|
2013-09-30 11:53:35 +00:00
|
|
|
import com.android.inputmethod.latin.Dictionary;
|
2013-08-26 09:50:22 +00:00
|
|
|
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
|
2014-02-04 12:36:04 +00:00
|
|
|
import com.android.inputmethod.latin.makedict.DictionaryHeader;
|
2013-07-31 05:42:50 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
2013-12-13 08:09:16 +00:00
|
|
|
import java.util.Locale;
|
2013-09-26 03:59:02 +00:00
|
|
|
import java.util.Map;
|
2013-07-26 05:38:52 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-26 03:59:02 +00:00
|
|
|
* This class is a base class of a dictionary that supports decaying for the personalized language
|
|
|
|
* model.
|
2013-07-26 05:38:52 +00:00
|
|
|
*/
|
2013-09-26 03:59:02 +00:00
|
|
|
public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableBinaryDictionary {
|
|
|
|
private static final String TAG = DecayingExpandableBinaryDictionaryBase.class.getSimpleName();
|
2013-12-13 08:09:16 +00:00
|
|
|
private static final boolean DBG_DUMP_ON_CLOSE = false;
|
2013-07-31 05:42:50 +00:00
|
|
|
|
|
|
|
/** Any pair being typed or picked */
|
2013-08-26 09:50:22 +00:00
|
|
|
public static final int FREQUENCY_FOR_TYPED = 2;
|
2013-07-31 05:42:50 +00:00
|
|
|
|
2013-09-30 11:53:35 +00:00
|
|
|
public static final int FREQUENCY_FOR_WORDS_IN_DICTS = FREQUENCY_FOR_TYPED;
|
|
|
|
public static final int FREQUENCY_FOR_WORDS_NOT_IN_DICTS = Dictionary.NOT_A_PROBABILITY;
|
|
|
|
|
2013-12-17 10:36:19 +00:00
|
|
|
/** The locale for this dictionary. */
|
|
|
|
public final Locale mLocale;
|
2013-07-26 05:38:52 +00:00
|
|
|
|
2014-02-13 07:16:44 +00:00
|
|
|
protected DecayingExpandableBinaryDictionaryBase(final Context context,
|
2014-02-13 03:12:13 +00:00
|
|
|
final String dictName, final Locale locale, final String dictionaryType,
|
2013-12-13 08:09:16 +00:00
|
|
|
final File dictFile) {
|
2014-02-27 14:21:09 +00:00
|
|
|
super(context, dictName, locale, dictionaryType, dictFile);
|
2013-07-26 05:38:52 +00:00
|
|
|
mLocale = locale;
|
2013-12-13 08:09:16 +00:00
|
|
|
if (mLocale != null && mLocale.toString().length() > 1) {
|
2013-09-09 04:04:28 +00:00
|
|
|
reloadDictionaryIfRequired();
|
2013-07-31 05:42:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void close() {
|
2013-12-13 08:09:16 +00:00
|
|
|
if (DBG_DUMP_ON_CLOSE) {
|
|
|
|
dumpAllWordsForDebug();
|
2013-09-24 13:57:15 +00:00
|
|
|
}
|
2013-08-26 09:50:22 +00:00
|
|
|
// Flush pending writes.
|
2013-12-13 08:09:16 +00:00
|
|
|
asyncFlushBinaryDictionary();
|
2014-04-24 21:48:01 +00:00
|
|
|
super.close();
|
2013-08-26 09:50:22 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 03:59:02 +00:00
|
|
|
@Override
|
|
|
|
protected Map<String, String> getHeaderAttributeMap() {
|
2014-02-27 14:21:09 +00:00
|
|
|
final Map<String, String> attributeMap = super.getHeaderAttributeMap();
|
2014-02-04 12:36:04 +00:00
|
|
|
attributeMap.put(DictionaryHeader.USES_FORGETTING_CURVE_KEY,
|
|
|
|
DictionaryHeader.ATTRIBUTE_VALUE_TRUE);
|
|
|
|
attributeMap.put(DictionaryHeader.HAS_HISTORICAL_INFO_KEY,
|
|
|
|
DictionaryHeader.ATTRIBUTE_VALUE_TRUE);
|
2013-09-26 03:59:02 +00:00
|
|
|
return attributeMap;
|
|
|
|
}
|
|
|
|
|
2013-08-26 09:50:22 +00:00
|
|
|
@Override
|
2014-02-27 14:21:09 +00:00
|
|
|
protected boolean haveContentsChanged() {
|
2013-08-26 09:50:22 +00:00
|
|
|
return false;
|
2013-07-31 05:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-27 14:21:09 +00:00
|
|
|
protected void loadInitialContentsLocked() {
|
|
|
|
// No initial contents.
|
2013-12-13 08:09:16 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 09:17:09 +00:00
|
|
|
/* package */ void runGCIfRequired() {
|
2013-10-02 09:06:08 +00:00
|
|
|
runGCIfRequired(false /* mindsBlockByGC */);
|
|
|
|
}
|
2013-07-26 05:38:52 +00:00
|
|
|
}
|