Remove BinaryDictionary.MAX_PREDICTION and MAX_SPACES, and rename MAX_WORDS to MAX_RESULTS

Change-Id: Iab2a422b367e7521f346481c7fe5e2575f2e9de3
main
Ken Wakasa 2013-01-11 18:59:01 +09:00
parent d8590857bd
commit f6870cc82d
16 changed files with 85 additions and 102 deletions

View File

@ -42,17 +42,13 @@ public final class BinaryDictionary extends Dictionary {
* really long words. * really long words.
*/ */
private static final int MAX_WORD_LENGTH = Constants.Dictionary.MAX_WORD_LENGTH; private static final int MAX_WORD_LENGTH = Constants.Dictionary.MAX_WORD_LENGTH;
private static final int MAX_WORDS = 18; private static final int MAX_RESULTS = 18; /* Must be identical to MAX_RESULTS in defines.h */
private static final int MAX_SPACES = 16;
private static final int MAX_PREDICTIONS = 60;
private static final int MAX_RESULTS = Math.max(MAX_PREDICTIONS, MAX_WORDS);
private long mNativeDict; private long mNativeDict;
private final Locale mLocale; private final Locale mLocale;
private final int[] mInputCodePoints = new int[MAX_WORD_LENGTH]; private final int[] mInputCodePoints = new int[MAX_WORD_LENGTH];
private final int[] mOutputCodePoints = new int[MAX_WORD_LENGTH * MAX_RESULTS]; private final int[] mOutputCodePoints = new int[MAX_WORD_LENGTH * MAX_RESULTS];
private final int[] mSpaceIndices = new int[MAX_SPACES]; private final int[] mSpaceIndices = new int[MAX_RESULTS];
private final int[] mOutputScores = new int[MAX_RESULTS]; private final int[] mOutputScores = new int[MAX_RESULTS];
private final int[] mOutputTypes = new int[MAX_RESULTS]; private final int[] mOutputTypes = new int[MAX_RESULTS];
@ -80,16 +76,14 @@ public final class BinaryDictionary extends Dictionary {
/** /**
* Constructor for the binary dictionary. This is supposed to be called from the * Constructor for the binary dictionary. This is supposed to be called from the
* dictionary factory. * dictionary factory.
* @param context the context to access the environment from.
* @param filename the name of the file to read through native code. * @param filename the name of the file to read through native code.
* @param offset the offset of the dictionary data within the file. * @param offset the offset of the dictionary data within the file.
* @param length the length of the binary data. * @param length the length of the binary data.
* @param useFullEditDistance whether to use the full edit distance in suggestions * @param useFullEditDistance whether to use the full edit distance in suggestions
* @param dictType the dictionary type, as a human-readable string * @param dictType the dictionary type, as a human-readable string
*/ */
public BinaryDictionary(final Context context, final String filename, final long offset, public BinaryDictionary(final String filename, final long offset, final long length,
final long length, final boolean useFullEditDistance, final Locale locale, final boolean useFullEditDistance, final Locale locale, final String dictType) {
final String dictType) {
super(dictType); super(dictType);
mLocale = locale; mLocale = locale;
mUseFullEditDistance = useFullEditDistance; mUseFullEditDistance = useFullEditDistance;
@ -101,7 +95,7 @@ public final class BinaryDictionary extends Dictionary {
} }
private native long openNative(String sourceDir, long dictOffset, long dictSize, private native long openNative(String sourceDir, long dictOffset, long dictSize,
int maxWordLength, int maxWords, int maxPredictions); int maxWordLength);
private native void closeNative(long dict); private native void closeNative(long dict);
private native int getFrequencyNative(long dict, int[] word); private native int getFrequencyNative(long dict, int[] word);
private native boolean isValidBigramNative(long dict, int[] word1, int[] word2); private native boolean isValidBigramNative(long dict, int[] word1, int[] word2);
@ -116,8 +110,7 @@ public final class BinaryDictionary extends Dictionary {
// TODO: Move native dict into session // TODO: Move native dict into session
private final void loadDictionary(final String path, final long startOffset, private final void loadDictionary(final String path, final long startOffset,
final long length) { final long length) {
mNativeDict = openNative(path, startOffset, length, MAX_WORD_LENGTH, MAX_WORDS, mNativeDict = openNative(path, startOffset, length, MAX_WORD_LENGTH);
MAX_PREDICTIONS);
} }
@Override @Override
@ -148,14 +141,12 @@ public final class BinaryDictionary extends Dictionary {
final InputPointers ips = composer.getInputPointers(); final InputPointers ips = composer.getInputPointers();
final int codesSize = isGesture ? ips.getPointerSize() : composerSize; final int codesSize = isGesture ? ips.getPointerSize() : composerSize;
// proximityInfo and/or prevWordForBigrams may not be null. // proximityInfo and/or prevWordForBigrams may not be null.
final int tmpCount = getSuggestionsNative(mNativeDict, final int count = getSuggestionsNative(mNativeDict, proximityInfo.getNativeProximityInfo(),
proximityInfo.getNativeProximityInfo(), getTraverseSession(sessionId).getSession(), getTraverseSession(sessionId).getSession(), ips.getXCoordinates(),
ips.getXCoordinates(), ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(), ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(), mInputCodePoints,
mInputCodePoints, codesSize, 0 /* commitPoint */, isGesture, prevWordCodePointArray, codesSize, 0 /* commitPoint */, isGesture, prevWordCodePointArray,
mUseFullEditDistance, mOutputCodePoints, mOutputScores, mSpaceIndices, mUseFullEditDistance, mOutputCodePoints, mOutputScores, mSpaceIndices,
mOutputTypes); mOutputTypes);
final int count = Math.min(tmpCount, MAX_PREDICTIONS);
final ArrayList<SuggestedWordInfo> suggestions = CollectionUtils.newArrayList(); final ArrayList<SuggestedWordInfo> suggestions = CollectionUtils.newArrayList();
for (int j = 0; j < count; ++j) { for (int j = 0; j < count; ++j) {
if (composerSize > 0 && mOutputScores[j] < 1) break; if (composerSize > 0 && mOutputScores[j] < 1) break;

View File

@ -58,9 +58,8 @@ public final class DictionaryFactory {
BinaryDictionaryGetter.getDictionaryFiles(locale, context); BinaryDictionaryGetter.getDictionaryFiles(locale, context);
if (null != assetFileList) { if (null != assetFileList) {
for (final AssetFileAddress f : assetFileList) { for (final AssetFileAddress f : assetFileList) {
final BinaryDictionary binaryDictionary = final BinaryDictionary binaryDictionary = new BinaryDictionary(f.mFilename,
new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength, f.mOffset, f.mLength, useFullEditDistance, locale, Dictionary.TYPE_MAIN);
useFullEditDistance, locale, Dictionary.TYPE_MAIN);
if (binaryDictionary.isValidDictionary()) { if (binaryDictionary.isValidDictionary()) {
dictList.add(binaryDictionary); dictList.add(binaryDictionary);
} }
@ -112,7 +111,7 @@ public final class DictionaryFactory {
Log.e(TAG, "sourceDir is not a file: " + sourceDir); Log.e(TAG, "sourceDir is not a file: " + sourceDir);
return null; return null;
} }
return new BinaryDictionary(context, sourceDir, afd.getStartOffset(), afd.getLength(), return new BinaryDictionary(sourceDir, afd.getStartOffset(), afd.getLength(),
false /* useFullEditDistance */, locale, Dictionary.TYPE_MAIN); false /* useFullEditDistance */, locale, Dictionary.TYPE_MAIN);
} catch (android.content.res.Resources.NotFoundException e) { } catch (android.content.res.Resources.NotFoundException e) {
Log.e(TAG, "Could not find the resource"); Log.e(TAG, "Could not find the resource");
@ -130,17 +129,16 @@ public final class DictionaryFactory {
/** /**
* Create a dictionary from passed data. This is intended for unit tests only. * Create a dictionary from passed data. This is intended for unit tests only.
* @param context the test context to create this data from.
* @param dictionary the file to read * @param dictionary the file to read
* @param startOffset the offset in the file where the data starts * @param startOffset the offset in the file where the data starts
* @param length the length of the data * @param length the length of the data
* @param useFullEditDistance whether to use the full edit distance in suggestions * @param useFullEditDistance whether to use the full edit distance in suggestions
* @return the created dictionary, or null. * @return the created dictionary, or null.
*/ */
public static Dictionary createDictionaryForTest(Context context, File dictionary, public static Dictionary createDictionaryForTest(File dictionary, long startOffset, long length,
long startOffset, long length, final boolean useFullEditDistance, Locale locale) { final boolean useFullEditDistance, Locale locale) {
if (dictionary.isFile()) { if (dictionary.isFile()) {
return new BinaryDictionary(context, dictionary.getAbsolutePath(), startOffset, length, return new BinaryDictionary(dictionary.getAbsolutePath(), startOffset, length,
useFullEditDistance, locale, Dictionary.TYPE_MAIN); useFullEditDistance, locale, Dictionary.TYPE_MAIN);
} else { } else {
Log.e(TAG, "Could not find the file. path=" + dictionary.getAbsolutePath()); Log.e(TAG, "Could not find the file. path=" + dictionary.getAbsolutePath());

View File

@ -279,9 +279,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
final long length = file.length(); final long length = file.length();
// Build the new binary dictionary // Build the new binary dictionary
final BinaryDictionary newBinaryDictionary = final BinaryDictionary newBinaryDictionary = new BinaryDictionary(filename, 0, length,
new BinaryDictionary(mContext, filename, 0, length, true /* useFullEditDistance */, true /* useFullEditDistance */, null, mDictType);
null, mDictType);
if (mBinaryDictionary != null) { if (mBinaryDictionary != null) {
// Ensure all threads accessing the current dictionary have finished before swapping in // Ensure all threads accessing the current dictionary have finished before swapping in

View File

@ -72,9 +72,8 @@ public final class Suggest {
} }
@UsedForTesting @UsedForTesting
Suggest(final Context context, final File dictionary, Suggest(final File dictionary, final long startOffset, final long length, final Locale locale) {
final long startOffset, final long length, final Locale locale) { final Dictionary mainDict = DictionaryFactory.createDictionaryForTest(dictionary,
final Dictionary mainDict = DictionaryFactory.createDictionaryForTest(context, dictionary,
startOffset, length /* useFullEditDistance */, false, locale); startOffset, length /* useFullEditDistance */, false, locale);
mLocale = locale; mLocale = locale;
mMainDictionary = mainDict; mMainDictionary = mainDict;

View File

@ -43,7 +43,7 @@ class ProximityInfo;
static void releaseDictBuf(const void *dictBuf, const size_t length, const int fd); static void releaseDictBuf(const void *dictBuf, const size_t length, const int fd);
static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object, jstring sourceDir, static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object, jstring sourceDir,
jlong dictOffset, jlong dictSize, jint maxWordLength, jint maxWords, jint maxPredictions) { jlong dictOffset, jlong dictSize, jint maxWordLength) {
PROF_OPEN; PROF_OPEN;
PROF_START(66); PROF_START(66);
const jsize sourceDirUtf8Length = env->GetStringUTFLength(sourceDir); const jsize sourceDirUtf8Length = env->GetStringUTFLength(sourceDir);
@ -117,8 +117,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object, jstring
releaseDictBuf(dictBuf, 0, 0); releaseDictBuf(dictBuf, 0, 0);
#endif // USE_MMAP_FOR_DICTIONARY #endif // USE_MMAP_FOR_DICTIONARY
} else { } else {
dictionary = new Dictionary(dictBuf, static_cast<int>(dictSize), fd, adjust, maxWordLength, dictionary = new Dictionary(dictBuf, static_cast<int>(dictSize), fd, adjust, maxWordLength);
maxWords, maxPredictions);
} }
PROF_END(66); PROF_END(66);
PROF_CLOSE; PROF_CLOSE;
@ -163,6 +162,14 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object,
const jsize outputCodePointsLength = env->GetArrayLength(outputCodePointsArray); const jsize outputCodePointsLength = env->GetArrayLength(outputCodePointsArray);
int outputCodePoints[outputCodePointsLength]; int outputCodePoints[outputCodePointsLength];
const jsize scoresLength = env->GetArrayLength(scoresArray); const jsize scoresLength = env->GetArrayLength(scoresArray);
/* By the way, let's check the output array length here to make sure */
if (scoresLength < MAX_RESULTS) {
ASSERT(false);
return 0;
}
// Cont'd: Output values
int scores[scoresLength]; int scores[scoresLength];
const jsize spaceIndicesLength = env->GetArrayLength(spaceIndicesArray); const jsize spaceIndicesLength = env->GetArrayLength(spaceIndicesArray);
int spaceIndices[spaceIndicesLength]; int spaceIndices[spaceIndicesLength];
@ -270,7 +277,7 @@ static void releaseDictBuf(const void *dictBuf, const size_t length, const int f
} }
static JNINativeMethod sMethods[] = { static JNINativeMethod sMethods[] = {
{"openNative", "(Ljava/lang/String;JJIII)J", {"openNative", "(Ljava/lang/String;JJI)J",
reinterpret_cast<void *>(latinime_BinaryDictionary_open)}, reinterpret_cast<void *>(latinime_BinaryDictionary_open)},
{"closeNative", "(J)V", reinterpret_cast<void *>(latinime_BinaryDictionary_close)}, {"closeNative", "(J)V", reinterpret_cast<void *>(latinime_BinaryDictionary_close)},
{"getSuggestionsNative", "(JJJ[I[I[I[I[IIIZ[IZ[I[I[I[I)I", {"getSuggestionsNative", "(JJJ[I[I[I[I[IIIZ[IZ[I[I[I[I)I",

View File

@ -26,8 +26,8 @@
namespace latinime { namespace latinime {
BigramDictionary::BigramDictionary(const unsigned char *dict, int maxWordLength, int maxPredictions) BigramDictionary::BigramDictionary(const unsigned char *dict, int maxWordLength)
: DICT(dict), MAX_WORD_LENGTH(maxWordLength), MAX_PREDICTIONS(maxPredictions) { : DICT(dict), MAX_WORD_LENGTH(maxWordLength) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
AKLOGI("BigramDictionary - constructor"); AKLOGI("BigramDictionary - constructor");
} }
@ -36,7 +36,7 @@ BigramDictionary::BigramDictionary(const unsigned char *dict, int maxWordLength,
BigramDictionary::~BigramDictionary() { BigramDictionary::~BigramDictionary() {
} }
bool BigramDictionary::addWordBigram(int *word, int length, int frequency, int *bigramFreq, void BigramDictionary::addWordBigram(int *word, int length, int frequency, int *bigramFreq,
int *bigramCodePoints, int *outputTypes) const { int *bigramCodePoints, int *outputTypes) const {
word[length] = 0; word[length] = 0;
if (DEBUG_DICT) { if (DEBUG_DICT) {
@ -49,7 +49,7 @@ bool BigramDictionary::addWordBigram(int *word, int length, int frequency, int *
// Find the right insertion point // Find the right insertion point
int insertAt = 0; int insertAt = 0;
while (insertAt < MAX_PREDICTIONS) { while (insertAt < MAX_RESULTS) {
if (frequency > bigramFreq[insertAt] || (bigramFreq[insertAt] == frequency if (frequency > bigramFreq[insertAt] || (bigramFreq[insertAt] == frequency
&& length < Dictionary::wideStrLen( && length < Dictionary::wideStrLen(
bigramCodePoints + insertAt * MAX_WORD_LENGTH))) { bigramCodePoints + insertAt * MAX_WORD_LENGTH))) {
@ -58,28 +58,27 @@ bool BigramDictionary::addWordBigram(int *word, int length, int frequency, int *
insertAt++; insertAt++;
} }
if (DEBUG_DICT) { if (DEBUG_DICT) {
AKLOGI("Bigram: InsertAt -> %d MAX_PREDICTIONS: %d", insertAt, MAX_PREDICTIONS); AKLOGI("Bigram: InsertAt -> %d MAX_RESULTS: %d", insertAt, MAX_RESULTS);
} }
if (insertAt < MAX_PREDICTIONS) { if (insertAt >= MAX_RESULTS) {
memmove(bigramFreq + (insertAt + 1), return;
bigramFreq + insertAt, }
(MAX_PREDICTIONS - insertAt - 1) * sizeof(bigramFreq[0])); memmove(bigramFreq + (insertAt + 1),
bigramFreq[insertAt] = frequency; bigramFreq + insertAt,
outputTypes[insertAt] = Dictionary::KIND_PREDICTION; (MAX_RESULTS - insertAt - 1) * sizeof(bigramFreq[0]));
memmove(bigramCodePoints + (insertAt + 1) * MAX_WORD_LENGTH, bigramFreq[insertAt] = frequency;
bigramCodePoints + insertAt * MAX_WORD_LENGTH, outputTypes[insertAt] = Dictionary::KIND_PREDICTION;
(MAX_PREDICTIONS - insertAt - 1) * sizeof(bigramCodePoints[0]) * MAX_WORD_LENGTH); memmove(bigramCodePoints + (insertAt + 1) * MAX_WORD_LENGTH,
int *dest = bigramCodePoints + insertAt * MAX_WORD_LENGTH; bigramCodePoints + insertAt * MAX_WORD_LENGTH,
while (length--) { (MAX_RESULTS - insertAt - 1) * sizeof(bigramCodePoints[0]) * MAX_WORD_LENGTH);
*dest++ = *word++; int *dest = bigramCodePoints + insertAt * MAX_WORD_LENGTH;
} while (length--) {
*dest = 0; // NULL terminate *dest++ = *word++;
if (DEBUG_DICT) { }
AKLOGI("Bigram: Added word at %d", insertAt); *dest = 0; // NULL terminate
} if (DEBUG_DICT) {
return true; AKLOGI("Bigram: Added word at %d", insertAt);
} }
return false;
} }
/* Parameters : /* Parameters :
@ -135,13 +134,12 @@ int BigramDictionary::getBigrams(const int *prevWord, int prevWordLength, int *i
// here, but it can't get too bad. // here, but it can't get too bad.
const int frequency = const int frequency =
BinaryFormat::computeFrequencyForBigram(unigramFreq, bigramFreqTemp); BinaryFormat::computeFrequencyForBigram(unigramFreq, bigramFreqTemp);
if (addWordBigram(bigramBuffer, length, frequency, bigramFreq, bigramCodePoints, addWordBigram(bigramBuffer, length, frequency, bigramFreq, bigramCodePoints,
outputTypes)) { outputTypes);
++bigramCount; ++bigramCount;
}
} }
} while (BinaryFormat::FLAG_ATTRIBUTE_HAS_NEXT & bigramFlags); } while (BinaryFormat::FLAG_ATTRIBUTE_HAS_NEXT & bigramFlags);
return bigramCount; return min(bigramCount, MAX_RESULTS);
} }
// Returns a pointer to the start of the bigram list. // Returns a pointer to the start of the bigram list.

View File

@ -26,7 +26,7 @@ namespace latinime {
class BigramDictionary { class BigramDictionary {
public: public:
BigramDictionary(const unsigned char *dict, int maxWordLength, int maxPredictions); BigramDictionary(const unsigned char *dict, int maxWordLength);
int getBigrams(const int *word, int length, int *inputCodes, int codesSize, int *outWords, int getBigrams(const int *word, int length, int *inputCodes, int codesSize, int *outWords,
int *frequencies, int *outputTypes) const; int *frequencies, int *outputTypes) const;
void fillBigramAddressToFrequencyMapAndFilter(const int *prevWord, const int prevWordLength, void fillBigramAddressToFrequencyMapAndFilter(const int *prevWord, const int prevWordLength,
@ -35,7 +35,7 @@ class BigramDictionary {
~BigramDictionary(); ~BigramDictionary();
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(BigramDictionary); DISALLOW_IMPLICIT_CONSTRUCTORS(BigramDictionary);
bool addWordBigram(int *word, int length, int frequency, int *bigramFreq, int *bigramCodePoints, void addWordBigram(int *word, int length, int frequency, int *bigramFreq, int *bigramCodePoints,
int *outputTypes) const; int *outputTypes) const;
int getBigramAddress(int *pos, bool advance); int getBigramAddress(int *pos, bool advance);
int getBigramFreq(int *pos); int getBigramFreq(int *pos);
@ -48,7 +48,6 @@ class BigramDictionary {
const unsigned char *DICT; const unsigned char *DICT;
const int MAX_WORD_LENGTH; const int MAX_WORD_LENGTH;
const int MAX_PREDICTIONS;
// TODO: Re-implement proximity correction for bigram correction // TODO: Re-implement proximity correction for bigram correction
static const int MAX_ALTERNATIVES = 1; static const int MAX_ALTERNATIVES = 1;
}; };

View File

@ -347,13 +347,8 @@ static inline void prof_out(void) {
#define SUPPRESS_SHORT_MULTIPLE_WORDS_THRESHOLD_FREQ (MAX_FREQ * 58 / 100) #define SUPPRESS_SHORT_MULTIPLE_WORDS_THRESHOLD_FREQ (MAX_FREQ * 58 / 100)
#define MAX_DEPTH_MULTIPLIER 3 #define MAX_DEPTH_MULTIPLIER 3
#define FIRST_WORD_INDEX 0 #define FIRST_WORD_INDEX 0
#define MAX_RESULTS 18 /* Must be identical to BinaryDictionary.MAX_RESULTS in Java */
#define MAX_SPACES_INTERNAL 16
// TODO: Change this to MAX_WORDS, remove MAX_WORDS in Java, and stop getting it from Java
#define MAX_WORDS_INTERNAL 18
// Max Distance between point to key // Max Distance between point to key
#define MAX_POINT_TO_KEY_LENGTH 10000000 #define MAX_POINT_TO_KEY_LENGTH 10000000

View File

@ -28,15 +28,14 @@
namespace latinime { namespace latinime {
Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int maxWordLength, Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int maxWordLength)
int maxWords, int maxPredictions)
: mDict(static_cast<unsigned char *>(dict)), : mDict(static_cast<unsigned char *>(dict)),
mOffsetDict((static_cast<unsigned char *>(dict)) + BinaryFormat::getHeaderSize(mDict)), mOffsetDict((static_cast<unsigned char *>(dict)) + BinaryFormat::getHeaderSize(mDict)),
mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust), mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust),
mUnigramDictionary(new UnigramDictionary(mOffsetDict, maxWordLength, maxWords, mUnigramDictionary(new UnigramDictionary(mOffsetDict, maxWordLength,
BinaryFormat::getFlags(mDict))), BinaryFormat::getFlags(mDict))),
mBigramDictionary(new BigramDictionary(mOffsetDict, maxWordLength, maxPredictions)), mBigramDictionary(new BigramDictionary(mOffsetDict, maxWordLength)),
mGestureSuggest(new GestureSuggest(maxWordLength, maxWords)) { mGestureSuggest(new GestureSuggest(maxWordLength)) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
if (MAX_WORD_LENGTH_INTERNAL < maxWordLength) { if (MAX_WORD_LENGTH_INTERNAL < maxWordLength) {
AKLOGI("Max word length (%d) is greater than %d", AKLOGI("Max word length (%d) is greater than %d",

View File

@ -41,8 +41,7 @@ class Dictionary {
const static int KIND_SHORTCUT = 7; // A shortcut const static int KIND_SHORTCUT = 7; // A shortcut
const static int KIND_PREDICTION = 8; // A prediction (== a suggestion with no input) const static int KIND_PREDICTION = 8; // A prediction (== a suggestion with no input)
Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int maxWordLength, Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int maxWordLength);
int maxWords, int maxPredictions);
int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates, int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates,
int *ycoordinates, int *times, int *pointerIds, int *codes, int codesSize, int *ycoordinates, int *times, int *pointerIds, int *codes, int codesSize,

View File

@ -17,7 +17,7 @@
#include "gesture_suggest.h" #include "gesture_suggest.h"
namespace latinime { namespace latinime {
SuggestInterface *(*GestureSuggest::sGestureSuggestFactoryMethod)(int, int) = 0; SuggestInterface *(*GestureSuggest::sGestureSuggestFactoryMethod)(int) = 0;
GestureSuggest::~GestureSuggest() { GestureSuggest::~GestureSuggest() {
delete mSuggestInterface; delete mSuggestInterface;

View File

@ -26,8 +26,8 @@ class ProximityInfo;
class GestureSuggest : public SuggestInterface { class GestureSuggest : public SuggestInterface {
public: public:
GestureSuggest(const int maxWordLength, const int maxWords) GestureSuggest(const int maxWordLength)
: mSuggestInterface(getGestureSuggestInstance(maxWordLength, maxWords)) { : mSuggestInterface(getGestureSuggestInstance(maxWordLength)) {
} }
virtual ~GestureSuggest(); virtual ~GestureSuggest();
@ -43,20 +43,20 @@ class GestureSuggest : public SuggestInterface {
outputTypes); outputTypes);
} }
static void setGestureSuggestFactoryMethod(SuggestInterface *(*factoryMethod)(int, int)) { static void setGestureSuggestFactoryMethod(SuggestInterface *(*factoryMethod)(int)) {
sGestureSuggestFactoryMethod = factoryMethod; sGestureSuggestFactoryMethod = factoryMethod;
} }
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(GestureSuggest); DISALLOW_IMPLICIT_CONSTRUCTORS(GestureSuggest);
static SuggestInterface *getGestureSuggestInstance(int maxWordLength, int maxWords) { static SuggestInterface *getGestureSuggestInstance(int maxWordLength) {
if (!sGestureSuggestFactoryMethod) { if (!sGestureSuggestFactoryMethod) {
return 0; return 0;
} }
return sGestureSuggestFactoryMethod(maxWordLength, maxWords); return sGestureSuggestFactoryMethod(maxWordLength);
} }
static SuggestInterface *(*sGestureSuggestFactoryMethod)(int, int); static SuggestInterface *(*sGestureSuggestFactoryMethod)(int);
SuggestInterface *mSuggestInterface; SuggestInterface *mSuggestInterface;
}; };
} // namespace latinime } // namespace latinime

View File

@ -17,7 +17,7 @@
#include "typing_suggest.h" #include "typing_suggest.h"
namespace latinime { namespace latinime {
SuggestInterface *(*TypingSuggest::sTypingSuggestFactoryMethod)(int, int) = 0; SuggestInterface *(*TypingSuggest::sTypingSuggestFactoryMethod)(int) = 0;
TypingSuggest::~TypingSuggest() { TypingSuggest::~TypingSuggest() {
delete mSuggestInterface; delete mSuggestInterface;

View File

@ -26,8 +26,8 @@ class ProximityInfo;
class TypingSuggest : public SuggestInterface { class TypingSuggest : public SuggestInterface {
public: public:
TypingSuggest(const int maxWordLength, const int maxWords) TypingSuggest(const int maxWordLength)
: mSuggestInterface(getTypingSuggestInstance(maxWordLength, maxWords)) { : mSuggestInterface(getTypingSuggestInstance(maxWordLength)) {
} }
virtual ~TypingSuggest(); virtual ~TypingSuggest();
@ -43,20 +43,20 @@ class TypingSuggest : public SuggestInterface {
outputTypes); outputTypes);
} }
static void setTypingSuggestFactoryMethod(SuggestInterface *(*factoryMethod)(int, int)) { static void setTypingSuggestFactoryMethod(SuggestInterface *(*factoryMethod)(int)) {
sTypingSuggestFactoryMethod = factoryMethod; sTypingSuggestFactoryMethod = factoryMethod;
} }
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(TypingSuggest); DISALLOW_IMPLICIT_CONSTRUCTORS(TypingSuggest);
static SuggestInterface *getTypingSuggestInstance(int maxWordLength, int maxWords) { static SuggestInterface *getTypingSuggestInstance(int maxWordLength) {
if (!sTypingSuggestFactoryMethod) { if (!sTypingSuggestFactoryMethod) {
return 0; return 0;
} }
return sTypingSuggestFactoryMethod(maxWordLength, maxWords); return sTypingSuggestFactoryMethod(maxWordLength);
} }
static SuggestInterface *(*sTypingSuggestFactoryMethod)(int, int); static SuggestInterface *(*sTypingSuggestFactoryMethod)(int);
SuggestInterface *mSuggestInterface; SuggestInterface *mSuggestInterface;
}; };
} // namespace latinime } // namespace latinime

View File

@ -41,9 +41,9 @@ const UnigramDictionary::digraph_t UnigramDictionary::FRENCH_LIGATURES_DIGRAPHS[
// TODO: check the header // TODO: check the header
UnigramDictionary::UnigramDictionary(const uint8_t *const streamStart, int maxWordLength, UnigramDictionary::UnigramDictionary(const uint8_t *const streamStart, int maxWordLength,
int maxWords, const unsigned int flags) const unsigned int flags)
: DICT_ROOT(streamStart), MAX_WORD_LENGTH(maxWordLength), MAX_WORDS(maxWords), : DICT_ROOT(streamStart), MAX_WORD_LENGTH(maxWordLength), ROOT_POS(0),
ROOT_POS(0), MAX_DIGRAPH_SEARCH_DEPTH(DEFAULT_MAX_DIGRAPH_SEARCH_DEPTH), FLAGS(flags) { MAX_DIGRAPH_SEARCH_DEPTH(DEFAULT_MAX_DIGRAPH_SEARCH_DEPTH), FLAGS(flags) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
AKLOGI("UnigramDictionary - constructor"); AKLOGI("UnigramDictionary - constructor");
} }
@ -170,7 +170,7 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo, const int *x
const int *ycoordinates, const int *codes, const int codesSize, const int *ycoordinates, const int *codes, const int codesSize,
const std::map<int, int> *bigramMap, const uint8_t *bigramFilter, const std::map<int, int> *bigramMap, const uint8_t *bigramFilter,
const bool useFullEditDistance, int *outWords, int *frequencies, int *outputTypes) const { const bool useFullEditDistance, int *outWords, int *frequencies, int *outputTypes) const {
WordsPriorityQueuePool queuePool(MAX_WORDS, SUB_QUEUE_MAX_WORDS, MAX_WORD_LENGTH); WordsPriorityQueuePool queuePool(MAX_RESULTS, SUB_QUEUE_MAX_WORDS, MAX_WORD_LENGTH);
queuePool.clearAll(); queuePool.clearAll();
Correction masterCorrection; Correction masterCorrection;
masterCorrection.resetCorrection(); masterCorrection.resetCorrection();

View File

@ -39,7 +39,7 @@ class UnigramDictionary {
static const int FLAG_MULTIPLE_SUGGEST_ABORT = 0; static const int FLAG_MULTIPLE_SUGGEST_ABORT = 0;
static const int FLAG_MULTIPLE_SUGGEST_SKIP = 1; static const int FLAG_MULTIPLE_SUGGEST_SKIP = 1;
static const int FLAG_MULTIPLE_SUGGEST_CONTINUE = 2; static const int FLAG_MULTIPLE_SUGGEST_CONTINUE = 2;
UnigramDictionary(const uint8_t *const streamStart, int maxWordLength, int maxWords, UnigramDictionary(const uint8_t *const streamStart, int maxWordLength,
const unsigned int flags); const unsigned int flags);
int getFrequency(const int *const inWord, const int length) const; int getFrequency(const int *const inWord, const int length) const;
int getBigramPosition(int pos, int *word, int offset, int length) const; int getBigramPosition(int pos, int *word, int offset, int length) const;
@ -110,7 +110,6 @@ class UnigramDictionary {
const uint8_t *const DICT_ROOT; const uint8_t *const DICT_ROOT;
const int MAX_WORD_LENGTH; const int MAX_WORD_LENGTH;
const int MAX_WORDS;
const int ROOT_POS; const int ROOT_POS;
const int MAX_DIGRAPH_SEARCH_DEPTH; const int MAX_DIGRAPH_SEARCH_DEPTH;
const int FLAGS; const int FLAGS;