Merge "Make contacts dict and user dict version 4."
This commit is contained in:
commit
b1814c9633
4 changed files with 14 additions and 32 deletions
|
@ -16,12 +16,12 @@
|
|||
|
||||
package com.android.inputmethod.latin;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.inputmethod.latin.makedict.DictEncoder;
|
||||
import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
|
||||
import com.android.inputmethod.latin.makedict.Ver2DictEncoder;
|
||||
import com.android.inputmethod.latin.makedict.Ver4DictEncoder;
|
||||
import com.android.inputmethod.latin.utils.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -31,10 +31,7 @@ abstract public class AbstractDictionaryWriter {
|
|||
/** Used for Log actions from this class */
|
||||
private static final String TAG = AbstractDictionaryWriter.class.getSimpleName();
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
public AbstractDictionaryWriter(final Context context) {
|
||||
mContext = context;
|
||||
public AbstractDictionaryWriter() {
|
||||
}
|
||||
|
||||
abstract public void clear();
|
||||
|
@ -61,12 +58,11 @@ abstract public class AbstractDictionaryWriter {
|
|||
final Map<String, String> attributeMap) throws IOException, UnsupportedFormatException;
|
||||
|
||||
public void write(final File file, final Map<String, String> attributeMap) {
|
||||
final String tempFilePath = file.getAbsolutePath() + ".temp";
|
||||
final File tempFile = new File(tempFilePath);
|
||||
try {
|
||||
final DictEncoder dictEncoder = new Ver2DictEncoder(tempFile);
|
||||
FileUtils.deleteRecursively(file);
|
||||
file.mkdir();
|
||||
final DictEncoder dictEncoder = new Ver4DictEncoder(file);
|
||||
writeDictionary(dictEncoder, attributeMap);
|
||||
tempFile.renameTo(file);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "IO exception while writing file", e);
|
||||
} catch (UnsupportedFormatException e) {
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package com.android.inputmethod.latin;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.inputmethod.latin.makedict.DictEncoder;
|
||||
import com.android.inputmethod.latin.makedict.FormatSpec;
|
||||
import com.android.inputmethod.latin.makedict.FusionDictionary;
|
||||
|
@ -35,14 +33,13 @@ import java.util.Map;
|
|||
* An in memory dictionary for memorizing entries and writing a binary dictionary.
|
||||
*/
|
||||
public class DictionaryWriter extends AbstractDictionaryWriter {
|
||||
private static final int BINARY_DICT_VERSION = 2;
|
||||
private static final int BINARY_DICT_VERSION = FormatSpec.VERSION4;
|
||||
private static final FormatSpec.FormatOptions FORMAT_OPTIONS =
|
||||
new FormatSpec.FormatOptions(BINARY_DICT_VERSION, false /* supportsDynamicUpdate */);
|
||||
new FormatSpec.FormatOptions(BINARY_DICT_VERSION, false /* hasTimestamp */);
|
||||
|
||||
private FusionDictionary mFusionDictionary;
|
||||
|
||||
public DictionaryWriter(final Context context) {
|
||||
super(context);
|
||||
public DictionaryWriter() {
|
||||
clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -136,12 +136,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
*/
|
||||
protected abstract boolean hasContentChanged();
|
||||
|
||||
protected boolean matchesExpectedBinaryDictFormatVersionForThisType(final int formatVersion) {
|
||||
// This class is using format 2 because it's used by the User and Contacts dictionary
|
||||
// only, which right now use format 2 (dicts using format 4 use Decaying*, which overrides
|
||||
// this method).
|
||||
// TODO: Migrate these dicts to ver4 format, and remove this function.
|
||||
return formatVersion == FormatSpec.VERSION2;
|
||||
private boolean matchesExpectedBinaryDictFormatVersionForThisType(final int formatVersion) {
|
||||
return formatVersion == FormatSpec.VERSION4;
|
||||
}
|
||||
|
||||
public boolean isValidDictionary() {
|
||||
|
@ -194,12 +190,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
}
|
||||
}
|
||||
|
||||
private static AbstractDictionaryWriter getDictionaryWriter(final Context context,
|
||||
private static AbstractDictionaryWriter getDictionaryWriter(
|
||||
final boolean isDynamicPersonalizationDictionary) {
|
||||
if (isDynamicPersonalizationDictionary) {
|
||||
return null;
|
||||
} else {
|
||||
return new DictionaryWriter(context);
|
||||
return new DictionaryWriter();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,7 +229,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
mBinaryDictionary = null;
|
||||
mDictNameDictionaryUpdateController = getDictionaryUpdateController(dictName);
|
||||
// Currently, only dynamic personalization dictionary is updatable.
|
||||
mDictionaryWriter = getDictionaryWriter(context, isUpdatable);
|
||||
mDictionaryWriter = getDictionaryWriter(isUpdatable);
|
||||
}
|
||||
|
||||
protected static String getDictNameWithLocale(final String name, final Locale locale) {
|
||||
|
|
|
@ -116,13 +116,6 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean matchesExpectedBinaryDictFormatVersionForThisType(final int formatVersion) {
|
||||
// This class is using format 4 because it's used by all version 4 dictionaries.
|
||||
// TODO: remove this when all dynamically generated dicts use version 4.
|
||||
return formatVersion == REQUIRED_BINARY_DICTIONARY_VERSION;
|
||||
}
|
||||
|
||||
public void addMultipleDictionaryEntriesToDictionary(
|
||||
final ArrayList<LanguageModelParam> languageModelParams,
|
||||
final ExpandableBinaryDictionary.AddMultipleDictionaryEntriesCallback callback) {
|
||||
|
|
Loading…
Reference in a new issue