Replace the flags in getSuggestions with a boolean.
Change-Id: I0ec44df1979cb1dc21017ea290d2151a2af0e7cd Conflicts: java/src/com/android/inputmethod/latin/Suggest.javamain
parent
24aee9100e
commit
338d3ec725
|
@ -61,11 +61,6 @@ public class BinaryDictionary extends Dictionary {
|
|||
public static final Flag FLAG_REQUIRES_FRENCH_LIGATURES_PROCESSING =
|
||||
new Flag(R.bool.config_require_ligatures_processing, 0x4);
|
||||
|
||||
// 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 int FLAG_USE_FULL_EDIT_DISTANCE = 0x2;
|
||||
|
||||
// Can create a new flag from extravalue :
|
||||
// public static final Flag FLAG_MYFLAG =
|
||||
// new Flag("my_flag", 0x02);
|
||||
|
@ -85,7 +80,7 @@ public class BinaryDictionary extends Dictionary {
|
|||
FLAG_REQUIRES_FRENCH_LIGATURES_PROCESSING,
|
||||
};
|
||||
|
||||
private final int mFlags;
|
||||
private final boolean mUseFullEditDistance;
|
||||
|
||||
/**
|
||||
* Constructor for the binary dictionary. This is supposed to be called from the
|
||||
|
@ -104,11 +99,7 @@ public class BinaryDictionary extends Dictionary {
|
|||
// Initializing this here will help transitioning out of the scheme where
|
||||
// the Suggest class knows everything about every single dictionary.
|
||||
mDicTypeId = Suggest.DIC_MAIN;
|
||||
if (useFullEditDistance) {
|
||||
mFlags = FLAG_USE_FULL_EDIT_DISTANCE;
|
||||
} else {
|
||||
mFlags = 0;
|
||||
}
|
||||
mUseFullEditDistance = useFullEditDistance;
|
||||
loadDictionary(filename, offset, length);
|
||||
}
|
||||
|
||||
|
@ -121,8 +112,8 @@ public class BinaryDictionary extends Dictionary {
|
|||
private native void closeNative(long dict);
|
||||
private native boolean isValidWordNative(long dict, char[] word, int wordLength);
|
||||
private native int getSuggestionsNative(long dict, long proximityInfo, int[] xCoordinates,
|
||||
int[] yCoordinates, int[] inputCodes, int codesSize, int flags, char[] outputChars,
|
||||
int[] scores);
|
||||
int[] yCoordinates, int[] inputCodes, int codesSize, boolean useFullEditDistance,
|
||||
char[] outputChars, int[] scores);
|
||||
private native int getBigramsNative(long dict, char[] prevWord, int prevWordLength,
|
||||
int[] inputCodes, int inputCodesLength, char[] outputChars, int[] scores,
|
||||
int maxWordLength, int maxBigrams);
|
||||
|
@ -214,7 +205,7 @@ public class BinaryDictionary extends Dictionary {
|
|||
return getSuggestionsNative(
|
||||
mNativeDict, proximityInfo.getNativeProximityInfo(),
|
||||
codes.getXCoordinates(), codes.getYCoordinates(), mInputCodes, codesSize,
|
||||
mFlags, outputChars, scores);
|
||||
mUseFullEditDistance, outputChars, scores);
|
||||
}
|
||||
|
||||
public static double calcNormalizedScore(String before, String after, int score) {
|
||||
|
|
|
@ -108,14 +108,6 @@ public class Suggest implements Dictionary.WordCallback {
|
|||
initAsynchronously(context, dictionaryResId, locale);
|
||||
}
|
||||
|
||||
// TODO: remove when the tests are updated
|
||||
/* package for test */ Suggest(final Context context, final File dictionary,
|
||||
final long startOffset, final long length, final Flag[] flagArray,
|
||||
final Locale locale) {
|
||||
initSynchronously(context, DictionaryFactory.createDictionaryForTest(context, dictionary,
|
||||
startOffset, length /* useFullEditDistance */, false, locale), locale);
|
||||
}
|
||||
|
||||
/* package for test */ Suggest(final Context context, final File dictionary,
|
||||
final long startOffset, final long length, final Locale locale) {
|
||||
initSynchronously(context, DictionaryFactory.createDictionaryForTest(context, dictionary,
|
||||
|
|
|
@ -127,7 +127,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
|
|||
|
||||
static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object, jlong dict,
|
||||
jlong proximityInfo, jintArray xCoordinatesArray, jintArray yCoordinatesArray,
|
||||
jintArray inputArray, jint arraySize, jint flags,
|
||||
jintArray inputArray, jint arraySize, jboolean useFullEditDistance,
|
||||
jcharArray outputArray, jintArray frequencyArray) {
|
||||
Dictionary *dictionary = (Dictionary*)dict;
|
||||
if (!dictionary) return 0;
|
||||
|
@ -141,7 +141,7 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object,
|
|||
jchar *outputChars = env->GetCharArrayElements(outputArray, 0);
|
||||
|
||||
int count = dictionary->getSuggestions(pInfo, xCoordinates, yCoordinates, inputCodes,
|
||||
arraySize, flags, (unsigned short*) outputChars, frequencies);
|
||||
arraySize, useFullEditDistance, (unsigned short*) outputChars, frequencies);
|
||||
|
||||
env->ReleaseIntArrayElements(frequencyArray, frequencies, 0);
|
||||
env->ReleaseIntArrayElements(inputArray, inputCodes, JNI_ABORT);
|
||||
|
@ -241,7 +241,7 @@ void releaseDictBuf(void* dictBuf, const size_t length, int fd) {
|
|||
static JNINativeMethod sMethods[] = {
|
||||
{"openNative", "(Ljava/lang/String;JJIIII)J", (void*)latinime_BinaryDictionary_open},
|
||||
{"closeNative", "(J)V", (void*)latinime_BinaryDictionary_close},
|
||||
{"getSuggestionsNative", "(JJ[I[I[III[C[I)I", (void*)latinime_BinaryDictionary_getSuggestions},
|
||||
{"getSuggestionsNative", "(JJ[I[I[IIZ[C[I)I", (void*)latinime_BinaryDictionary_getSuggestions},
|
||||
{"isValidWordNative", "(J[CI)Z", (void*)latinime_BinaryDictionary_isValidWord},
|
||||
{"getBigramsNative", "(J[CI[II[C[III)I", (void*)latinime_BinaryDictionary_getBigrams},
|
||||
{"calcNormalizedScoreNative", "([CI[CII)D",
|
||||
|
|
|
@ -33,10 +33,11 @@ class Dictionary {
|
|||
int fullWordMultiplier, int maxWordLength, int maxWords);
|
||||
|
||||
int getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates,
|
||||
int *codes, int codesSize, int flags, unsigned short *outWords, int *frequencies) {
|
||||
int *codes, int codesSize, bool useFullEditDistance, unsigned short *outWords,
|
||||
int *frequencies) {
|
||||
return mUnigramDictionary->getSuggestions(proximityInfo, mWordsPriorityQueuePool,
|
||||
mCorrection, xcoordinates, ycoordinates, codes,
|
||||
codesSize, flags, outWords, frequencies);
|
||||
codesSize, useFullEditDistance, outWords, frequencies);
|
||||
}
|
||||
|
||||
int getBigrams(unsigned short *word, int length, int *codes, int codesSize,
|
||||
|
|
|
@ -98,7 +98,7 @@ int UnigramDictionary::getDigraphReplacement(const int *codes, const int i, cons
|
|||
void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximityInfo,
|
||||
const int *xcoordinates, const int *ycoordinates, const int *codesBuffer,
|
||||
int *xCoordinatesBuffer, int *yCoordinatesBuffer,
|
||||
const int codesBufferSize, const int flags, const int *codesSrc,
|
||||
const int codesBufferSize, const bool useFullEditDistance, const int *codesSrc,
|
||||
const int codesRemain, const int currentDepth, int *codesDest, Correction *correction,
|
||||
WordsPriorityQueuePool *queuePool,
|
||||
const digraph_t* const digraphs, const unsigned int digraphsSize) {
|
||||
|
@ -126,8 +126,8 @@ void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximit
|
|||
codesDest[(i - 1) * (BYTES_IN_ONE_CHAR / sizeof(codesDest[0]))] =
|
||||
replacementCodePoint;
|
||||
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates,
|
||||
codesBuffer, xCoordinatesBuffer, yCoordinatesBuffer, codesBufferSize, flags,
|
||||
codesSrc + i + 1, codesRemain - i - 1,
|
||||
codesBuffer, xCoordinatesBuffer, yCoordinatesBuffer, codesBufferSize,
|
||||
useFullEditDistance, codesSrc + i + 1, codesRemain - i - 1,
|
||||
currentDepth + 1, codesDest + i, correction,
|
||||
queuePool, digraphs, digraphsSize);
|
||||
|
||||
|
@ -136,8 +136,8 @@ void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximit
|
|||
// In our example, after "pru" in the buffer copy the "e", and continue on "fen"
|
||||
memcpy(codesDest + i, codesSrc + i, BYTES_IN_ONE_CHAR);
|
||||
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates,
|
||||
codesBuffer, xCoordinatesBuffer, yCoordinatesBuffer, codesBufferSize, flags,
|
||||
codesSrc + i, codesRemain - i, currentDepth + 1,
|
||||
codesBuffer, xCoordinatesBuffer, yCoordinatesBuffer, codesBufferSize,
|
||||
useFullEditDistance, codesSrc + i, codesRemain - i, currentDepth + 1,
|
||||
codesDest + i, correction, queuePool,
|
||||
digraphs, digraphsSize);
|
||||
return;
|
||||
|
@ -160,14 +160,14 @@ void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximit
|
|||
}
|
||||
|
||||
getWordSuggestions(proximityInfo, xCoordinatesBuffer, yCoordinatesBuffer, codesBuffer,
|
||||
startIndex + codesRemain, flags, correction,
|
||||
startIndex + codesRemain, useFullEditDistance, correction,
|
||||
queuePool);
|
||||
}
|
||||
|
||||
int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo,
|
||||
WordsPriorityQueuePool *queuePool, Correction *correction, const int *xcoordinates,
|
||||
const int *ycoordinates, const int *codes, const int codesSize, const int flags,
|
||||
unsigned short *outWords, int *frequencies) {
|
||||
const int *ycoordinates, const int *codes, const int codesSize,
|
||||
const bool useFullEditDistance, unsigned short *outWords, int *frequencies) {
|
||||
|
||||
queuePool->clearAll();
|
||||
Correction* masterCorrection = correction;
|
||||
|
@ -178,8 +178,8 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo,
|
|||
int yCoordinatesBuffer[codesSize];
|
||||
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates, codesBuffer,
|
||||
xCoordinatesBuffer, yCoordinatesBuffer,
|
||||
codesSize, flags, codes, codesSize, 0, codesBuffer, masterCorrection, queuePool,
|
||||
GERMAN_UMLAUT_DIGRAPHS,
|
||||
codesSize, useFullEditDistance, codes, codesSize, 0, codesBuffer, masterCorrection,
|
||||
queuePool, GERMAN_UMLAUT_DIGRAPHS,
|
||||
sizeof(GERMAN_UMLAUT_DIGRAPHS) / sizeof(GERMAN_UMLAUT_DIGRAPHS[0]));
|
||||
} else if (BinaryFormat::REQUIRES_FRENCH_LIGATURES_PROCESSING & FLAGS) {
|
||||
int codesBuffer[getCodesBufferSize(codes, codesSize)];
|
||||
|
@ -187,12 +187,12 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo,
|
|||
int yCoordinatesBuffer[codesSize];
|
||||
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates, codesBuffer,
|
||||
xCoordinatesBuffer, yCoordinatesBuffer,
|
||||
codesSize, flags, codes, codesSize, 0, codesBuffer, masterCorrection, queuePool,
|
||||
FRENCH_LIGATURES_DIGRAPHS,
|
||||
codesSize, useFullEditDistance, codes, codesSize, 0, codesBuffer, masterCorrection,
|
||||
queuePool, FRENCH_LIGATURES_DIGRAPHS,
|
||||
sizeof(FRENCH_LIGATURES_DIGRAPHS) / sizeof(FRENCH_LIGATURES_DIGRAPHS[0]));
|
||||
} else { // Normal processing
|
||||
getWordSuggestions(proximityInfo, xcoordinates, ycoordinates, codes, codesSize, flags,
|
||||
masterCorrection, queuePool);
|
||||
getWordSuggestions(proximityInfo, xcoordinates, ycoordinates, codes, codesSize,
|
||||
useFullEditDistance, masterCorrection, queuePool);
|
||||
}
|
||||
|
||||
PROF_START(20);
|
||||
|
@ -225,7 +225,7 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo,
|
|||
|
||||
void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
|
||||
const int *xcoordinates, const int *ycoordinates, const int *codes,
|
||||
const int inputLength, const int flags, Correction *correction,
|
||||
const int inputLength, const bool useFullEditDistance, Correction *correction,
|
||||
WordsPriorityQueuePool *queuePool) {
|
||||
|
||||
PROF_OPEN;
|
||||
|
@ -233,7 +233,6 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
|
|||
PROF_END(0);
|
||||
|
||||
PROF_START(1);
|
||||
const bool useFullEditDistance = USE_FULL_EDIT_DISTANCE & flags;
|
||||
getOneWordSuggestions(proximityInfo, xcoordinates, ycoordinates, codes, useFullEditDistance,
|
||||
inputLength, correction, queuePool);
|
||||
PROF_END(1);
|
||||
|
|
|
@ -75,20 +75,21 @@ class UnigramDictionary {
|
|||
int getBigramPosition(int pos, unsigned short *word, int offset, int length) const;
|
||||
int getSuggestions(ProximityInfo *proximityInfo, WordsPriorityQueuePool *queuePool,
|
||||
Correction *correction, const int *xcoordinates,
|
||||
const int *ycoordinates, const int *codes, const int codesSize, const int flags,
|
||||
unsigned short *outWords, int *frequencies);
|
||||
const int *ycoordinates, const int *codes, const int codesSize,
|
||||
const bool useFullEditDistance, unsigned short *outWords, int *frequencies);
|
||||
virtual ~UnigramDictionary();
|
||||
|
||||
private:
|
||||
void getWordSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates,
|
||||
const int *ycoordinates, const int *codes, const int inputLength,
|
||||
const int flags, Correction *correction, WordsPriorityQueuePool *queuePool);
|
||||
const bool useFullEditDistance, Correction *correction,
|
||||
WordsPriorityQueuePool *queuePool);
|
||||
int getDigraphReplacement(const int *codes, const int i, const int codesSize,
|
||||
const digraph_t* const digraphs, const unsigned int digraphsSize) const;
|
||||
void getWordWithDigraphSuggestionsRec(ProximityInfo *proximityInfo,
|
||||
const int *xcoordinates, const int* ycoordinates, const int *codesBuffer,
|
||||
int *xCoordinatesBuffer, int *yCoordinatesBuffer,
|
||||
const int codesBufferSize, const int flags, const int* codesSrc,
|
||||
const int codesBufferSize, const bool useFullEditDistance, const int* codesSrc,
|
||||
const int codesRemain, const int currentDepth, int* codesDest, Correction *correction,
|
||||
WordsPriorityQueuePool* queuePool, const digraph_t* const digraphs,
|
||||
const unsigned int digraphsSize);
|
||||
|
@ -145,13 +146,6 @@ class UnigramDictionary {
|
|||
const int MAX_DIGRAPH_SEARCH_DEPTH;
|
||||
const int FLAGS;
|
||||
|
||||
// Flags for special processing
|
||||
// Those *must* match the flags in BinaryDictionary.Flags.ALL_FLAGS in BinaryDictionary.java
|
||||
// or something very bad (like, the apocalypse) will happen.
|
||||
// Please update both at the same time.
|
||||
enum {
|
||||
USE_FULL_EDIT_DISTANCE = 0x2,
|
||||
};
|
||||
static const digraph_t GERMAN_UMLAUT_DIGRAPHS[];
|
||||
static const digraph_t FRENCH_LIGATURES_DIGRAPHS[];
|
||||
|
||||
|
|
Loading…
Reference in New Issue