Merge "Fix additional proximity in the native code"

This commit is contained in:
satok 2012-03-13 20:26:22 -07:00 committed by Android (Google) Code Review
commit 6338b9f2c6
6 changed files with 83 additions and 39 deletions

View file

@ -50,7 +50,7 @@ static jlong latinime_Keyboard_setProximityInfo(JNIEnv *env, jobject object,
ProximityInfo *proximityInfo = new ProximityInfo( ProximityInfo *proximityInfo = new ProximityInfo(
localeStr, maxProximityCharsSize, displayWidth, localeStr, maxProximityCharsSize, displayWidth,
displayHeight, gridWidth, gridHeight, mostCommonkeyWidth, displayHeight, gridWidth, gridHeight, mostCommonkeyWidth,
(const uint32_t*)proximityChars, (const int32_t*)proximityChars,
keyCount, (const int32_t*)keyXCoordinates, (const int32_t*)keyYCoordinates, keyCount, (const int32_t*)keyXCoordinates, (const int32_t*)keyYCoordinates,
(const int32_t*)keyWidths, (const int32_t*)keyHeights, (const int32_t*)keyCharCodes, (const int32_t*)keyWidths, (const int32_t*)keyHeights, (const int32_t*)keyCharCodes,
(const float*)sweetSpotCenterXs, (const float*)sweetSpotCenterYs, (const float*)sweetSpotCenterXs, (const float*)sweetSpotCenterYs,

View file

@ -19,23 +19,23 @@
namespace latinime { namespace latinime {
const std::string AdditionalProximityChars::LOCALE_EN_US("en"); const std::string AdditionalProximityChars::LOCALE_EN_US("en");
const uint32_t AdditionalProximityChars::EN_US_ADDITIONAL_A[EN_US_ADDITIONAL_A_SIZE] = { const int32_t AdditionalProximityChars::EN_US_ADDITIONAL_A[EN_US_ADDITIONAL_A_SIZE] = {
'e', 'i', 'o', 'u' 'e', 'i', 'o', 'u'
}; };
const uint32_t AdditionalProximityChars::EN_US_ADDITIONAL_E[EN_US_ADDITIONAL_E_SIZE] = { const int32_t AdditionalProximityChars::EN_US_ADDITIONAL_E[EN_US_ADDITIONAL_E_SIZE] = {
'a', 'i', 'o', 'u' 'a', 'i', 'o', 'u'
}; };
const uint32_t AdditionalProximityChars::EN_US_ADDITIONAL_I[EN_US_ADDITIONAL_I_SIZE] = { const int32_t AdditionalProximityChars::EN_US_ADDITIONAL_I[EN_US_ADDITIONAL_I_SIZE] = {
'a', 'e', 'o', 'u' 'a', 'e', 'o', 'u'
}; };
const uint32_t AdditionalProximityChars::EN_US_ADDITIONAL_O[EN_US_ADDITIONAL_O_SIZE] = { const int32_t AdditionalProximityChars::EN_US_ADDITIONAL_O[EN_US_ADDITIONAL_O_SIZE] = {
'a', 'e', 'i', 'u' 'a', 'e', 'i', 'u'
}; };
const uint32_t AdditionalProximityChars::EN_US_ADDITIONAL_U[EN_US_ADDITIONAL_U_SIZE] = { const int32_t AdditionalProximityChars::EN_US_ADDITIONAL_U[EN_US_ADDITIONAL_U_SIZE] = {
'a', 'e', 'i', 'o' 'a', 'e', 'i', 'o'
}; };
} }

View file

@ -20,29 +20,31 @@
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include "defines.h"
namespace latinime { namespace latinime {
class AdditionalProximityChars { class AdditionalProximityChars {
private: private:
static const std::string LOCALE_EN_US; static const std::string LOCALE_EN_US;
static const int EN_US_ADDITIONAL_A_SIZE = 4; static const int EN_US_ADDITIONAL_A_SIZE = 4;
static const uint32_t EN_US_ADDITIONAL_A[]; static const int32_t EN_US_ADDITIONAL_A[];
static const int EN_US_ADDITIONAL_E_SIZE = 4; static const int EN_US_ADDITIONAL_E_SIZE = 4;
static const uint32_t EN_US_ADDITIONAL_E[]; static const int32_t EN_US_ADDITIONAL_E[];
static const int EN_US_ADDITIONAL_I_SIZE = 4; static const int EN_US_ADDITIONAL_I_SIZE = 4;
static const uint32_t EN_US_ADDITIONAL_I[]; static const int32_t EN_US_ADDITIONAL_I[];
static const int EN_US_ADDITIONAL_O_SIZE = 4; static const int EN_US_ADDITIONAL_O_SIZE = 4;
static const uint32_t EN_US_ADDITIONAL_O[]; static const int32_t EN_US_ADDITIONAL_O[];
static const int EN_US_ADDITIONAL_U_SIZE = 4; static const int EN_US_ADDITIONAL_U_SIZE = 4;
static const uint32_t EN_US_ADDITIONAL_U[]; static const int32_t EN_US_ADDITIONAL_U[];
static bool isEnLocale(const std::string* locale_str) { static bool isEnLocale(const std::string *locale_str) {
return locale_str && locale_str->size() >= LOCALE_EN_US.size() return locale_str && locale_str->size() >= LOCALE_EN_US.size()
&& locale_str->compare(0, LOCALE_EN_US.size(), LOCALE_EN_US); && LOCALE_EN_US.compare(0, LOCALE_EN_US.size(), *locale_str);
} }
public: public:
static int getAdditionalCharsSize(const std::string* locale_str, const uint16_t c) { static int getAdditionalCharsSize(const std::string* locale_str, const int32_t c) {
if (!isEnLocale(locale_str)) { if (!isEnLocale(locale_str)) {
return 0; return 0;
} }
@ -62,7 +64,7 @@ class AdditionalProximityChars {
} }
} }
static const uint32_t* getAdditionalChars(const std::string* locale_str, const uint32_t c) { static const int32_t* getAdditionalChars(const std::string *locale_str, const int32_t c) {
if (!isEnLocale(locale_str)) { if (!isEnLocale(locale_str)) {
return 0; return 0;
} }
@ -82,7 +84,7 @@ class AdditionalProximityChars {
} }
} }
static bool hasAdditionalChars(const std::string* locale_str, const uint32_t c) { static bool hasAdditionalChars(const std::string *locale_str, const int32_t c) {
return getAdditionalCharsSize(locale_str, c) > 0; return getAdditionalCharsSize(locale_str, c) > 0;
} }
}; };

View file

@ -115,6 +115,7 @@ static inline void prof_out(void) {
#define DEBUG_NODE DEBUG_DICT_FULL #define DEBUG_NODE DEBUG_DICT_FULL
#define DEBUG_TRACE DEBUG_DICT_FULL #define DEBUG_TRACE DEBUG_DICT_FULL
#define DEBUG_PROXIMITY_INFO false #define DEBUG_PROXIMITY_INFO false
#define DEBUG_PROXIMITY_CHARS false
#define DEBUG_CORRECTION false #define DEBUG_CORRECTION false
#define DEBUG_CORRECTION_FREQ false #define DEBUG_CORRECTION_FREQ false
#define DEBUG_WORDS_PRIORITY_QUEUE false #define DEBUG_WORDS_PRIORITY_QUEUE false
@ -128,6 +129,7 @@ static inline void prof_out(void) {
#define DEBUG_NODE false #define DEBUG_NODE false
#define DEBUG_TRACE false #define DEBUG_TRACE false
#define DEBUG_PROXIMITY_INFO false #define DEBUG_PROXIMITY_INFO false
#define DEBUG_PROXIMITY_CHARS false
#define DEBUG_CORRECTION false #define DEBUG_CORRECTION false
#define DEBUG_CORRECTION_FREQ false #define DEBUG_CORRECTION_FREQ false
#define DEBUG_WORDS_PRIORITY_QUEUE false #define DEBUG_WORDS_PRIORITY_QUEUE false

View file

@ -37,7 +37,7 @@ inline void copyOrFillZero(void *to, const void *from, size_t size) {
ProximityInfo::ProximityInfo(const std::string localeStr, const int maxProximityCharsSize, ProximityInfo::ProximityInfo(const std::string localeStr, const int maxProximityCharsSize,
const int keyboardWidth, const int keyboardHeight, const int gridWidth, const int keyboardWidth, const int keyboardHeight, const int gridWidth,
const int gridHeight, const int mostCommonKeyWidth, const int gridHeight, const int mostCommonKeyWidth,
const uint32_t *proximityCharsArray, const int keyCount, const int32_t *keyXCoordinates, const int32_t *proximityCharsArray, const int keyCount, const int32_t *keyXCoordinates,
const int32_t *keyYCoordinates, const int32_t *keyWidths, const int32_t *keyHeights, const int32_t *keyYCoordinates, const int32_t *keyWidths, const int32_t *keyHeights,
const int32_t *keyCharCodes, const float *sweetSpotCenterXs, const float *sweetSpotCenterYs, const int32_t *keyCharCodes, const float *sweetSpotCenterXs, const float *sweetSpotCenterYs,
const float *sweetSpotRadii) const float *sweetSpotRadii)
@ -54,7 +54,7 @@ ProximityInfo::ProximityInfo(const std::string localeStr, const int maxProximity
mInputXCoordinates(0), mInputYCoordinates(0), mInputXCoordinates(0), mInputYCoordinates(0),
mTouchPositionCorrectionEnabled(false) { mTouchPositionCorrectionEnabled(false) {
const int proximityGridLength = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE; const int proximityGridLength = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE;
mProximityCharsArray = new uint32_t[proximityGridLength]; mProximityCharsArray = new int32_t[proximityGridLength];
if (DEBUG_PROXIMITY_INFO) { if (DEBUG_PROXIMITY_INFO) {
AKLOGI("Create proximity info array %d", proximityGridLength); AKLOGI("Create proximity info array %d", proximityGridLength);
} }
@ -148,35 +148,43 @@ int ProximityInfo::squaredDistanceToEdge(const int keyId, const int x, const int
} }
void ProximityInfo::calculateNearbyKeyCodes( void ProximityInfo::calculateNearbyKeyCodes(
const int x, const int y, const uint32_t primaryKey, int *inputCodes) { const int x, const int y, const int32_t primaryKey, int *inputCodes) {
int insertPos = 0; int insertPos = 0;
inputCodes[insertPos++] = primaryKey; inputCodes[insertPos++] = primaryKey;
const int startIndex = getStartIndexFromCoordinates(x, y); const int startIndex = getStartIndexFromCoordinates(x, y);
for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) { for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) {
const uint32_t c = mProximityCharsArray[startIndex + i]; const int32_t c = mProximityCharsArray[startIndex + i];
if (c < KEYCODE_SPACE || c == primaryKey) { if (c < KEYCODE_SPACE || c == primaryKey) {
continue; continue;
} }
for (int j = 0; j < KEY_COUNT; ++j) { int keyIndex = getKeyIndex(c);
const bool onKey = isOnKey(j, x, y); const bool onKey = isOnKey(keyIndex, x, y);
const int distance = squaredDistanceToEdge(j, x, y); const int distance = squaredDistanceToEdge(keyIndex, x, y);
if (onKey || distance < MOST_COMMON_KEY_WIDTH_SQUARE) { if (onKey || distance < MOST_COMMON_KEY_WIDTH_SQUARE) {
inputCodes[insertPos++] = c; inputCodes[insertPos++] = c;
if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) {
if (DEBUG_DICT) {
assert(false);
}
return;
} }
} }
} }
const int existingProximitySize = insertPos; inputCodes[insertPos++] = ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE;
for (int i = 0; i < existingProximitySize; ++i) { if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) {
const uint32_t c = inputCodes[i]; if (DEBUG_DICT) {
const int additionalProximitySize = assert(false);
AdditionalProximityChars::hasAdditionalChars(&mLocaleStr, c);
if (additionalProximitySize <= 0) {
continue;
} }
const uint32_t* additionalProximityChars = return;
AdditionalProximityChars::getAdditionalChars(&mLocaleStr, c); }
const int additionalProximitySize =
AdditionalProximityChars::getAdditionalCharsSize(&mLocaleStr, primaryKey);
if (additionalProximitySize > 0) {
const int32_t* additionalProximityChars =
AdditionalProximityChars::getAdditionalChars(&mLocaleStr, primaryKey);
for (int j = 0; j < additionalProximitySize; ++j) { for (int j = 0; j < additionalProximitySize; ++j) {
const uint32_t ac = additionalProximityChars[j]; const int32_t ac = additionalProximityChars[j];
int k = 0; int k = 0;
for (; k < insertPos; ++k) { for (; k < insertPos; ++k) {
if ((int)ac == inputCodes[k]) { if ((int)ac == inputCodes[k]) {
@ -187,9 +195,16 @@ void ProximityInfo::calculateNearbyKeyCodes(
continue; continue;
} }
inputCodes[insertPos++] = ac; inputCodes[insertPos++] = ac;
if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) {
if (DEBUG_DICT) {
assert(false);
}
return;
}
} }
} }
// TODO: calculate additional chars // Add a delimiter for the proximity characters
inputCodes[insertPos] = 0;
} }
// TODO: Calculate nearby codes here. // TODO: Calculate nearby codes here.
@ -205,8 +220,30 @@ void ProximityInfo::setInputParams(const int* inputCodes, const int inputLength,
mPrimaryInputWord[i] = getPrimaryCharAt(i); mPrimaryInputWord[i] = getPrimaryCharAt(i);
} }
mPrimaryInputWord[inputLength] = 0; mPrimaryInputWord[inputLength] = 0;
if (DEBUG_PROXIMITY_CHARS) {
AKLOGI("--- setInputParams");
}
for (int i = 0; i < mInputLength; ++i) { for (int i = 0; i < mInputLength; ++i) {
const int *proximityChars = getProximityCharsAt(i); const int *proximityChars = getProximityCharsAt(i);
const int primaryKey = proximityChars[0];
const int x = xCoordinates[i];
const int y = yCoordinates[i];
if (DEBUG_PROXIMITY_CHARS) {
int a = x + y + primaryKey;
a += 0;
AKLOGI("--- Primary = %c, x = %d, y = %d", primaryKey, x, y);
// Keep debug code just in case
//int proximities[50];
//for (int m = 0; m < 50; ++m) {
//proximities[m] = 0;
//}
//calculateNearbyKeyCodes(x, y, primaryKey, proximities);
//for (int l = 0; l < 50 && proximities[l] > 0; ++l) {
//if (DEBUG_PROXIMITY_CHARS) {
//AKLOGI("--- native Proximity (%d) = %c", l, proximities[l]);
//}
//}
}
for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE && proximityChars[j] > 0; ++j) { for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE && proximityChars[j] > 0; ++j) {
const int currentChar = proximityChars[j]; const int currentChar = proximityChars[j];
const int keyIndex = getKeyIndex(currentChar); const int keyIndex = getKeyIndex(currentChar);
@ -219,6 +256,9 @@ void ProximityInfo::setInputParams(const int* inputCodes, const int inputLength,
? EQUIVALENT_CHAR_WITHOUT_DISTANCE_INFO ? EQUIVALENT_CHAR_WITHOUT_DISTANCE_INFO
: PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO; : PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO;
} }
if (DEBUG_PROXIMITY_CHARS) {
AKLOGI("--- Proximity (%d) = %c", j, currentChar);
}
} }
} }
} }

