Merge "Generalize incremental recognition to non-Latin languages" into jb-mr1-dev

main
Tom Ouyang 2012-09-13 02:26:53 -07:00 committed by Android (Google) Code Review
commit 0e301bdc29
3 changed files with 11 additions and 30 deletions

View File

@ -67,7 +67,8 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, const int ma
&& keyWidths && keyHeights && keyCharCodes && sweetSpotCenterXs
&& sweetSpotCenterYs && sweetSpotRadii),
mProximityCharsArray(new int32_t[GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE
/* proximityGridLength */]) {
/* proximityGridLength */]),
mCodeToKeyMap() {
const int proximityGridLength = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE;
if (DEBUG_PROXIMITY_INFO) {
AKLOGI("Create proximity info array %d", proximityGridLength);
@ -88,22 +89,9 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, const int ma
safeGetOrFillZeroFloatArrayRegion(env, sweetSpotCenterXs, KEY_COUNT, mSweetSpotCenterXs);
safeGetOrFillZeroFloatArrayRegion(env, sweetSpotCenterYs, KEY_COUNT, mSweetSpotCenterYs);
safeGetOrFillZeroFloatArrayRegion(env, sweetSpotRadii, KEY_COUNT, mSweetSpotRadii);
initializeCodePointToKeyIndex();
initializeG();
}
// Build the reversed look up table from the char code to the index in mKeyXCoordinates,
// mKeyYCoordinates, mKeyWidths, mKeyHeights, mKeyCharCodes.
void ProximityInfo::initializeCodePointToKeyIndex() {
memset(mCodePointToKeyIndex, -1, sizeof(mCodePointToKeyIndex));
for (int i = 0; i < KEY_COUNT; ++i) {
const int code = mKeyCodePoints[i];
if (0 <= code && code <= MAX_CHAR_CODE) {
mCodePointToKeyIndex[code] = i;
}
}
}
ProximityInfo::~ProximityInfo() {
delete[] mProximityCharsArray;
}
@ -239,11 +227,12 @@ int ProximityInfo::getKeyIndexOf(const int c) const {
// We do not have the coordinate data
return NOT_AN_INDEX;
}
const unsigned short baseLowerC = toBaseLowerCase(c);
if (baseLowerC > MAX_CHAR_CODE) {
return NOT_AN_INDEX;
const int baseLowerC = static_cast<int>(toBaseLowerCase(c));
hash_map_compat<int, int>::const_iterator mapPos = mCodeToKeyMap.find(baseLowerC);
if (mapPos != mCodeToKeyMap.end()) {
return mapPos->second;
}
return mCodePointToKeyIndex[baseLowerC];
return NOT_AN_INDEX;
}
int ProximityInfo::getCodePointOf(const int keyIndex) const {
@ -260,12 +249,8 @@ void ProximityInfo::initializeG() {
const int lowerCode = toBaseLowerCase(code);
mCenterXsG[i] = mKeyXCoordinates[i] + mKeyWidths[i] / 2;
mCenterYsG[i] = mKeyYCoordinates[i] + mKeyHeights[i] / 2;
if (code != lowerCode && lowerCode >= 0 && lowerCode <= MAX_CHAR_CODE) {
mCodePointToKeyIndex[lowerCode] = i;
mKeyIndexToCodePointG[i] = lowerCode;
} else {
mKeyIndexToCodePointG[i] = code;
}
mCodeToKeyMap[lowerCode] = i;
mKeyIndexToCodePointG[i] = lowerCode;
}
for (int i = 0; i < KEY_COUNT; i++) {
mKeyKeyDistancesG[i][i] = 0;

View File

@ -20,6 +20,7 @@
#include <stdint.h>
#include "defines.h"
#include "hash_map_compat.h"
#include "jni.h"
namespace latinime {
@ -112,12 +113,9 @@ class ProximityInfo {
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfo);
// The upper limit of the char code in mCodePointToKeyIndex
static const int MAX_CHAR_CODE = 127;
static const float NOT_A_DISTANCE_FLOAT;
int getStartIndexFromCoordinates(const int x, const int y) const;
void initializeCodePointToKeyIndex();
void initializeG();
float calculateNormalizedSquaredDistance(const int keyIndex, const int inputIndex) const;
float calculateSquaredDistanceFromSweetSpotCenter(
@ -154,7 +152,7 @@ class ProximityInfo {
float mSweetSpotCenterXs[MAX_KEY_COUNT_IN_A_KEYBOARD];
float mSweetSpotCenterYs[MAX_KEY_COUNT_IN_A_KEYBOARD];
float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD];
int mCodePointToKeyIndex[MAX_CHAR_CODE + 1];
hash_map_compat<int, int> mCodeToKeyMap;
int mKeyIndexToCodePointG[MAX_KEY_COUNT_IN_A_KEYBOARD];
int mCenterXsG[MAX_KEY_COUNT_IN_A_KEYBOARD];

View File

@ -37,8 +37,6 @@ class ProximityInfoState {
static const int NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2 = 10;
static const int NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR =
1 << NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2;
// The upper limit of the char code in mCodeToKeyIndex
static const int MAX_CHAR_CODE = 127;
static const float NOT_A_DISTANCE_FLOAT = -1.0f;
static const int NOT_A_CODE = -1;