Merge "Make use of the FULL_EDIT_DISTANCE flag."
This commit is contained in:
commit
646a66159a
3 changed files with 48 additions and 7 deletions
|
@ -61,16 +61,26 @@ public class BinaryDictionary extends Dictionary {
|
||||||
public static final Flag FLAG_REQUIRES_GERMAN_UMLAUT_PROCESSING =
|
public static final Flag FLAG_REQUIRES_GERMAN_UMLAUT_PROCESSING =
|
||||||
new Flag(R.bool.config_require_umlaut_processing, 0x1);
|
new Flag(R.bool.config_require_umlaut_processing, 0x1);
|
||||||
|
|
||||||
|
// FULL_EDIT_DISTANCE is a flag that forces the dictionary to use full words
|
||||||
|
// when computing edit distance, instead of the default behavior of stopping
|
||||||
|
// the evaluation at the size the user typed.
|
||||||
public static final Flag FLAG_USE_FULL_EDIT_DISTANCE = new Flag(0x2);
|
public static final Flag FLAG_USE_FULL_EDIT_DISTANCE = new Flag(0x2);
|
||||||
|
|
||||||
// Can create a new flag from extravalue :
|
// Can create a new flag from extravalue :
|
||||||
// public static final Flag FLAG_MYFLAG =
|
// public static final Flag FLAG_MYFLAG =
|
||||||
// new Flag("my_flag", 0x02);
|
// new Flag("my_flag", 0x02);
|
||||||
|
|
||||||
private static final Flag[] ALL_FLAGS = {
|
// ALL_CONFIG_FLAGS is a collection of flags that enable reading all flags from configuration.
|
||||||
|
// This is but a mask - it does not mean the flags will be on, only that the configuration
|
||||||
|
// will be read for this particular flag.
|
||||||
|
public static final Flag[] ALL_CONFIG_FLAGS = {
|
||||||
// Here should reside all flags that trigger some special processing
|
// Here should reside all flags that trigger some special processing
|
||||||
// These *must* match the definition in UnigramDictionary enum in
|
// These *must* match the definition in UnigramDictionary enum in
|
||||||
// unigram_dictionary.h so please update both at the same time.
|
// unigram_dictionary.h so please update both at the same time.
|
||||||
|
// Please note that flags created with a resource are of type CONFIG while flags
|
||||||
|
// created with a string are of type EXTRAVALUE. These behave like masks, and the
|
||||||
|
// actual value will be read from the configuration/extra value at run time for
|
||||||
|
// the configuration at dictionary creation time.
|
||||||
FLAG_REQUIRES_GERMAN_UMLAUT_PROCESSING,
|
FLAG_REQUIRES_GERMAN_UMLAUT_PROCESSING,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -93,7 +103,7 @@ public class BinaryDictionary extends Dictionary {
|
||||||
// the Suggest class knows everything about every single dictionary.
|
// the Suggest class knows everything about every single dictionary.
|
||||||
mDicTypeId = Suggest.DIC_MAIN;
|
mDicTypeId = Suggest.DIC_MAIN;
|
||||||
// TODO: Stop relying on the state of SubtypeSwitcher, get it as a parameter
|
// TODO: Stop relying on the state of SubtypeSwitcher, get it as a parameter
|
||||||
mFlags = Flag.initFlags(null == flagArray ? ALL_FLAGS : flagArray, context,
|
mFlags = Flag.initFlags(null == flagArray ? ALL_CONFIG_FLAGS : flagArray, context,
|
||||||
SubtypeSwitcher.getInstance());
|
SubtypeSwitcher.getInstance());
|
||||||
loadDictionary(filename, offset, length);
|
loadDictionary(filename, offset, length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class DictionaryFactory {
|
||||||
private static String TAG = DictionaryFactory.class.getSimpleName();
|
private static String TAG = DictionaryFactory.class.getSimpleName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a dictionary from a dictionary pack.
|
* Initializes a dictionary from a dictionary pack, with explicit flags.
|
||||||
*
|
*
|
||||||
* This searches for a content provider providing a dictionary pack for the specified
|
* This searches for a content provider providing a dictionary pack for the specified
|
||||||
* locale. If none is found, it falls back to using the resource passed as fallBackResId
|
* locale. If none is found, it falls back to using the resource passed as fallBackResId
|
||||||
|
@ -42,10 +42,11 @@ public class DictionaryFactory {
|
||||||
* @param context application context for reading resources
|
* @param context application context for reading resources
|
||||||
* @param locale the locale for which to create the dictionary
|
* @param locale the locale for which to create the dictionary
|
||||||
* @param fallbackResId the id of the resource to use as a fallback if no pack is found
|
* @param fallbackResId the id of the resource to use as a fallback if no pack is found
|
||||||
|
* @param flagArray an array of flags to use
|
||||||
* @return an initialized instance of DictionaryCollection
|
* @return an initialized instance of DictionaryCollection
|
||||||
*/
|
*/
|
||||||
public static DictionaryCollection createDictionaryFromManager(Context context, Locale locale,
|
public static DictionaryCollection createDictionaryFromManager(final Context context,
|
||||||
int fallbackResId) {
|
final Locale locale, final int fallbackResId, final Flag[] flagArray) {
|
||||||
if (null == locale) {
|
if (null == locale) {
|
||||||
Log.e(TAG, "No locale defined for dictionary");
|
Log.e(TAG, "No locale defined for dictionary");
|
||||||
return new DictionaryCollection(createBinaryDictionary(context, fallbackResId, locale));
|
return new DictionaryCollection(createBinaryDictionary(context, fallbackResId, locale));
|
||||||
|
@ -57,7 +58,7 @@ public class DictionaryFactory {
|
||||||
if (null != assetFileList) {
|
if (null != assetFileList) {
|
||||||
for (final AssetFileAddress f : assetFileList) {
|
for (final AssetFileAddress f : assetFileList) {
|
||||||
final BinaryDictionary binaryDictionary =
|
final BinaryDictionary binaryDictionary =
|
||||||
new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength, null);
|
new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength, flagArray);
|
||||||
if (binaryDictionary.isValidDictionary()) {
|
if (binaryDictionary.isValidDictionary()) {
|
||||||
dictList.add(binaryDictionary);
|
dictList.add(binaryDictionary);
|
||||||
}
|
}
|
||||||
|
@ -70,6 +71,22 @@ public class DictionaryFactory {
|
||||||
return new DictionaryCollection(dictList);
|
return new DictionaryCollection(dictList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a dictionary from a dictionary pack, with default flags.
|
||||||
|
*
|
||||||
|
* This searches for a content provider providing a dictionary pack for the specified
|
||||||
|
* locale. If none is found, it falls back to using the resource passed as fallBackResId
|
||||||
|
* as a dictionary.
|
||||||
|
* @param context application context for reading resources
|
||||||
|
* @param locale the locale for which to create the dictionary
|
||||||
|
* @param fallbackResId the id of the resource to use as a fallback if no pack is found
|
||||||
|
* @return an initialized instance of DictionaryCollection
|
||||||
|
*/
|
||||||
|
public static DictionaryCollection createDictionaryFromManager(final Context context,
|
||||||
|
final Locale locale, final int fallbackResId) {
|
||||||
|
return createDictionaryFromManager(context, locale, fallbackResId, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a dictionary from a raw resource file
|
* Initializes a dictionary from a raw resource file
|
||||||
* @param context application context for reading resources
|
* @param context application context for reading resources
|
||||||
|
|
|
@ -28,11 +28,13 @@ import android.text.TextUtils;
|
||||||
import com.android.inputmethod.compat.ArraysCompatUtils;
|
import com.android.inputmethod.compat.ArraysCompatUtils;
|
||||||
import com.android.inputmethod.keyboard.Key;
|
import com.android.inputmethod.keyboard.Key;
|
||||||
import com.android.inputmethod.keyboard.ProximityInfo;
|
import com.android.inputmethod.keyboard.ProximityInfo;
|
||||||
|
import com.android.inputmethod.latin.BinaryDictionary;
|
||||||
import com.android.inputmethod.latin.Dictionary;
|
import com.android.inputmethod.latin.Dictionary;
|
||||||
import com.android.inputmethod.latin.Dictionary.DataType;
|
import com.android.inputmethod.latin.Dictionary.DataType;
|
||||||
import com.android.inputmethod.latin.Dictionary.WordCallback;
|
import com.android.inputmethod.latin.Dictionary.WordCallback;
|
||||||
import com.android.inputmethod.latin.DictionaryCollection;
|
import com.android.inputmethod.latin.DictionaryCollection;
|
||||||
import com.android.inputmethod.latin.DictionaryFactory;
|
import com.android.inputmethod.latin.DictionaryFactory;
|
||||||
|
import com.android.inputmethod.latin.Flag;
|
||||||
import com.android.inputmethod.latin.LocaleUtils;
|
import com.android.inputmethod.latin.LocaleUtils;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.SynchronouslyLoadedUserDictionary;
|
import com.android.inputmethod.latin.SynchronouslyLoadedUserDictionary;
|
||||||
|
@ -65,6 +67,17 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
|
||||||
private final static SuggestionsInfo IN_DICT_EMPTY_SUGGESTIONS =
|
private final static SuggestionsInfo IN_DICT_EMPTY_SUGGESTIONS =
|
||||||
new SuggestionsInfo(SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY,
|
new SuggestionsInfo(SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY,
|
||||||
EMPTY_STRING_ARRAY);
|
EMPTY_STRING_ARRAY);
|
||||||
|
private final static Flag[] USE_FULL_EDIT_DISTANCE_FLAG_ARRAY;
|
||||||
|
static {
|
||||||
|
// See BinaryDictionary.java for an explanation of these flags
|
||||||
|
// Specifially, ALL_CONFIG_FLAGS means that we want to consider all flags with the
|
||||||
|
// current dictionary configuration - for example, consider the UMLAUT flag
|
||||||
|
// so that it will be turned on for German dictionaries and off for others.
|
||||||
|
USE_FULL_EDIT_DISTANCE_FLAG_ARRAY = Arrays.copyOf(BinaryDictionary.ALL_CONFIG_FLAGS,
|
||||||
|
BinaryDictionary.ALL_CONFIG_FLAGS.length + 1);
|
||||||
|
USE_FULL_EDIT_DISTANCE_FLAG_ARRAY[BinaryDictionary.ALL_CONFIG_FLAGS.length] =
|
||||||
|
BinaryDictionary.FLAG_USE_FULL_EDIT_DISTANCE;
|
||||||
|
}
|
||||||
private Map<String, DictionaryPool> mDictionaryPools =
|
private Map<String, DictionaryPool> mDictionaryPools =
|
||||||
Collections.synchronizedMap(new TreeMap<String, DictionaryPool>());
|
Collections.synchronizedMap(new TreeMap<String, DictionaryPool>());
|
||||||
private Map<String, Dictionary> mUserDictionaries =
|
private Map<String, Dictionary> mUserDictionaries =
|
||||||
|
@ -263,7 +276,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
|
||||||
final Resources resources = getResources();
|
final Resources resources = getResources();
|
||||||
final int fallbackResourceId = Utils.getMainDictionaryResourceId(resources);
|
final int fallbackResourceId = Utils.getMainDictionaryResourceId(resources);
|
||||||
final DictionaryCollection dictionaryCollection =
|
final DictionaryCollection dictionaryCollection =
|
||||||
DictionaryFactory.createDictionaryFromManager(this, locale, fallbackResourceId);
|
DictionaryFactory.createDictionaryFromManager(this, locale, fallbackResourceId,
|
||||||
|
USE_FULL_EDIT_DISTANCE_FLAG_ARRAY);
|
||||||
final String localeStr = locale.toString();
|
final String localeStr = locale.toString();
|
||||||
Dictionary userDict = mUserDictionaries.get(localeStr);
|
Dictionary userDict = mUserDictionaries.get(localeStr);
|
||||||
if (null == userDict) {
|
if (null == userDict) {
|
||||||
|
|
Loading…
Reference in a new issue