View file

@ -47,7 +47,7 @@ class ProximityInfo {
ProximityInfo(const std::string localeStr, const int maxProximityCharsSize, ProximityInfo(const std::string localeStr, const int maxProximityCharsSize,
const int keyboardWidth, const int keybaordHeight, const int gridWidth, const int keyboardWidth, const int keybaordHeight, const int gridWidth,
const int gridHeight, const int mostCommonkeyWidth, const int gridHeight, const int mostCommonkeyWidth,
const uint32_t *proximityCharsArray, const int keyCount, const int32_t *keyXCoordinates, const int32_t *proximityCharsArray, const int keyCount, const int32_t *keyXCoordinates,
const int32_t *keyYCoordinates, const int32_t *keyWidths, const int32_t *keyHeights, const int32_t *keyYCoordinates, const int32_t *keyWidths, const int32_t *keyHeights,
const int32_t *keyCharCodes, const float *sweetSpotCenterXs, const int32_t *keyCharCodes, const float *sweetSpotCenterXs,
const float *sweetSpotCenterYs, const float *sweetSpotRadii); const float *sweetSpotCenterYs, const float *sweetSpotRadii);
@ -92,7 +92,7 @@ class ProximityInfo {
bool isOnKey(const int keyId, const int x, const int y); bool isOnKey(const int keyId, const int x, const int y);
int squaredDistanceToEdge(const int keyId, const int x, const int y); int squaredDistanceToEdge(const int keyId, const int x, const int y);
void calculateNearbyKeyCodes( void calculateNearbyKeyCodes(
const int x, const int y, const uint32_t primaryKey, int *inputCodes); const int x, const int y, const int32_t primaryKey, int *inputCodes);
const int MAX_PROXIMITY_CHARS_SIZE; const int MAX_PROXIMITY_CHARS_SIZE;
const int KEYBOARD_WIDTH; const int KEYBOARD_WIDTH;
@ -109,7 +109,7 @@ class ProximityInfo {
const int *mInputXCoordinates; const int *mInputXCoordinates;
const int *mInputYCoordinates; const int *mInputYCoordinates;
bool mTouchPositionCorrectionEnabled; bool mTouchPositionCorrectionEnabled;
uint32_t *mProximityCharsArray; int32_t *mProximityCharsArray;
int *mNormalizedSquaredDistances; int *mNormalizedSquaredDistances;
int32_t mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD]; int32_t mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
int32_t mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD]; int32_t mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];