am 604599c3
: Merge "Fetch and pass the bigram position on suggestions." into jb-dev
* commit '604599c38913cc1cce38cf5f5b018b5507cf3766': Fetch and pass the bigram position on suggestions.
This commit is contained in:
commit
b096e3f589
4 changed files with 18 additions and 16 deletions
|
@ -137,13 +137,15 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object,
|
||||||
int *frequencies = env->GetIntArrayElements(frequencyArray, 0);
|
int *frequencies = env->GetIntArrayElements(frequencyArray, 0);
|
||||||
int *inputCodes = env->GetIntArrayElements(inputArray, 0);
|
int *inputCodes = env->GetIntArrayElements(inputArray, 0);
|
||||||
jchar *outputChars = env->GetCharArrayElements(outputArray, 0);
|
jchar *outputChars = env->GetCharArrayElements(outputArray, 0);
|
||||||
// Deactivated to prevent unused variable errors.
|
jint *prevWordChars = prevWordForBigrams
|
||||||
// TODO: use the following variables.
|
? env->GetIntArrayElements(prevWordForBigrams, 0) : 0;
|
||||||
// jint *prevWordChars = prevWordForBigrams
|
jsize prevWordLength = prevWordChars ? env->GetArrayLength(prevWordForBigrams) : 0;
|
||||||
// ? env->GetIntArrayElements(prevWordForBigrams, 0) : NULL;
|
|
||||||
// jsize prevWordLength = prevWordChars ? env->GetArrayLength(prevWordForBigrams) : 0;
|
|
||||||
int count = dictionary->getSuggestions(pInfo, xCoordinates, yCoordinates, inputCodes,
|
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->ReleaseCharArrayElements(outputArray, outputChars, 0);
|
||||||
env->ReleaseIntArrayElements(inputArray, inputCodes, JNI_ABORT);
|
env->ReleaseIntArrayElements(inputArray, inputCodes, JNI_ABORT);
|
||||||
env->ReleaseIntArrayElements(frequencyArray, frequencies, 0);
|
env->ReleaseIntArrayElements(frequencyArray, frequencies, 0);
|
||||||
|
|
|
@ -107,8 +107,8 @@ int BigramDictionary::getBigrams(const int32_t *prevWord, int prevWordLength, in
|
||||||
mMaxBigrams = maxBigrams;
|
mMaxBigrams = maxBigrams;
|
||||||
|
|
||||||
const uint8_t* const root = DICT;
|
const uint8_t* const root = DICT;
|
||||||
int pos = getBigramListForWord(root, prevWord, prevWordLength);
|
int pos = getBigramListPositionForWord(prevWord, prevWordLength);
|
||||||
// getBigramListForWord returns 0 if this word is not in the dictionary or has no bigrams
|
// getBigramListPositionForWord returns 0 if this word isn't in the dictionary or has no bigrams
|
||||||
if (0 == pos) return 0;
|
if (0 == pos) return 0;
|
||||||
int bigramFlags;
|
int bigramFlags;
|
||||||
int bigramCount = 0;
|
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.
|
// Returns a pointer to the start of the bigram list.
|
||||||
// If the word is not found or has no bigrams, this function returns 0.
|
// If the word is not found or has no bigrams, this function returns 0.
|
||||||
int BigramDictionary::getBigramListForWord(const uint8_t* const root,
|
int BigramDictionary::getBigramListPositionForWord(const int32_t *prevWord,
|
||||||
const int32_t *prevWord, const int prevWordLength) {
|
const int prevWordLength) {
|
||||||
|
const uint8_t* const root = DICT;
|
||||||
int pos = BinaryFormat::getTerminalPosition(root, prevWord, prevWordLength);
|
int pos = BinaryFormat::getTerminalPosition(root, prevWord, prevWordLength);
|
||||||
|
|
||||||
if (NOT_VALID_WORD == pos) return 0;
|
if (NOT_VALID_WORD == pos) return 0;
|
||||||
|
|
|
@ -27,8 +27,7 @@ class BigramDictionary {
|
||||||
BigramDictionary(const unsigned char *dict, int maxWordLength, Dictionary *parentDictionary);
|
BigramDictionary(const unsigned char *dict, int maxWordLength, Dictionary *parentDictionary);
|
||||||
int getBigrams(const int32_t *word, int length, int *codes, int codesSize,
|
int getBigrams(const int32_t *word, int length, int *codes, int codesSize,
|
||||||
unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams);
|
unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams);
|
||||||
int getBigramListForWord(const uint8_t* const root,
|
int getBigramListPositionForWord(const int32_t *prevWord, const int prevWordLength);
|
||||||
const int32_t *prevWord, const int prevWordLength);
|
|
||||||
~BigramDictionary();
|
~BigramDictionary();
|
||||||
private:
|
private:
|
||||||
bool addWordBigram(unsigned short *word, int length, int frequency);
|
bool addWordBigram(unsigned short *word, int length, int frequency);
|
||||||
|
|
|
@ -33,12 +33,12 @@ class Dictionary {
|
||||||
int fullWordMultiplier, int maxWordLength, int maxWords);
|
int fullWordMultiplier, int maxWordLength, int maxWords);
|
||||||
|
|
||||||
int getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates,
|
int getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates,
|
||||||
int *codes, int codesSize, bool useFullEditDistance, unsigned short *outWords,
|
int *codes, int codesSize, const int32_t* prevWordChars, const int prevWordLength,
|
||||||
int *frequencies) {
|
bool useFullEditDistance, unsigned short *outWords, int *frequencies) {
|
||||||
// bigramListPosition is, as an int, the offset of the bigram list in the file.
|
// bigramListPosition is, as an int, the offset of the bigram list in the file.
|
||||||
// If none, it's zero.
|
// If none, it's zero.
|
||||||
// TODO: get this from the bigram dictionary instance
|
const int bigramListPosition = !prevWordChars ? 0
|
||||||
const int bigramListPosition = 0;
|
: mBigramDictionary->getBigramListPositionForWord(prevWordChars, prevWordLength);
|
||||||
return mUnigramDictionary->getSuggestions(proximityInfo, mWordsPriorityQueuePool,
|
return mUnigramDictionary->getSuggestions(proximityInfo, mWordsPriorityQueuePool,
|
||||||
mCorrection, xcoordinates, ycoordinates, codes, codesSize, bigramListPosition,
|
mCorrection, xcoordinates, ycoordinates, codes, codesSize, bigramListPosition,
|
||||||
useFullEditDistance, outWords, frequencies);
|
useFullEditDistance, outWords, frequencies);
|
||||||
|
|
Loading…
Reference in a new issue