am 604599c3: Merge "Fetch and pass the bigram position on suggestions." into jb-dev

* commit '604599c38913cc1cce38cf5f5b018b5507cf3766':
  Fetch and pass the bigram position on suggestions.
main
Jean Chalard 2012-04-26 00:28:35 -07:00 committed by Android Git Automerger
commit b096e3f589
4 changed files with 18 additions and 16 deletions

View File

@ -137,13 +137,15 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object,
int *frequencies = env->GetIntArrayElements(frequencyArray, 0);
int *inputCodes = env->GetIntArrayElements(inputArray, 0);
jchar *outputChars = env->GetCharArrayElements(outputArray, 0);
// Deactivated to prevent unused variable errors.
// TODO: use the following variables.
// jint *prevWordChars = prevWordForBigrams
// ? env->GetIntArrayElements(prevWordForBigrams, 0) : NULL;
// jsize prevWordLength = prevWordChars ? env->GetArrayLength(prevWordForBigrams) : 0;
jint *prevWordChars = prevWordForBigrams
? env->GetIntArrayElements(prevWordForBigrams, 0) : 0;
jsize prevWordLength = prevWordChars ? env->GetArrayLength(prevWordForBigrams) : 0;
int count = dictionary->getSuggestions(pInfo, xCoordinates, yCoordinates, inputCodes,
arraySize, useFullEditDistance, (unsigned short*) outputChars, frequencies);
arraySize, prevWordChars, prevWordLength, useFullEditDistance,
(unsigned short*) outputChars, frequencies);
if (prevWordChars) {
env->ReleaseIntArrayElements(prevWordForBigrams, prevWordChars, JNI_ABORT);
}
env->ReleaseCharArrayElements(outputArray, outputChars, 0);
env->ReleaseIntArrayElements(inputArray, inputCodes, JNI_ABORT);
env->ReleaseIntArrayElements(frequencyArray, frequencies, 0);

View File

@ -107,8 +107,8 @@ int BigramDictionary::getBigrams(const int32_t *prevWord, int prevWordLength, in
mMaxBigrams = maxBigrams;
const uint8_t* const root = DICT;
int pos = getBigramListForWord(root, prevWord, prevWordLength);
// getBigramListForWord returns 0 if this word is not in the dictionary or has no bigrams
int pos = getBigramListPositionForWord(prevWord, prevWordLength);
// getBigramListPositionForWord returns 0 if this word isn't in the dictionary or has no bigrams
if (0 == pos) return 0;
int bigramFlags;
int bigramCount = 0;
@ -133,8 +133,9 @@ int BigramDictionary::getBigrams(const int32_t *prevWord, int prevWordLength, in
// Returns a pointer to the start of the bigram list.
// If the word is not found or has no bigrams, this function returns 0.
int BigramDictionary::getBigramListForWord(const uint8_t* const root,
const int32_t *prevWord, const int prevWordLength) {
int BigramDictionary::getBigramListPositionForWord(const int32_t *prevWord,
const int prevWordLength) {
const uint8_t* const root = DICT;
int pos = BinaryFormat::getTerminalPosition(root, prevWord, prevWordLength);
if (NOT_VALID_WORD == pos) return 0;

View File

@ -27,8 +27,7 @@ class BigramDictionary {
BigramDictionary(const unsigned char *dict, int maxWordLength, Dictionary *parentDictionary);
int getBigrams(const int32_t *word, int length, int *codes, int codesSize,
unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams);
int getBigramListForWord(const uint8_t* const root,
const int32_t *prevWord, const int prevWordLength);
int getBigramListPositionForWord(const int32_t *prevWord, const int prevWordLength);
~BigramDictionary();
private:
bool addWordBigram(unsigned short *word, int length, int frequency);

View File

@ -33,12 +33,12 @@ class Dictionary {
int fullWordMultiplier, int maxWordLength, int maxWords);
int getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates,
int *codes, int codesSize, bool useFullEditDistance, unsigned short *outWords,
int *frequencies) {
int *codes, int codesSize, const int32_t* prevWordChars, const int prevWordLength,
bool useFullEditDistance, unsigned short *outWords, int *frequencies) {
// bigramListPosition is, as an int, the offset of the bigram list in the file.
// If none, it's zero.
// TODO: get this from the bigram dictionary instance
const int bigramListPosition = 0;
const int bigramListPosition = !prevWordChars ? 0
: mBigramDictionary->getBigramListPositionForWord(prevWordChars, prevWordLength);
return mUnigramDictionary->getSuggestions(proximityInfo, mWordsPriorityQueuePool,
mCorrection, xcoordinates, ycoordinates, codes, codesSize, bigramListPosition,
useFullEditDistance, outWords, frequencies);