am ff745e9a: am 830ba674: refactor MAX_POINT_TO_KEY_LENGTH

* commit 'ff745e9a8adef082859dfbfa3ceeb16a0842980b':
  refactor MAX_POINT_TO_KEY_LENGTH
main
Satoshi Kataoka 2013-03-04 22:24:48 -08:00 committed by Android Git Automerger
commit 6094388f0f
6 changed files with 11 additions and 10 deletions

View File

@ -119,7 +119,7 @@ class Correction {
// proximity info state // proximity info state
void initInputParams(const ProximityInfo *proximityInfo, const int *inputCodes, void initInputParams(const ProximityInfo *proximityInfo, const int *inputCodes,
const int inputSize, const int *xCoordinates, const int *yCoordinates) { const int inputSize, const int *xCoordinates, const int *yCoordinates) {
mProximityInfoState.initInputParams(0, MAX_POINT_TO_KEY_LENGTH, mProximityInfoState.initInputParams(0, static_cast<float>(MAX_VALUE_FOR_WEIGHTING),
proximityInfo, inputCodes, inputSize, xCoordinates, yCoordinates, 0, 0, false); proximityInfo, inputCodes, inputSize, xCoordinates, yCoordinates, 0, 0, false);
} }

View File

@ -341,8 +341,9 @@ static inline void prof_out(void) {
#define MAX_DEPTH_MULTIPLIER 3 #define MAX_DEPTH_MULTIPLIER 3
#define FIRST_WORD_INDEX 0 #define FIRST_WORD_INDEX 0
// Max Distance between point to key // Max value for length, distance and probability which are used in weighting
#define MAX_POINT_TO_KEY_LENGTH 10000000 // TODO: Remove
#define MAX_VALUE_FOR_WEIGHTING 10000000
// The max number of the keys in one keyboard layout // The max number of the keys in one keyboard layout
#define MAX_KEY_COUNT_IN_A_KEYBOARD 64 #define MAX_KEY_COUNT_IN_A_KEYBOARD 64

View File

@ -204,6 +204,6 @@ int ProximityInfo::getKeyKeyDistanceG(const int keyId0, const int keyId1) const
if (keyId0 >= 0 && keyId1 >= 0) { if (keyId0 >= 0 && keyId1 >= 0) {
return mKeyKeyDistancesG[keyId0][keyId1]; return mKeyKeyDistancesG[keyId0][keyId1];
} }
return MAX_POINT_TO_KEY_LENGTH; return MAX_VALUE_FOR_WEIGHTING;
} }
} // namespace latinime } // namespace latinime

View File

@ -170,7 +170,7 @@ float ProximityInfoState::getPointToKeyLength(
return 0.0f; return 0.0f;
} }
// If the char is not a key on the keyboard then return the max length. // If the char is not a key on the keyboard then return the max length.
return MAX_POINT_TO_KEY_LENGTH; return static_cast<float>(MAX_VALUE_FOR_WEIGHTING);
} }
float ProximityInfoState::getPointToKeyLength_G(const int inputIndex, const int codePoint) const { float ProximityInfoState::getPointToKeyLength_G(const int inputIndex, const int codePoint) const {
@ -314,6 +314,6 @@ float ProximityInfoState::getProbability(const int index, const int keyIndex) co
if (it != mCharProbabilities[index].end()) { if (it != mCharProbabilities[index].end()) {
return it->second; return it->second;
} }
return static_cast<float>(MAX_POINT_TO_KEY_LENGTH); return static_cast<float>(MAX_VALUE_FOR_WEIGHTING);
} }
} // namespace latinime } // namespace latinime

View File

@ -645,7 +645,7 @@ namespace latinime {
return min((*SampledDistanceCache_G)[index] * scale, maxPointToKeyLength); return min((*SampledDistanceCache_G)[index] * scale, maxPointToKeyLength);
} }
// If the char is not a key on the keyboard then return the max length. // If the char is not a key on the keyboard then return the max length.
return static_cast<float>(MAX_POINT_TO_KEY_LENGTH); return static_cast<float>(MAX_VALUE_FOR_WEIGHTING);
} }
/* static */ float ProximityInfoStateUtils::getPointToKeyByIdLength(const float maxPointToKeyLength, /* static */ float ProximityInfoStateUtils::getPointToKeyByIdLength(const float maxPointToKeyLength,
@ -678,7 +678,7 @@ namespace latinime {
const float currentAngle = getPointAngle(sampledInputXs, sampledInputYs, i); const float currentAngle = getPointAngle(sampledInputXs, sampledInputYs, i);
const float speedRate = (*sampledSpeedRates)[i]; const float speedRate = (*sampledSpeedRates)[i];
float nearestKeyDistance = static_cast<float>(MAX_POINT_TO_KEY_LENGTH); float nearestKeyDistance = static_cast<float>(MAX_VALUE_FOR_WEIGHTING);
for (int j = 0; j < keyCount; ++j) { for (int j = 0; j < keyCount; ++j) {
if ((*SampledNearKeySets)[i].test(j)) { if ((*SampledNearKeySets)[i].test(j)) {
const float distance = getPointToKeyByIdLength( const float distance = getPointToKeyByIdLength(
@ -1016,7 +1016,7 @@ namespace latinime {
float sumLogProbability = 0.0f; float sumLogProbability = 0.0f;
// TODO: Current implementation is greedy algorithm. DP would be efficient for many cases. // TODO: Current implementation is greedy algorithm. DP would be efficient for many cases.
for (int i = 0; i < sampledInputSize && index < MAX_WORD_LENGTH - 1; ++i) { for (int i = 0; i < sampledInputSize && index < MAX_WORD_LENGTH - 1; ++i) {
float minLogProbability = static_cast<float>(MAX_POINT_TO_KEY_LENGTH); float minLogProbability = static_cast<float>(MAX_VALUE_FOR_WEIGHTING);
int character = NOT_AN_INDEX; int character = NOT_AN_INDEX;
for (hash_map_compat<int, float>::const_iterator it = (*charProbabilities)[i].begin(); for (hash_map_compat<int, float>::const_iterator it = (*charProbabilities)[i].begin();
it != (*charProbabilities)[i].end(); ++it) { it != (*charProbabilities)[i].end(); ++it) {

View File

@ -226,7 +226,7 @@ class ProximityInfoUtils {
const int *const keyYCoordinates, const int *const keyWidths, const int *keyHeights, const int *const keyYCoordinates, const int *const keyWidths, const int *keyHeights,
const int keyId, const int x, const int y) { const int keyId, const int x, const int y) {
// NOT_A_ID is -1, but return whenever < 0 just in case // NOT_A_ID is -1, but return whenever < 0 just in case
if (keyId < 0) return MAX_POINT_TO_KEY_LENGTH; if (keyId < 0) return MAX_VALUE_FOR_WEIGHTING;
const int left = keyXCoordinates[keyId]; const int left = keyXCoordinates[keyId];
const int top = keyYCoordinates[keyId]; const int top = keyYCoordinates[keyId];
const int right = left + keyWidths[keyId]; const int right = left + keyWidths[keyId];