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;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.makedict.DictEncoder;
|
import com.android.inputmethod.latin.makedict.DictEncoder;
|
||||||
import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
|
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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -31,10 +31,7 @@ abstract public class AbstractDictionaryWriter {
|
||||||
/** Used for Log actions from this class */
|
/** Used for Log actions from this class */
|
||||||
private static final String TAG = AbstractDictionaryWriter.class.getSimpleName();
|
private static final String TAG = AbstractDictionaryWriter.class.getSimpleName();
|
||||||
|
|
||||||
private final Context mContext;
|
public AbstractDictionaryWriter() {
|
||||||
|
|
||||||
public AbstractDictionaryWriter(final Context context) {
|
|
||||||
mContext = context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public void clear();
|
abstract public void clear();
|
||||||
|
@ -61,12 +58,11 @@ abstract public class AbstractDictionaryWriter {
|
||||||
final Map<String, String> attributeMap) throws IOException, UnsupportedFormatException;
|
final Map<String, String> attributeMap) throws IOException, UnsupportedFormatException;
|
||||||
|
|
||||||
public void write(final File file, final Map<String, String> attributeMap) {
|
public void write(final File file, final Map<String, String> attributeMap) {
|
||||||
final String tempFilePath = file.getAbsolutePath() + ".temp";
|
|
||||||
final File tempFile = new File(tempFilePath);
|
|
||||||
try {
|
try {
|
||||||
final DictEncoder dictEncoder = new Ver2DictEncoder(tempFile);
|
FileUtils.deleteRecursively(file);
|
||||||
|
file.mkdir();
|
||||||
|
final DictEncoder dictEncoder = new Ver4DictEncoder(file);
|
||||||
writeDictionary(dictEncoder, attributeMap);
|
writeDictionary(dictEncoder, attributeMap);
|
||||||
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);
|
||||||
} catch (UnsupportedFormatException e) {
|
} catch (UnsupportedFormatException e) {
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.android.inputmethod.latin.makedict.DictEncoder;
|
import com.android.inputmethod.latin.makedict.DictEncoder;
|
||||||
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;
|
||||||
|
@ -35,14 +33,13 @@ 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.
|
||||||
*/
|
*/
|
||||||
public class DictionaryWriter extends AbstractDictionaryWriter {
|
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 =
|
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;
|
private FusionDictionary mFusionDictionary;
|
||||||
|
|
||||||
public DictionaryWriter(final Context context) {
|
public DictionaryWriter() {
|
||||||
super(context);
|
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,12 +136,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
*/
|
*/
|
||||||
protected abstract boolean hasContentChanged();
|
protected abstract boolean hasContentChanged();
|
||||||
|
|
||||||
protected boolean matchesExpectedBinaryDictFormatVersionForThisType(final int formatVersion) {
|
private boolean matchesExpectedBinaryDictFormatVersionForThisType(final int formatVersion) {
|
||||||
// This class is using format 2 because it's used by the User and Contacts dictionary
|
return formatVersion == FormatSpec.VERSION4;
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidDictionary() {
|
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) {
|
final boolean isDynamicPersonalizationDictionary) {
|
||||||
if (isDynamicPersonalizationDictionary) {
|
if (isDynamicPersonalizationDictionary) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return new DictionaryWriter(context);
|
return new DictionaryWriter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +229,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
mBinaryDictionary = null;
|
mBinaryDictionary = null;
|
||||||
mDictNameDictionaryUpdateController = getDictionaryUpdateController(dictName);
|
mDictNameDictionaryUpdateController = getDictionaryUpdateController(dictName);
|
||||||
// Currently, only dynamic personalization dictionary is updatable.
|
// Currently, only dynamic personalization dictionary is updatable.
|
||||||
mDictionaryWriter = getDictionaryWriter(context, isUpdatable);
|
mDictionaryWriter = getDictionaryWriter(isUpdatable);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String getDictNameWithLocale(final String name, final Locale locale) {
|
protected static String getDictNameWithLocale(final String name, final Locale locale) {
|
||||||
|
|
|
@ -116,13 +116,6 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
|
||||||
return false;
|
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(
|
public void addMultipleDictionaryEntriesToDictionary(
|
||||||
final ArrayList<LanguageModelParam> languageModelParams,
|
final ArrayList<LanguageModelParam> languageModelParams,
|
||||||
final ExpandableBinaryDictionary.AddMultipleDictionaryEntriesCallback callback) {
|
final ExpandableBinaryDictionary.AddMultipleDictionaryEntriesCallback callback) {
|
||||||
|
|
Loading…
Reference in a new issue