refactor native step 2
- proximity_info is now stateless Change-Id: I62725bfe05b161fa8fc050ea6b50867e10a354e2main
parent
eed2cf287d
commit
4a3db7057f
|
@ -98,7 +98,7 @@ inline static int getCurrentEditDistance(int *editDistanceTable, const int editD
|
||||||
static const char QUOTE = '\'';
|
static const char QUOTE = '\'';
|
||||||
|
|
||||||
inline bool Correction::isQuote(const unsigned short c) {
|
inline bool Correction::isQuote(const unsigned short c) {
|
||||||
const unsigned short userTypedChar = mProximityInfo->getPrimaryCharAt(mInputIndex);
|
const unsigned short userTypedChar = mProximityInfoState.getPrimaryCharAt(mInputIndex);
|
||||||
return (c == QUOTE && userTypedChar != QUOTE);
|
return (c == QUOTE && userTypedChar != QUOTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ bool Correction::needsToPrune() const {
|
||||||
|
|
||||||
void Correction::addCharToCurrentWord(const int32_t c) {
|
void Correction::addCharToCurrentWord(const int32_t c) {
|
||||||
mWord[mOutputIndex] = c;
|
mWord[mOutputIndex] = c;
|
||||||
const unsigned short *primaryInputWord = mProximityInfo->getPrimaryInputWord();
|
const unsigned short *primaryInputWord = mProximityInfoState.getPrimaryInputWord();
|
||||||
calcEditDistanceOneStep(mEditDistanceTable, primaryInputWord, mInputLength,
|
calcEditDistanceOneStep(mEditDistanceTable, primaryInputWord, mInputLength,
|
||||||
mWord, mOutputIndex + 1);
|
mWord, mOutputIndex + 1);
|
||||||
}
|
}
|
||||||
|
@ -335,19 +335,19 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
bool incremented = false;
|
bool incremented = false;
|
||||||
if (mLastCharExceeded && mInputIndex == mInputLength - 1) {
|
if (mLastCharExceeded && mInputIndex == mInputLength - 1) {
|
||||||
// TODO: Do not check the proximity if EditDistance exceeds the threshold
|
// TODO: Do not check the proximity if EditDistance exceeds the threshold
|
||||||
const ProximityType matchId =
|
const ProximityType matchId = mProximityInfoState.getMatchedProximityId(
|
||||||
mProximityInfo->getMatchedProximityId(mInputIndex, c, true, &proximityIndex);
|
mInputIndex, c, true, &proximityIndex);
|
||||||
if (isEquivalentChar(matchId)) {
|
if (isEquivalentChar(matchId)) {
|
||||||
mLastCharExceeded = false;
|
mLastCharExceeded = false;
|
||||||
--mExcessiveCount;
|
--mExcessiveCount;
|
||||||
mDistances[mOutputIndex] =
|
mDistances[mOutputIndex] =
|
||||||
mProximityInfo->getNormalizedSquaredDistance(mInputIndex, 0);
|
mProximityInfoState.getNormalizedSquaredDistance(mInputIndex, 0);
|
||||||
} else if (matchId == NEAR_PROXIMITY_CHAR) {
|
} else if (matchId == NEAR_PROXIMITY_CHAR) {
|
||||||
mLastCharExceeded = false;
|
mLastCharExceeded = false;
|
||||||
--mExcessiveCount;
|
--mExcessiveCount;
|
||||||
++mProximityCount;
|
++mProximityCount;
|
||||||
mDistances[mOutputIndex] =
|
mDistances[mOutputIndex] = mProximityInfoState.getNormalizedSquaredDistance(
|
||||||
mProximityInfo->getNormalizedSquaredDistance(mInputIndex, proximityIndex);
|
mInputIndex, proximityIndex);
|
||||||
}
|
}
|
||||||
if (!isQuote(c)) {
|
if (!isQuote(c)) {
|
||||||
incrementInputIndex();
|
incrementInputIndex();
|
||||||
|
@ -388,7 +388,8 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
|
|
||||||
bool secondTransposing = false;
|
bool secondTransposing = false;
|
||||||
if (mTransposedCount % 2 == 1) {
|
if (mTransposedCount % 2 == 1) {
|
||||||
if (isEquivalentChar(mProximityInfo->getMatchedProximityId(mInputIndex - 1, c, false))) {
|
if (isEquivalentChar(mProximityInfoState.getMatchedProximityId(
|
||||||
|
mInputIndex - 1, c, false))) {
|
||||||
++mTransposedCount;
|
++mTransposedCount;
|
||||||
secondTransposing = true;
|
secondTransposing = true;
|
||||||
} else if (mCorrectionStates[mOutputIndex].mExceeding) {
|
} else if (mCorrectionStates[mOutputIndex].mExceeding) {
|
||||||
|
@ -419,7 +420,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
|
|
||||||
ProximityType matchedProximityCharId = secondTransposing
|
ProximityType matchedProximityCharId = secondTransposing
|
||||||
? EQUIVALENT_CHAR
|
? EQUIVALENT_CHAR
|
||||||
: mProximityInfo->getMatchedProximityId(
|
: mProximityInfoState.getMatchedProximityId(
|
||||||
mInputIndex, c, checkProximityChars, &proximityIndex);
|
mInputIndex, c, checkProximityChars, &proximityIndex);
|
||||||
|
|
||||||
if (UNRELATED_CHAR == matchedProximityCharId
|
if (UNRELATED_CHAR == matchedProximityCharId
|
||||||
|
@ -427,7 +428,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
if (canTryCorrection && mOutputIndex > 0
|
if (canTryCorrection && mOutputIndex > 0
|
||||||
&& mCorrectionStates[mOutputIndex].mProximityMatching
|
&& mCorrectionStates[mOutputIndex].mProximityMatching
|
||||||
&& mCorrectionStates[mOutputIndex].mExceeding
|
&& mCorrectionStates[mOutputIndex].mExceeding
|
||||||
&& isEquivalentChar(mProximityInfo->getMatchedProximityId(
|
&& isEquivalentChar(mProximityInfoState.getMatchedProximityId(
|
||||||
mInputIndex, mWord[mOutputIndex - 1], false))) {
|
mInputIndex, mWord[mOutputIndex - 1], false))) {
|
||||||
if (DEBUG_CORRECTION
|
if (DEBUG_CORRECTION
|
||||||
&& (INPUTLENGTH_FOR_DEBUG <= 0 || INPUTLENGTH_FOR_DEBUG == mInputLength)
|
&& (INPUTLENGTH_FOR_DEBUG <= 0 || INPUTLENGTH_FOR_DEBUG == mInputLength)
|
||||||
|
@ -446,7 +447,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
// Here, we are doing something equivalent to matchedProximityCharId,
|
// Here, we are doing something equivalent to matchedProximityCharId,
|
||||||
// but we already know that "excessive char correction" just happened
|
// but we already know that "excessive char correction" just happened
|
||||||
// so that we just need to check "mProximityCount == 0".
|
// so that we just need to check "mProximityCount == 0".
|
||||||
matchedProximityCharId = mProximityInfo->getMatchedProximityId(
|
matchedProximityCharId = mProximityInfoState.getMatchedProximityId(
|
||||||
mInputIndex, c, mProximityCount == 0, &proximityIndex);
|
mInputIndex, c, mProximityCount == 0, &proximityIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -463,10 +464,10 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
if (mInputIndex < mInputLength - 1 && mOutputIndex > 0 && mTransposedCount > 0
|
if (mInputIndex < mInputLength - 1 && mOutputIndex > 0 && mTransposedCount > 0
|
||||||
&& !mCorrectionStates[mOutputIndex].mTransposing
|
&& !mCorrectionStates[mOutputIndex].mTransposing
|
||||||
&& mCorrectionStates[mOutputIndex - 1].mTransposing
|
&& mCorrectionStates[mOutputIndex - 1].mTransposing
|
||||||
&& isEquivalentChar(mProximityInfo->getMatchedProximityId(
|
&& isEquivalentChar(mProximityInfoState.getMatchedProximityId(
|
||||||
mInputIndex, mWord[mOutputIndex - 1], false))
|
mInputIndex, mWord[mOutputIndex - 1], false))
|
||||||
&& isEquivalentChar(
|
&& isEquivalentChar(
|
||||||
mProximityInfo->getMatchedProximityId(mInputIndex + 1, c, false))) {
|
mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) {
|
||||||
// Conversion t->e
|
// Conversion t->e
|
||||||
// Example:
|
// Example:
|
||||||
// occaisional -> occa sional
|
// occaisional -> occa sional
|
||||||
|
@ -478,7 +479,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
&& !mCorrectionStates[mOutputIndex].mTransposing
|
&& !mCorrectionStates[mOutputIndex].mTransposing
|
||||||
&& mCorrectionStates[mOutputIndex - 1].mTransposing
|
&& mCorrectionStates[mOutputIndex - 1].mTransposing
|
||||||
&& isEquivalentChar(
|
&& isEquivalentChar(
|
||||||
mProximityInfo->getMatchedProximityId(mInputIndex - 1, c, false))) {
|
mProximityInfoState.getMatchedProximityId(mInputIndex - 1, c, false))) {
|
||||||
// Conversion t->s
|
// Conversion t->s
|
||||||
// Example:
|
// Example:
|
||||||
// chcolate -> chocolate
|
// chcolate -> chocolate
|
||||||
|
@ -490,7 +491,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
&& mCorrectionStates[mOutputIndex].mProximityMatching
|
&& mCorrectionStates[mOutputIndex].mProximityMatching
|
||||||
&& mCorrectionStates[mOutputIndex].mSkipping
|
&& mCorrectionStates[mOutputIndex].mSkipping
|
||||||
&& isEquivalentChar(
|
&& isEquivalentChar(
|
||||||
mProximityInfo->getMatchedProximityId(mInputIndex - 1, c, false))) {
|
mProximityInfoState.getMatchedProximityId(mInputIndex - 1, c, false))) {
|
||||||
// Conversion p->s
|
// Conversion p->s
|
||||||
// Note: This logic tries saving cases like contrst --> contrast -- "a" is one of
|
// Note: This logic tries saving cases like contrst --> contrast -- "a" is one of
|
||||||
// proximity chars of "s", but it should rather be handled as a skipped char.
|
// proximity chars of "s", but it should rather be handled as a skipped char.
|
||||||
|
@ -502,7 +503,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
&& mCorrectionStates[mOutputIndex].mSkipping
|
&& mCorrectionStates[mOutputIndex].mSkipping
|
||||||
&& mCorrectionStates[mOutputIndex].mAdditionalProximityMatching
|
&& mCorrectionStates[mOutputIndex].mAdditionalProximityMatching
|
||||||
&& isProximityCharOrEquivalentChar(
|
&& isProximityCharOrEquivalentChar(
|
||||||
mProximityInfo->getMatchedProximityId(mInputIndex + 1, c, false))) {
|
mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) {
|
||||||
// Conversion s->a
|
// Conversion s->a
|
||||||
incrementInputIndex();
|
incrementInputIndex();
|
||||||
--mSkippedCount;
|
--mSkippedCount;
|
||||||
|
@ -511,7 +512,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
mDistances[mOutputIndex] = ADDITIONAL_PROXIMITY_CHAR_DISTANCE_INFO;
|
mDistances[mOutputIndex] = ADDITIONAL_PROXIMITY_CHAR_DISTANCE_INFO;
|
||||||
} else if ((mExceeding || mTransposing) && mInputIndex - 1 < mInputLength
|
} else if ((mExceeding || mTransposing) && mInputIndex - 1 < mInputLength
|
||||||
&& isEquivalentChar(
|
&& isEquivalentChar(
|
||||||
mProximityInfo->getMatchedProximityId(mInputIndex + 1, c, false))) {
|
mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) {
|
||||||
// 1.2. Excessive or transpose correction
|
// 1.2. Excessive or transpose correction
|
||||||
if (mTransposing) {
|
if (mTransposing) {
|
||||||
++mTransposedCount;
|
++mTransposedCount;
|
||||||
|
@ -573,12 +574,12 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
} else if (isEquivalentChar(matchedProximityCharId)) {
|
} else if (isEquivalentChar(matchedProximityCharId)) {
|
||||||
mMatching = true;
|
mMatching = true;
|
||||||
++mEquivalentCharCount;
|
++mEquivalentCharCount;
|
||||||
mDistances[mOutputIndex] = mProximityInfo->getNormalizedSquaredDistance(mInputIndex, 0);
|
mDistances[mOutputIndex] = mProximityInfoState.getNormalizedSquaredDistance(mInputIndex, 0);
|
||||||
} else if (NEAR_PROXIMITY_CHAR == matchedProximityCharId) {
|
} else if (NEAR_PROXIMITY_CHAR == matchedProximityCharId) {
|
||||||
mProximityMatching = true;
|
mProximityMatching = true;
|
||||||
++mProximityCount;
|
++mProximityCount;
|
||||||
mDistances[mOutputIndex] =
|
mDistances[mOutputIndex] =
|
||||||
mProximityInfo->getNormalizedSquaredDistance(mInputIndex, proximityIndex);
|
mProximityInfoState.getNormalizedSquaredDistance(mInputIndex, proximityIndex);
|
||||||
if (DEBUG_CORRECTION
|
if (DEBUG_CORRECTION
|
||||||
&& (INPUTLENGTH_FOR_DEBUG <= 0 || INPUTLENGTH_FOR_DEBUG == mInputLength)
|
&& (INPUTLENGTH_FOR_DEBUG <= 0 || INPUTLENGTH_FOR_DEBUG == mInputLength)
|
||||||
&& (MIN_OUTPUT_INDEX_FOR_DEBUG <= 0
|
&& (MIN_OUTPUT_INDEX_FOR_DEBUG <= 0
|
||||||
|
@ -662,7 +663,7 @@ int Correction::RankingAlgorithm::calculateFinalProbability(const int inputIndex
|
||||||
const int excessivePos = correction->getExcessivePos();
|
const int excessivePos = correction->getExcessivePos();
|
||||||
const int typedLetterMultiplier = correction->TYPED_LETTER_MULTIPLIER;
|
const int typedLetterMultiplier = correction->TYPED_LETTER_MULTIPLIER;
|
||||||
const int fullWordMultiplier = correction->FULL_WORD_MULTIPLIER;
|
const int fullWordMultiplier = correction->FULL_WORD_MULTIPLIER;
|
||||||
const ProximityInfo *proximityInfo = correction->mProximityInfo;
|
const ProximityInfoState *proximityInfoState = &correction->mProximityInfoState;
|
||||||
const int skippedCount = correction->mSkippedCount;
|
const int skippedCount = correction->mSkippedCount;
|
||||||
const int transposedCount = correction->mTransposedCount / 2;
|
const int transposedCount = correction->mTransposedCount / 2;
|
||||||
const int excessiveCount = correction->mExcessiveCount + correction->mTransposedCount % 2;
|
const int excessiveCount = correction->mExcessiveCount + correction->mTransposedCount % 2;
|
||||||
|
@ -685,7 +686,7 @@ int Correction::RankingAlgorithm::calculateFinalProbability(const int inputIndex
|
||||||
const bool skipped = skippedCount > 0;
|
const bool skipped = skippedCount > 0;
|
||||||
|
|
||||||
const int quoteDiffCount = max(0, getQuoteCount(word, outputLength)
|
const int quoteDiffCount = max(0, getQuoteCount(word, outputLength)
|
||||||
- getQuoteCount(proximityInfo->getPrimaryInputWord(), inputLength));
|
- getQuoteCount(proximityInfoState->getPrimaryInputWord(), inputLength));
|
||||||
|
|
||||||
// TODO: Calculate edit distance for transposed and excessive
|
// TODO: Calculate edit distance for transposed and excessive
|
||||||
int ed = 0;
|
int ed = 0;
|
||||||
|
@ -737,7 +738,7 @@ int Correction::RankingAlgorithm::calculateFinalProbability(const int inputIndex
|
||||||
multiplyIntCapped(matchWeight, &finalFreq);
|
multiplyIntCapped(matchWeight, &finalFreq);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proximityInfo->getMatchedProximityId(0, word[0], true) == UNRELATED_CHAR) {
|
if (proximityInfoState->getMatchedProximityId(0, word[0], true) == UNRELATED_CHAR) {
|
||||||
multiplyRate(FIRST_CHAR_DIFFERENT_DEMOTION_RATE, &finalFreq);
|
multiplyRate(FIRST_CHAR_DIFFERENT_DEMOTION_RATE, &finalFreq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -763,7 +764,7 @@ int Correction::RankingAlgorithm::calculateFinalProbability(const int inputIndex
|
||||||
// Demotion for a word with excessive character
|
// Demotion for a word with excessive character
|
||||||
if (excessiveCount > 0) {
|
if (excessiveCount > 0) {
|
||||||
multiplyRate(WORDS_WITH_EXCESSIVE_CHARACTER_DEMOTION_RATE, &finalFreq);
|
multiplyRate(WORDS_WITH_EXCESSIVE_CHARACTER_DEMOTION_RATE, &finalFreq);
|
||||||
if (!lastCharExceeded && !proximityInfo->existsAdjacentProximityChars(excessivePos)) {
|
if (!lastCharExceeded && !proximityInfoState->existsAdjacentProximityChars(excessivePos)) {
|
||||||
if (DEBUG_DICT_FULL) {
|
if (DEBUG_DICT_FULL) {
|
||||||
AKLOGI("Double excessive demotion");
|
AKLOGI("Double excessive demotion");
|
||||||
}
|
}
|
||||||
|
@ -774,8 +775,9 @@ int Correction::RankingAlgorithm::calculateFinalProbability(const int inputIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool performTouchPositionCorrection =
|
const bool performTouchPositionCorrection =
|
||||||
CALIBRATE_SCORE_BY_TOUCH_COORDINATES && proximityInfo->touchPositionCorrectionEnabled()
|
CALIBRATE_SCORE_BY_TOUCH_COORDINATES
|
||||||
&& skippedCount == 0 && excessiveCount == 0 && transposedCount == 0;
|
&& proximityInfoState->touchPositionCorrectionEnabled()
|
||||||
|
&& skippedCount == 0 && excessiveCount == 0 && transposedCount == 0;
|
||||||
// Score calibration by touch coordinates is being done only for pure-fat finger typing error
|
// Score calibration by touch coordinates is being done only for pure-fat finger typing error
|
||||||
// cases.
|
// cases.
|
||||||
int additionalProximityCount = 0;
|
int additionalProximityCount = 0;
|
||||||
|
@ -1145,5 +1147,4 @@ float Correction::RankingAlgorithm::calcNormalizedScore(const unsigned short* be
|
||||||
const float weight = 1.0 - (float) distance / afterLength;
|
const float weight = 1.0 - (float) distance / afterLength;
|
||||||
return (score / maxScore) * weight;
|
return (score / maxScore) * weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
|
|
|
@ -19,9 +19,10 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "correction_state.h"
|
|
||||||
|
|
||||||
|
#include "correction_state.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
#include "proximity_info_state.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
@ -178,6 +179,21 @@ class Correction {
|
||||||
static const int FULL_WORD_MULTIPLIER = 2;
|
static const int FULL_WORD_MULTIPLIER = 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// proximity info state
|
||||||
|
void initInputParams(const ProximityInfo *proximityInfo, const int32_t *inputCodes,
|
||||||
|
const int inputLength, const int *xCoordinates, const int *yCoordinates) {
|
||||||
|
mProximityInfoState.initInputParams(
|
||||||
|
proximityInfo, inputCodes, inputLength, xCoordinates, yCoordinates);
|
||||||
|
}
|
||||||
|
|
||||||
|
const unsigned short* getPrimaryInputWord() const {
|
||||||
|
return mProximityInfoState.getPrimaryInputWord();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned short getPrimaryCharAt(const int index) const {
|
||||||
|
return mProximityInfoState.getPrimaryCharAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline void incrementInputIndex();
|
inline void incrementInputIndex();
|
||||||
inline void incrementOutputIndex();
|
inline void incrementOutputIndex();
|
||||||
|
@ -240,7 +256,7 @@ class Correction {
|
||||||
bool mExceeding;
|
bool mExceeding;
|
||||||
bool mTransposing;
|
bool mTransposing;
|
||||||
bool mSkipping;
|
bool mSkipping;
|
||||||
|
ProximityInfoState mProximityInfoState;
|
||||||
};
|
};
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
#endif // LATINIME_CORRECTION_H
|
#endif // LATINIME_CORRECTION_H
|
||||||
|
|
|
@ -73,9 +73,6 @@ ProximityInfo::ProximityInfo(const std::string localeStr, const int maxProximity
|
||||||
copyOrFillZero(mSweetSpotRadii, sweetSpotRadii, KEY_COUNT * sizeof(mSweetSpotRadii[0]));
|
copyOrFillZero(mSweetSpotRadii, sweetSpotRadii, KEY_COUNT * sizeof(mSweetSpotRadii[0]));
|
||||||
|
|
||||||
initializeCodeToKeyIndex();
|
initializeCodeToKeyIndex();
|
||||||
mProximityInfoState = new ProximityInfoState(this, MAX_PROXIMITY_CHARS_SIZE,
|
|
||||||
HAS_TOUCH_POSITION_CORRECTION_DATA, MOST_COMMON_KEY_WIDTH_SQUARE, mLocaleStr,
|
|
||||||
KEY_COUNT, CELL_HEIGHT, CELL_WIDTH, GRID_WIDTH, GRID_HEIGHT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the reversed look up table from the char code to the index in mKeyXCoordinates,
|
// Build the reversed look up table from the char code to the index in mKeyXCoordinates,
|
||||||
|
@ -92,7 +89,6 @@ void ProximityInfo::initializeCodeToKeyIndex() {
|
||||||
|
|
||||||
ProximityInfo::~ProximityInfo() {
|
ProximityInfo::~ProximityInfo() {
|
||||||
delete[] mProximityCharsArray;
|
delete[] mProximityCharsArray;
|
||||||
delete mProximityInfoState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int ProximityInfo::getStartIndexFromCoordinates(const int x, const int y) const {
|
inline int ProximityInfo::getStartIndexFromCoordinates(const int x, const int y) const {
|
||||||
|
@ -203,12 +199,6 @@ void ProximityInfo::calculateNearbyKeyCodes(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove
|
|
||||||
void ProximityInfo::initInputParams(const int32_t *inputCodes, const int inputLength,
|
|
||||||
const int *xCoordinates, const int *yCoordinates) {
|
|
||||||
mProximityInfoState->initInputParams(inputCodes, inputLength, xCoordinates, yCoordinates);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ProximityInfo::getKeyIndex(const int c) const {
|
int ProximityInfo::getKeyIndex(const int c) const {
|
||||||
if (KEY_COUNT == 0) {
|
if (KEY_COUNT == 0) {
|
||||||
// We do not have the coordinate data
|
// We do not have the coordinate data
|
||||||
|
@ -220,47 +210,4 @@ int ProximityInfo::getKeyIndex(const int c) const {
|
||||||
}
|
}
|
||||||
return mCodeToKeyIndex[baseLowerC];
|
return mCodeToKeyIndex[baseLowerC];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove
|
|
||||||
inline const int* ProximityInfo::getProximityCharsAt(const int index) const {
|
|
||||||
return mProximityInfoState->getProximityCharsAt(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: remove
|
|
||||||
unsigned short ProximityInfo::getPrimaryCharAt(const int index) const {
|
|
||||||
return mProximityInfoState->getPrimaryCharAt(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: remove
|
|
||||||
bool ProximityInfo::existsCharInProximityAt(const int index, const int c) const {
|
|
||||||
return mProximityInfoState->existsCharInProximityAt(index, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: remove
|
|
||||||
bool ProximityInfo::existsAdjacentProximityChars(const int index) const {
|
|
||||||
return mProximityInfoState->existsAdjacentProximityChars(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: remove
|
|
||||||
ProximityType ProximityInfo::getMatchedProximityId(const int index,
|
|
||||||
const unsigned short c, const bool checkProximityChars, int *proximityIndex) const {
|
|
||||||
return mProximityInfoState->getMatchedProximityId(
|
|
||||||
index, c, checkProximityChars, proximityIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: remove
|
|
||||||
int ProximityInfo::getNormalizedSquaredDistance(
|
|
||||||
const int inputIndex, const int proximityIndex) const {
|
|
||||||
return mProximityInfoState->getNormalizedSquaredDistance(inputIndex, proximityIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: remove
|
|
||||||
const unsigned short* ProximityInfo::getPrimaryInputWord() const {
|
|
||||||
return mProximityInfoState->getPrimaryInputWord();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: remove
|
|
||||||
bool ProximityInfo::touchPositionCorrectionEnabled() const {
|
|
||||||
return mProximityInfoState->touchPositionCorrectionEnabled();
|
|
||||||
}
|
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
|
|
|
@ -25,11 +25,9 @@
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
class Correction;
|
class Correction;
|
||||||
class ProximityInfoState;
|
|
||||||
|
|
||||||
class ProximityInfo {
|
class ProximityInfo {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ProximityInfo(const std::string localeStr, const int maxProximityCharsSize,
|
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,
|
||||||
|
@ -68,21 +66,37 @@ class ProximityInfo {
|
||||||
void calculateNearbyKeyCodes(
|
void calculateNearbyKeyCodes(
|
||||||
const int x, const int y, const int32_t primaryKey, int *inputCodes) const;
|
const int x, const int y, const int32_t primaryKey, int *inputCodes) const;
|
||||||
|
|
||||||
////////////////////////////////////
|
bool hasTouchPositionCorrectionData() const {
|
||||||
// Access to proximity info state //
|
return HAS_TOUCH_POSITION_CORRECTION_DATA;
|
||||||
// TODO: remove //
|
}
|
||||||
////////////////////////////////////
|
|
||||||
void initInputParams(const int32_t *inputCodes, const int inputLength,
|
int getMostCommonKeyWidthSquare() const {
|
||||||
const int *xCoordinates, const int *yCoordinates);
|
return MOST_COMMON_KEY_WIDTH_SQUARE;
|
||||||
const int* getProximityCharsAt(const int index) const;
|
}
|
||||||
unsigned short getPrimaryCharAt(const int index) const;
|
|
||||||
bool existsCharInProximityAt(const int index, const int c) const;
|
std::string getLocaleStr() const {
|
||||||
bool existsAdjacentProximityChars(const int index) const;
|
return mLocaleStr;
|
||||||
ProximityType getMatchedProximityId(const int index, const unsigned short c,
|
}
|
||||||
const bool checkProximityChars, int *proximityIndex = 0) const;
|
|
||||||
const unsigned short* getPrimaryInputWord() const;
|
int getKeyCount() const {
|
||||||
bool touchPositionCorrectionEnabled() const;
|
return KEY_COUNT;
|
||||||
////////////////////////////////////
|
}
|
||||||
|
|
||||||
|
int getCellHeight() const {
|
||||||
|
return CELL_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getCellWidth() const {
|
||||||
|
return CELL_WIDTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getGridWidth() const {
|
||||||
|
return GRID_WIDTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getGridHeight() const {
|
||||||
|
return GRID_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// The max number of the keys in one keyboard layout
|
// The max number of the keys in one keyboard layout
|
||||||
|
@ -121,7 +135,6 @@ class ProximityInfo {
|
||||||
float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
||||||
int mCodeToKeyIndex[MAX_CHAR_CODE + 1];
|
int mCodeToKeyIndex[MAX_CHAR_CODE + 1];
|
||||||
// TODO: move to correction.h
|
// TODO: move to correction.h
|
||||||
ProximityInfoState *mProximityInfoState;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
|
|
|
@ -27,25 +27,41 @@
|
||||||
#include "proximity_info_state.h"
|
#include "proximity_info_state.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
void ProximityInfoState::initInputParams(const int32_t* inputCodes, const int inputLength,
|
void ProximityInfoState::initInputParams(
|
||||||
|
const ProximityInfo* proximityInfo, const int32_t* inputCodes, const int inputLength,
|
||||||
const int* xCoordinates, const int* yCoordinates) {
|
const int* xCoordinates, const int* yCoordinates) {
|
||||||
|
mProximityInfo = proximityInfo;
|
||||||
|
mHasTouchPositionCorrectionData = proximityInfo->hasTouchPositionCorrectionData();
|
||||||
|
mMostCommonKeyWidthSquare = proximityInfo->getMostCommonKeyWidthSquare();
|
||||||
|
mLocaleStr = proximityInfo->getLocaleStr();
|
||||||
|
mKeyCount = proximityInfo->getKeyCount();
|
||||||
|
mCellHeight = proximityInfo->getCellHeight();
|
||||||
|
mCellWidth = proximityInfo->getCellWidth();
|
||||||
|
mGridHeight = proximityInfo->getGridWidth();
|
||||||
|
mGridWidth = proximityInfo->getGridHeight();
|
||||||
|
const int normalizedSquaredDistancesLength =
|
||||||
|
MAX_PROXIMITY_CHARS_SIZE_INTERNAL * MAX_WORD_LENGTH_INTERNAL;
|
||||||
|
for (int i = 0; i < normalizedSquaredDistancesLength; ++i) {
|
||||||
|
mNormalizedSquaredDistances[i] = NOT_A_DISTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
memset(mInputCodes, 0,
|
memset(mInputCodes, 0,
|
||||||
MAX_WORD_LENGTH_INTERNAL * MAX_PROXIMITY_CHARS_SIZE * sizeof(mInputCodes[0]));
|
MAX_WORD_LENGTH_INTERNAL * MAX_PROXIMITY_CHARS_SIZE_INTERNAL * sizeof(mInputCodes[0]));
|
||||||
|
|
||||||
for (int i = 0; i < inputLength; ++i) {
|
for (int i = 0; i < inputLength; ++i) {
|
||||||
const int32_t primaryKey = inputCodes[i];
|
const int32_t primaryKey = inputCodes[i];
|
||||||
const int x = xCoordinates[i];
|
const int x = xCoordinates[i];
|
||||||
const int y = yCoordinates[i];
|
const int y = yCoordinates[i];
|
||||||
int *proximities = &mInputCodes[i * MAX_PROXIMITY_CHARS_SIZE];
|
int *proximities = &mInputCodes[i * MAX_PROXIMITY_CHARS_SIZE_INTERNAL];
|
||||||
mProximityInfo->calculateNearbyKeyCodes(x, y, primaryKey, proximities);
|
mProximityInfo->calculateNearbyKeyCodes(x, y, primaryKey, proximities);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DEBUG_PROXIMITY_CHARS) {
|
if (DEBUG_PROXIMITY_CHARS) {
|
||||||
for (int i = 0; i < inputLength; ++i) {
|
for (int i = 0; i < inputLength; ++i) {
|
||||||
AKLOGI("---");
|
AKLOGI("---");
|
||||||
for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE; ++j) {
|
for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE_INTERNAL; ++j) {
|
||||||
int icc = mInputCodes[i * MAX_PROXIMITY_CHARS_SIZE + j];
|
int icc = mInputCodes[i * MAX_PROXIMITY_CHARS_SIZE_INTERNAL + j];
|
||||||
int icfjc = inputCodes[i * MAX_PROXIMITY_CHARS_SIZE + j];
|
int icfjc = inputCodes[i * MAX_PROXIMITY_CHARS_SIZE_INTERNAL + j];
|
||||||
icc += 0;
|
icc += 0;
|
||||||
icfjc += 0;
|
icfjc += 0;
|
||||||
AKLOGI("--- (%d)%c,%c", i, icc, icfjc); AKLOGI("--- A<%d>,B<%d>", icc, icfjc);
|
AKLOGI("--- (%d)%c,%c", i, icc, icfjc); AKLOGI("--- A<%d>,B<%d>", icc, icfjc);
|
||||||
|
@ -54,8 +70,8 @@ void ProximityInfoState::initInputParams(const int32_t* inputCodes, const int in
|
||||||
}
|
}
|
||||||
mInputXCoordinates = xCoordinates;
|
mInputXCoordinates = xCoordinates;
|
||||||
mInputYCoordinates = yCoordinates;
|
mInputYCoordinates = yCoordinates;
|
||||||
mTouchPositionCorrectionEnabled = HAS_TOUCH_POSITION_CORRECTION_DATA && xCoordinates
|
mTouchPositionCorrectionEnabled =
|
||||||
&& yCoordinates;
|
mHasTouchPositionCorrectionData && xCoordinates && yCoordinates;
|
||||||
mInputLength = inputLength;
|
mInputLength = inputLength;
|
||||||
for (int i = 0; i < inputLength; ++i) {
|
for (int i = 0; i < inputLength; ++i) {
|
||||||
mPrimaryInputWord[i] = getPrimaryCharAt(i);
|
mPrimaryInputWord[i] = getPrimaryCharAt(i);
|
||||||
|
@ -74,17 +90,17 @@ void ProximityInfoState::initInputParams(const int32_t* inputCodes, const int in
|
||||||
a += 0;
|
a += 0;
|
||||||
AKLOGI("--- Primary = %c, x = %d, y = %d", primaryKey, x, y);
|
AKLOGI("--- Primary = %c, x = %d, y = %d", primaryKey, x, y);
|
||||||
}
|
}
|
||||||
for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE && proximityChars[j] > 0; ++j) {
|
for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE_INTERNAL && proximityChars[j] > 0; ++j) {
|
||||||
const int currentChar = proximityChars[j];
|
const int currentChar = proximityChars[j];
|
||||||
const float squaredDistance =
|
const float squaredDistance =
|
||||||
hasInputCoordinates() ? calculateNormalizedSquaredDistance(
|
hasInputCoordinates() ? calculateNormalizedSquaredDistance(
|
||||||
mProximityInfo->getKeyIndex(currentChar), i) :
|
mProximityInfo->getKeyIndex(currentChar), i) :
|
||||||
NOT_A_DISTANCE_FLOAT;
|
NOT_A_DISTANCE_FLOAT;
|
||||||
if (squaredDistance >= 0.0f) {
|
if (squaredDistance >= 0.0f) {
|
||||||
mNormalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE + j] =
|
mNormalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE_INTERNAL + j] =
|
||||||
(int) (squaredDistance * NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR);
|
(int) (squaredDistance * NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR);
|
||||||
} else {
|
} else {
|
||||||
mNormalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE + j] =
|
mNormalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE_INTERNAL + j] =
|
||||||
(j == 0) ? EQUIVALENT_CHAR_WITHOUT_DISTANCE_INFO :
|
(j == 0) ? EQUIVALENT_CHAR_WITHOUT_DISTANCE_INFO :
|
||||||
PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO;
|
PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO;
|
||||||
}
|
}
|
||||||
|
@ -94,4 +110,30 @@ void ProximityInfoState::initInputParams(const int32_t* inputCodes, const int in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float ProximityInfoState::calculateNormalizedSquaredDistance(
|
||||||
|
const int keyIndex, const int inputIndex) const {
|
||||||
|
if (keyIndex == NOT_AN_INDEX) {
|
||||||
|
return NOT_A_DISTANCE_FLOAT;
|
||||||
|
}
|
||||||
|
if (!mProximityInfo->hasSweetSpotData(keyIndex)) {
|
||||||
|
return NOT_A_DISTANCE_FLOAT;
|
||||||
|
}
|
||||||
|
if (NOT_A_COORDINATE == mInputXCoordinates[inputIndex]) {
|
||||||
|
return NOT_A_DISTANCE_FLOAT;
|
||||||
|
}
|
||||||
|
const float squaredDistance = calculateSquaredDistanceFromSweetSpotCenter(
|
||||||
|
keyIndex, inputIndex);
|
||||||
|
const float squaredRadius = square(mProximityInfo->getSweetSpotRadiiAt(keyIndex));
|
||||||
|
return squaredDistance / squaredRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ProximityInfoState::calculateSquaredDistanceFromSweetSpotCenter(
|
||||||
|
const int keyIndex, const int inputIndex) const {
|
||||||
|
const float sweetSpotCenterX = mProximityInfo->getSweetSpotCenterXAt(keyIndex);
|
||||||
|
const float sweetSpotCenterY = mProximityInfo->getSweetSpotCenterYAt(keyIndex);
|
||||||
|
const float inputX = (float)mInputXCoordinates[inputIndex];
|
||||||
|
const float inputY = (float)mInputYCoordinates[inputIndex];
|
||||||
|
return square(inputX - sweetSpotCenterX) + square(inputY - sweetSpotCenterY);
|
||||||
|
}
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "additional_proximity_chars.h"
|
#include "additional_proximity_chars.h"
|
||||||
|
#include "char_utils.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
@ -33,8 +34,6 @@ class ProximityInfoState {
|
||||||
static const int NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2 = 10;
|
static const int NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2 = 10;
|
||||||
static const int NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR =
|
static const int NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR =
|
||||||
1 << NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2;
|
1 << NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2;
|
||||||
// The max number of the keys in one keyboard layout
|
|
||||||
static const int MAX_KEY_COUNT_IN_A_KEYBOARD = 64;
|
|
||||||
// The upper limit of the char code in mCodeToKeyIndex
|
// The upper limit of the char code in mCodeToKeyIndex
|
||||||
static const int MAX_CHAR_CODE = 127;
|
static const int MAX_CHAR_CODE = 127;
|
||||||
static const float NOT_A_DISTANCE_FLOAT = -1.0f;
|
static const float NOT_A_DISTANCE_FLOAT = -1.0f;
|
||||||
|
@ -43,39 +42,15 @@ class ProximityInfoState {
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// Defined in proximity_info_state.cpp //
|
// Defined in proximity_info_state.cpp //
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
void initInputParams(const int32_t* inputCodes, const int inputLength,
|
void initInputParams(
|
||||||
const int* xCoordinates, const int* yCoordinates);
|
const ProximityInfo* proximityInfo, const int32_t* inputCodes, const int inputLength,
|
||||||
|
const int* xCoordinates, const int* yCoordinates);
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// Defined here //
|
// Defined here //
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// TODO: Move the constructor to initInputParams
|
|
||||||
ProximityInfoState(ProximityInfo* proximityInfo, const int maxProximityCharsSize,
|
|
||||||
const bool hasTouchPositionCorrectionData, const int mostCommonKeyWidthSquare,
|
|
||||||
const std::string localeStr, const int keyCount, const int cellHeight,
|
|
||||||
const int cellWidth, const int gridHeight, const int gridWidth)
|
|
||||||
: mProximityInfo(proximityInfo),
|
|
||||||
MAX_PROXIMITY_CHARS_SIZE(maxProximityCharsSize),
|
|
||||||
HAS_TOUCH_POSITION_CORRECTION_DATA(hasTouchPositionCorrectionData),
|
|
||||||
MOST_COMMON_KEY_WIDTH_SQUARE(mostCommonKeyWidthSquare),
|
|
||||||
LOCALE_STR(localeStr),
|
|
||||||
KEY_COUNT(keyCount),
|
|
||||||
CELL_HEIGHT(cellHeight),
|
|
||||||
CELL_WIDTH(cellWidth),
|
|
||||||
GRID_HEIGHT(gridHeight),
|
|
||||||
GRID_WIDTH(gridWidth),
|
|
||||||
mInputXCoordinates(0),
|
|
||||||
mInputYCoordinates(0),
|
|
||||||
mTouchPositionCorrectionEnabled(false) {
|
|
||||||
const int normalizedSquaredDistancesLength =
|
|
||||||
MAX_PROXIMITY_CHARS_SIZE_INTERNAL * MAX_WORD_LENGTH_INTERNAL;
|
|
||||||
for (int i = 0; i < normalizedSquaredDistancesLength; ++i) {
|
|
||||||
mNormalizedSquaredDistances[i] = NOT_A_DISTANCE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const int* getProximityCharsAt(const int index) const {
|
inline const int* getProximityCharsAt(const int index) const {
|
||||||
return mInputCodes + (index * MAX_PROXIMITY_CHARS_SIZE);
|
return mInputCodes + (index * MAX_PROXIMITY_CHARS_SIZE_INTERNAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned short getPrimaryCharAt(const int index) const {
|
inline unsigned short getPrimaryCharAt(const int index) const {
|
||||||
|
@ -85,7 +60,7 @@ class ProximityInfoState {
|
||||||
inline bool existsCharInProximityAt(const int index, const int c) const {
|
inline bool existsCharInProximityAt(const int index, const int c) const {
|
||||||
const int *chars = getProximityCharsAt(index);
|
const int *chars = getProximityCharsAt(index);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (chars[i] > 0 && i < MAX_PROXIMITY_CHARS_SIZE) {
|
while (chars[i] > 0 && i < MAX_PROXIMITY_CHARS_SIZE_INTERNAL) {
|
||||||
if (chars[i++] == c) {
|
if (chars[i++] == c) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +95,7 @@ class ProximityInfoState {
|
||||||
// in their list. The non-accented version of the character should be considered
|
// in their list. The non-accented version of the character should be considered
|
||||||
// "close", but not the other keys close to the non-accented version.
|
// "close", but not the other keys close to the non-accented version.
|
||||||
inline ProximityType getMatchedProximityId(const int index,
|
inline ProximityType getMatchedProximityId(const int index,
|
||||||
const unsigned short c, const bool checkProximityChars, int *proximityIndex) const {
|
const unsigned short c, const bool checkProximityChars, int *proximityIndex = 0) const {
|
||||||
const int *currentChars = getProximityCharsAt(index);
|
const int *currentChars = getProximityCharsAt(index);
|
||||||
const int firstChar = currentChars[0];
|
const int firstChar = currentChars[0];
|
||||||
const unsigned short baseLowerC = toBaseLowerCase(c);
|
const unsigned short baseLowerC = toBaseLowerCase(c);
|
||||||
|
@ -141,7 +116,7 @@ class ProximityInfoState {
|
||||||
|
|
||||||
// Not an exact nor an accent-alike match: search the list of close keys
|
// Not an exact nor an accent-alike match: search the list of close keys
|
||||||
int j = 1;
|
int j = 1;
|
||||||
while (j < MAX_PROXIMITY_CHARS_SIZE
|
while (j < MAX_PROXIMITY_CHARS_SIZE_INTERNAL
|
||||||
&& currentChars[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
|
&& currentChars[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
|
||||||
const bool matched = (currentChars[j] == baseLowerC || currentChars[j] == c);
|
const bool matched = (currentChars[j] == baseLowerC || currentChars[j] == c);
|
||||||
if (matched) {
|
if (matched) {
|
||||||
|
@ -152,10 +127,10 @@ class ProximityInfoState {
|
||||||
}
|
}
|
||||||
++j;
|
++j;
|
||||||
}
|
}
|
||||||
if (j < MAX_PROXIMITY_CHARS_SIZE
|
if (j < MAX_PROXIMITY_CHARS_SIZE_INTERNAL
|
||||||
&& currentChars[j] == ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
|
&& currentChars[j] == ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
|
||||||
++j;
|
++j;
|
||||||
while (j < MAX_PROXIMITY_CHARS_SIZE
|
while (j < MAX_PROXIMITY_CHARS_SIZE_INTERNAL
|
||||||
&& currentChars[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
|
&& currentChars[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
|
||||||
const bool matched = (currentChars[j] == baseLowerC || currentChars[j] == c);
|
const bool matched = (currentChars[j] == baseLowerC || currentChars[j] == c);
|
||||||
if (matched) {
|
if (matched) {
|
||||||
|
@ -174,7 +149,8 @@ class ProximityInfoState {
|
||||||
|
|
||||||
inline int getNormalizedSquaredDistance(
|
inline int getNormalizedSquaredDistance(
|
||||||
const int inputIndex, const int proximityIndex) const {
|
const int inputIndex, const int proximityIndex) const {
|
||||||
return mNormalizedSquaredDistances[inputIndex * MAX_PROXIMITY_CHARS_SIZE + proximityIndex];
|
return mNormalizedSquaredDistances[
|
||||||
|
inputIndex * MAX_PROXIMITY_CHARS_SIZE_INTERNAL + proximityIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const unsigned short* getPrimaryInputWord() const {
|
inline const unsigned short* getPrimaryInputWord() const {
|
||||||
|
@ -186,38 +162,23 @@ class ProximityInfoState {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline float square(const float x) const { return x * x; }
|
/////////////////////////////////////////
|
||||||
|
// Defined in proximity_info_state.cpp //
|
||||||
|
/////////////////////////////////////////
|
||||||
|
float calculateNormalizedSquaredDistance(const int keyIndex, const int inputIndex) const;
|
||||||
|
|
||||||
float calculateNormalizedSquaredDistance(
|
float calculateSquaredDistanceFromSweetSpotCenter(
|
||||||
const int keyIndex, const int inputIndex) const {
|
const int keyIndex, const int inputIndex) const;
|
||||||
if (keyIndex == NOT_AN_INDEX) {
|
|
||||||
return NOT_A_DISTANCE_FLOAT;
|
/////////////////////////////////////////
|
||||||
}
|
// Defined here //
|
||||||
if (!mProximityInfo->hasSweetSpotData(keyIndex)) {
|
/////////////////////////////////////////
|
||||||
return NOT_A_DISTANCE_FLOAT;
|
inline float square(const float x) const { return x * x; }
|
||||||
}
|
|
||||||
if (NOT_A_COORDINATE == mInputXCoordinates[inputIndex]) {
|
|
||||||
return NOT_A_DISTANCE_FLOAT;
|
|
||||||
}
|
|
||||||
const float squaredDistance = calculateSquaredDistanceFromSweetSpotCenter(
|
|
||||||
keyIndex, inputIndex);
|
|
||||||
const float squaredRadius = square(mProximityInfo->getSweetSpotRadiiAt(keyIndex));
|
|
||||||
return squaredDistance / squaredRadius;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasInputCoordinates() const {
|
bool hasInputCoordinates() const {
|
||||||
return mInputXCoordinates && mInputYCoordinates;
|
return mInputXCoordinates && mInputYCoordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
float calculateSquaredDistanceFromSweetSpotCenter(
|
|
||||||
const int keyIndex, const int inputIndex) const {
|
|
||||||
const float sweetSpotCenterX = mProximityInfo->getSweetSpotCenterXAt(keyIndex);
|
|
||||||
const float sweetSpotCenterY = mProximityInfo->getSweetSpotCenterYAt(keyIndex);
|
|
||||||
const float inputX = (float)mInputXCoordinates[inputIndex];
|
|
||||||
const float inputY = (float)mInputYCoordinates[inputIndex];
|
|
||||||
return square(inputX - sweetSpotCenterX) + square(inputY - sweetSpotCenterY);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sameAsTyped(const unsigned short *word, int length) const {
|
bool sameAsTyped(const unsigned short *word, int length) const {
|
||||||
if (length != mInputLength) {
|
if (length != mInputLength) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -227,23 +188,22 @@ class ProximityInfoState {
|
||||||
if ((unsigned int) *inputCodes != (unsigned int) *word) {
|
if ((unsigned int) *inputCodes != (unsigned int) *word) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
inputCodes += MAX_PROXIMITY_CHARS_SIZE;
|
inputCodes += MAX_PROXIMITY_CHARS_SIZE_INTERNAL;
|
||||||
word++;
|
word++;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: const
|
// const
|
||||||
ProximityInfo *mProximityInfo;
|
const ProximityInfo *mProximityInfo;
|
||||||
const int MAX_PROXIMITY_CHARS_SIZE;
|
bool mHasTouchPositionCorrectionData;
|
||||||
const bool HAS_TOUCH_POSITION_CORRECTION_DATA;
|
int mMostCommonKeyWidthSquare;
|
||||||
const int MOST_COMMON_KEY_WIDTH_SQUARE;
|
std::string mLocaleStr;
|
||||||
const std::string LOCALE_STR;
|
int mKeyCount;
|
||||||
const int KEY_COUNT;
|
int mCellHeight;
|
||||||
const int CELL_HEIGHT;
|
int mCellWidth;
|
||||||
const int CELL_WIDTH;
|
int mGridHeight;
|
||||||
const int GRID_HEIGHT;
|
int mGridWidth;
|
||||||
const int GRID_WIDTH;
|
|
||||||
|
|
||||||
const int *mInputXCoordinates;
|
const int *mInputXCoordinates;
|
||||||
const int *mInputYCoordinates;
|
const int *mInputYCoordinates;
|
||||||
|
|
|
@ -205,17 +205,17 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo,
|
||||||
PROF_START(20);
|
PROF_START(20);
|
||||||
if (DEBUG_DICT) {
|
if (DEBUG_DICT) {
|
||||||
float ns = queuePool->getMasterQueue()->getHighestNormalizedScore(
|
float ns = queuePool->getMasterQueue()->getHighestNormalizedScore(
|
||||||
proximityInfo->getPrimaryInputWord(), codesSize, 0, 0, 0);
|
correction->getPrimaryInputWord(), codesSize, 0, 0, 0);
|
||||||
ns += 0;
|
ns += 0;
|
||||||
AKLOGI("Max normalized score = %f", ns);
|
AKLOGI("Max normalized score = %f", ns);
|
||||||
}
|
}
|
||||||
const int suggestedWordsCount =
|
const int suggestedWordsCount =
|
||||||
queuePool->getMasterQueue()->outputSuggestions(
|
queuePool->getMasterQueue()->outputSuggestions(
|
||||||
proximityInfo->getPrimaryInputWord(), codesSize, frequencies, outWords);
|
correction->getPrimaryInputWord(), codesSize, frequencies, outWords);
|
||||||
|
|
||||||
if (DEBUG_DICT) {
|
if (DEBUG_DICT) {
|
||||||
float ns = queuePool->getMasterQueue()->getHighestNormalizedScore(
|
float ns = queuePool->getMasterQueue()->getHighestNormalizedScore(
|
||||||
proximityInfo->getPrimaryInputWord(), codesSize, 0, 0, 0);
|
correction->getPrimaryInputWord(), codesSize, 0, 0, 0);
|
||||||
ns += 0;
|
ns += 0;
|
||||||
AKLOGI("Returning %d words", suggestedWordsCount);
|
AKLOGI("Returning %d words", suggestedWordsCount);
|
||||||
/// Print the returned words
|
/// Print the returned words
|
||||||
|
@ -259,7 +259,7 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
|
||||||
WordsPriorityQueue* masterQueue = queuePool->getMasterQueue();
|
WordsPriorityQueue* masterQueue = queuePool->getMasterQueue();
|
||||||
if (masterQueue->size() > 0) {
|
if (masterQueue->size() > 0) {
|
||||||
float nsForMaster = masterQueue->getHighestNormalizedScore(
|
float nsForMaster = masterQueue->getHighestNormalizedScore(
|
||||||
proximityInfo->getPrimaryInputWord(), inputLength, 0, 0, 0);
|
correction->getPrimaryInputWord(), inputLength, 0, 0, 0);
|
||||||
hasAutoCorrectionCandidate = (nsForMaster > START_TWO_WORDS_CORRECTION_THRESHOLD);
|
hasAutoCorrectionCandidate = (nsForMaster > START_TWO_WORDS_CORRECTION_THRESHOLD);
|
||||||
}
|
}
|
||||||
PROF_END(4);
|
PROF_END(4);
|
||||||
|
@ -288,11 +288,11 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
|
||||||
const unsigned short* word = sw->mWord;
|
const unsigned short* word = sw->mWord;
|
||||||
const int wordLength = sw->mWordLength;
|
const int wordLength = sw->mWordLength;
|
||||||
float ns = Correction::RankingAlgorithm::calcNormalizedScore(
|
float ns = Correction::RankingAlgorithm::calcNormalizedScore(
|
||||||
proximityInfo->getPrimaryInputWord(), i, word, wordLength, score);
|
correction->getPrimaryInputWord(), i, word, wordLength, score);
|
||||||
ns += 0;
|
ns += 0;
|
||||||
AKLOGI("--- TOP SUB WORDS for %d --- %d %f [%d]", i, score, ns,
|
AKLOGI("--- TOP SUB WORDS for %d --- %d %f [%d]", i, score, ns,
|
||||||
(ns > TWO_WORDS_CORRECTION_WITH_OTHER_ERROR_THRESHOLD));
|
(ns > TWO_WORDS_CORRECTION_WITH_OTHER_ERROR_THRESHOLD));
|
||||||
DUMP_WORD(proximityInfo->getPrimaryInputWord(), i);
|
DUMP_WORD(correction->getPrimaryInputWord(), i);
|
||||||
DUMP_WORD(word, wordLength);
|
DUMP_WORD(word, wordLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -305,7 +305,7 @@ void UnigramDictionary::initSuggestions(ProximityInfo *proximityInfo, const int
|
||||||
AKLOGI("initSuggest");
|
AKLOGI("initSuggest");
|
||||||
DUMP_WORD_INT(codes, inputLength);
|
DUMP_WORD_INT(codes, inputLength);
|
||||||
}
|
}
|
||||||
proximityInfo->initInputParams(codes, inputLength, xCoordinates, yCoordinates);
|
correction->initInputParams(proximityInfo, codes, inputLength, xCoordinates, yCoordinates);
|
||||||
const int maxDepth = min(inputLength * MAX_DEPTH_MULTIPLIER, MAX_WORD_LENGTH);
|
const int maxDepth = min(inputLength * MAX_DEPTH_MULTIPLIER, MAX_WORD_LENGTH);
|
||||||
correction->initCorrection(proximityInfo, inputLength, maxDepth);
|
correction->initCorrection(proximityInfo, inputLength, maxDepth);
|
||||||
}
|
}
|
||||||
|
@ -480,7 +480,7 @@ int UnigramDictionary::getSubStringSuggestion(
|
||||||
inputLength, correction);
|
inputLength, correction);
|
||||||
|
|
||||||
int freq = getMostFrequentWordLike(
|
int freq = getMostFrequentWordLike(
|
||||||
inputWordStartPos, inputWordLength, proximityInfo, mWord);
|
inputWordStartPos, inputWordLength, correction, mWord);
|
||||||
if (freq > 0) {
|
if (freq > 0) {
|
||||||
nextWordLength = inputWordLength;
|
nextWordLength = inputWordLength;
|
||||||
tempOutputWord = mWord;
|
tempOutputWord = mWord;
|
||||||
|
@ -510,7 +510,7 @@ int UnigramDictionary::getSubStringSuggestion(
|
||||||
}
|
}
|
||||||
int score = 0;
|
int score = 0;
|
||||||
const float ns = queue->getHighestNormalizedScore(
|
const float ns = queue->getHighestNormalizedScore(
|
||||||
proximityInfo->getPrimaryInputWord(), inputWordLength,
|
correction->getPrimaryInputWord(), inputWordLength,
|
||||||
&tempOutputWord, &score, &nextWordLength);
|
&tempOutputWord, &score, &nextWordLength);
|
||||||
if (DEBUG_DICT) {
|
if (DEBUG_DICT) {
|
||||||
AKLOGI("NS(%d) = %f, Score = %d", currentWordIndex, ns, score);
|
AKLOGI("NS(%d) = %f, Score = %d", currentWordIndex, ns, score);
|
||||||
|
@ -678,11 +678,11 @@ void UnigramDictionary::getSplitMultipleWordsSuggestions(ProximityInfo *proximit
|
||||||
// Wrapper for getMostFrequentWordLikeInner, which matches it to the previous
|
// Wrapper for getMostFrequentWordLikeInner, which matches it to the previous
|
||||||
// interface.
|
// interface.
|
||||||
inline int UnigramDictionary::getMostFrequentWordLike(const int startInputIndex,
|
inline int UnigramDictionary::getMostFrequentWordLike(const int startInputIndex,
|
||||||
const int inputLength, ProximityInfo *proximityInfo, unsigned short *word) {
|
const int inputLength, Correction *correction, unsigned short *word) {
|
||||||
uint16_t inWord[inputLength];
|
uint16_t inWord[inputLength];
|
||||||
|
|
||||||
for (int i = 0; i < inputLength; ++i) {
|
for (int i = 0; i < inputLength; ++i) {
|
||||||
inWord[i] = (uint16_t)proximityInfo->getPrimaryCharAt(startInputIndex + i);
|
inWord[i] = (uint16_t)correction->getPrimaryCharAt(startInputIndex + i);
|
||||||
}
|
}
|
||||||
return getMostFrequentWordLikeInner(inWord, inputLength, word);
|
return getMostFrequentWordLikeInner(inWord, inputLength, word);
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,7 @@ class UnigramDictionary {
|
||||||
int *newChildPosition, int *nextSiblingPosition, WordsPriorityQueuePool *queuePool,
|
int *newChildPosition, int *nextSiblingPosition, WordsPriorityQueuePool *queuePool,
|
||||||
const int currentWordIndex);
|
const int currentWordIndex);
|
||||||
int getMostFrequentWordLike(const int startInputIndex, const int inputLength,
|
int getMostFrequentWordLike(const int startInputIndex, const int inputLength,
|
||||||
ProximityInfo *proximityInfo, unsigned short *word);
|
Correction *correction, unsigned short *word);
|
||||||
int getMostFrequentWordLikeInner(const uint16_t* const inWord, const int length,
|
int getMostFrequentWordLikeInner(const uint16_t* const inWord, const int length,
|
||||||
short unsigned int *outWord);
|
short unsigned int *outWord);
|
||||||
int getSubStringSuggestion(
|
int getSubStringSuggestion(
|
||||||
|
|
Loading…
Reference in New Issue