parent
f06ab49999
commit
697a9d3541
|
@ -214,7 +214,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
||||||
bool incremented = false;
|
bool incremented = false;
|
||||||
if (mLastCharExceeded && mInputIndex == mInputSize - 1) {
|
if (mLastCharExceeded && mInputIndex == mInputSize - 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 = mProximityInfoState.getMatchedProximityId(
|
const ProximityType matchId = mProximityInfoState.getProximityType(
|
||||||
mInputIndex, c, true, &proximityIndex);
|
mInputIndex, c, true, &proximityIndex);
|
||||||
if (isEquivalentChar(matchId)) {
|
if (isEquivalentChar(matchId)) {
|
||||||
mLastCharExceeded = false;
|
mLastCharExceeded = false;
|
||||||
|
@ -268,7 +268,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
||||||
|
|
||||||
bool secondTransposing = false;
|
bool secondTransposing = false;
|
||||||
if (mTransposedCount % 2 == 1) {
|
if (mTransposedCount % 2 == 1) {
|
||||||
if (isEquivalentChar(mProximityInfoState.getMatchedProximityId(
|
if (isEquivalentChar(mProximityInfoState.getProximityType(
|
||||||
mInputIndex - 1, c, false))) {
|
mInputIndex - 1, c, false))) {
|
||||||
++mTransposedCount;
|
++mTransposedCount;
|
||||||
secondTransposing = true;
|
secondTransposing = true;
|
||||||
|
@ -300,7 +300,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
||||||
|
|
||||||
ProximityType matchedProximityCharId = secondTransposing
|
ProximityType matchedProximityCharId = secondTransposing
|
||||||
? EQUIVALENT_CHAR
|
? EQUIVALENT_CHAR
|
||||||
: mProximityInfoState.getMatchedProximityId(
|
: mProximityInfoState.getProximityType(
|
||||||
mInputIndex, c, checkProximityChars, &proximityIndex);
|
mInputIndex, c, checkProximityChars, &proximityIndex);
|
||||||
|
|
||||||
if (UNRELATED_CHAR == matchedProximityCharId
|
if (UNRELATED_CHAR == matchedProximityCharId
|
||||||
|
@ -308,7 +308,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
||||||
if (canTryCorrection && mOutputIndex > 0
|
if (canTryCorrection && mOutputIndex > 0
|
||||||
&& mCorrectionStates[mOutputIndex].mProximityMatching
|
&& mCorrectionStates[mOutputIndex].mProximityMatching
|
||||||
&& mCorrectionStates[mOutputIndex].mExceeding
|
&& mCorrectionStates[mOutputIndex].mExceeding
|
||||||
&& isEquivalentChar(mProximityInfoState.getMatchedProximityId(
|
&& isEquivalentChar(mProximityInfoState.getProximityType(
|
||||||
mInputIndex, mWord[mOutputIndex - 1], false))) {
|
mInputIndex, mWord[mOutputIndex - 1], false))) {
|
||||||
if (DEBUG_CORRECTION
|
if (DEBUG_CORRECTION
|
||||||
&& (INPUTLENGTH_FOR_DEBUG <= 0 || INPUTLENGTH_FOR_DEBUG == mInputSize)
|
&& (INPUTLENGTH_FOR_DEBUG <= 0 || INPUTLENGTH_FOR_DEBUG == mInputSize)
|
||||||
|
@ -327,7 +327,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
||||||
// 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 = mProximityInfoState.getMatchedProximityId(
|
matchedProximityCharId = mProximityInfoState.getProximityType(
|
||||||
mInputIndex, c, mProximityCount == 0, &proximityIndex);
|
mInputIndex, c, mProximityCount == 0, &proximityIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -344,10 +344,10 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
||||||
if (mInputIndex < mInputSize - 1 && mOutputIndex > 0 && mTransposedCount > 0
|
if (mInputIndex < mInputSize - 1 && mOutputIndex > 0 && mTransposedCount > 0
|
||||||
&& !mCorrectionStates[mOutputIndex].mTransposing
|
&& !mCorrectionStates[mOutputIndex].mTransposing
|
||||||
&& mCorrectionStates[mOutputIndex - 1].mTransposing
|
&& mCorrectionStates[mOutputIndex - 1].mTransposing
|
||||||
&& isEquivalentChar(mProximityInfoState.getMatchedProximityId(
|
&& isEquivalentChar(mProximityInfoState.getProximityType(
|
||||||
mInputIndex, mWord[mOutputIndex - 1], false))
|
mInputIndex, mWord[mOutputIndex - 1], false))
|
||||||
&& isEquivalentChar(
|
&& isEquivalentChar(
|
||||||
mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) {
|
mProximityInfoState.getProximityType(mInputIndex + 1, c, false))) {
|
||||||
// Conversion t->e
|
// Conversion t->e
|
||||||
// Example:
|
// Example:
|
||||||
// occaisional -> occa sional
|
// occaisional -> occa sional
|
||||||
|
@ -359,7 +359,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
||||||
&& !mCorrectionStates[mOutputIndex].mTransposing
|
&& !mCorrectionStates[mOutputIndex].mTransposing
|
||||||
&& mCorrectionStates[mOutputIndex - 1].mTransposing
|
&& mCorrectionStates[mOutputIndex - 1].mTransposing
|
||||||
&& isEquivalentChar(
|
&& isEquivalentChar(
|
||||||
mProximityInfoState.getMatchedProximityId(mInputIndex - 1, c, false))) {
|
mProximityInfoState.getProximityType(mInputIndex - 1, c, false))) {
|
||||||
// Conversion t->s
|
// Conversion t->s
|
||||||
// Example:
|
// Example:
|
||||||
// chcolate -> chocolate
|
// chcolate -> chocolate
|
||||||
|
@ -371,7 +371,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
||||||
&& mCorrectionStates[mOutputIndex].mProximityMatching
|
&& mCorrectionStates[mOutputIndex].mProximityMatching
|
||||||
&& mCorrectionStates[mOutputIndex].mSkipping
|
&& mCorrectionStates[mOutputIndex].mSkipping
|
||||||
&& isEquivalentChar(
|
&& isEquivalentChar(
|
||||||
mProximityInfoState.getMatchedProximityId(mInputIndex - 1, c, false))) {
|
mProximityInfoState.getProximityType(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.
|
||||||
|
@ -383,7 +383,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
||||||
&& mCorrectionStates[mOutputIndex].mSkipping
|
&& mCorrectionStates[mOutputIndex].mSkipping
|
||||||
&& mCorrectionStates[mOutputIndex].mAdditionalProximityMatching
|
&& mCorrectionStates[mOutputIndex].mAdditionalProximityMatching
|
||||||
&& isProximityCharOrEquivalentChar(
|
&& isProximityCharOrEquivalentChar(
|
||||||
mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) {
|
mProximityInfoState.getProximityType(mInputIndex + 1, c, false))) {
|
||||||
// Conversion s->a
|
// Conversion s->a
|
||||||
incrementInputIndex();
|
incrementInputIndex();
|
||||||
--mSkippedCount;
|
--mSkippedCount;
|
||||||
|
@ -392,7 +392,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
||||||
mDistances[mOutputIndex] = ADDITIONAL_PROXIMITY_CHAR_DISTANCE_INFO;
|
mDistances[mOutputIndex] = ADDITIONAL_PROXIMITY_CHAR_DISTANCE_INFO;
|
||||||
} else if ((mExceeding || mTransposing) && mInputIndex - 1 < mInputSize
|
} else if ((mExceeding || mTransposing) && mInputIndex - 1 < mInputSize
|
||||||
&& isEquivalentChar(
|
&& isEquivalentChar(
|
||||||
mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) {
|
mProximityInfoState.getProximityType(mInputIndex + 1, c, false))) {
|
||||||
// 1.2. Excessive or transpose correction
|
// 1.2. Excessive or transpose correction
|
||||||
if (mTransposing) {
|
if (mTransposing) {
|
||||||
++mTransposedCount;
|
++mTransposedCount;
|
||||||
|
@ -614,7 +614,7 @@ inline static bool isUpperCase(unsigned short c) {
|
||||||
multiplyIntCapped(matchWeight, &finalFreq);
|
multiplyIntCapped(matchWeight, &finalFreq);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proximityInfoState->getMatchedProximityId(0, word[0], true) == UNRELATED_CHAR) {
|
if (proximityInfoState->getProximityType(0, word[0], true) == UNRELATED_CHAR) {
|
||||||
multiplyRate(FIRST_CHAR_DIFFERENT_DEMOTION_RATE, &finalFreq);
|
multiplyRate(FIRST_CHAR_DIFFERENT_DEMOTION_RATE, &finalFreq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ class ProximityInfo {
|
||||||
int getKeyCenterYOfKeyIdG(int keyId) const;
|
int getKeyCenterYOfKeyIdG(int keyId) const;
|
||||||
int getKeyKeyDistanceG(int keyId0, int keyId1) const;
|
int getKeyKeyDistanceG(int keyId0, int keyId1) const;
|
||||||
|
|
||||||
void AK_FORCE_INLINE initializeProximities(const int *const inputCodes,
|
AK_FORCE_INLINE void initializeProximities(const int *const inputCodes,
|
||||||
const int *const inputXCoordinates, const int *const inputYCoordinates,
|
const int *const inputXCoordinates, const int *const inputYCoordinates,
|
||||||
const int inputSize, int *allInputCodes) const {
|
const int inputSize, int *allInputCodes) const {
|
||||||
ProximityInfoUtils::initializeProximities(inputCodes, inputXCoordinates, inputYCoordinates,
|
ProximityInfoUtils::initializeProximities(inputCodes, inputXCoordinates, inputYCoordinates,
|
||||||
|
@ -79,10 +79,14 @@ class ProximityInfo {
|
||||||
KEY_COUNT, mLocaleStr, &mCodeToKeyMap, allInputCodes);
|
KEY_COUNT, mLocaleStr, &mCodeToKeyMap, allInputCodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
int AK_FORCE_INLINE getKeyIndexOf(const int c) const {
|
AK_FORCE_INLINE int getKeyIndexOf(const int c) const {
|
||||||
return ProximityInfoUtils::getKeyIndexOf(KEY_COUNT, c, &mCodeToKeyMap);
|
return ProximityInfoUtils::getKeyIndexOf(KEY_COUNT, c, &mCodeToKeyMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AK_FORCE_INLINE bool isCodePointOnKeyboard(const int codePoint) const {
|
||||||
|
return getKeyIndexOf(codePoint) != NOT_AN_INDEX;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfo);
|
DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfo);
|
||||||
|
|
||||||
|
|
|
@ -193,20 +193,20 @@ float ProximityInfoState::getPointToKeyByIdLength(const int inputIndex, const in
|
||||||
// the same position. We want to see if c is in it: if so, then the word contains at that position
|
// the same position. We want to see if c is in it: if so, then the word contains at that position
|
||||||
// a character close to what the user typed.
|
// a character close to what the user typed.
|
||||||
// What the user typed is actually the first character of the array.
|
// What the user typed is actually the first character of the array.
|
||||||
// proximityIndex is a pointer to the variable where getMatchedProximityId returns the index of c
|
// proximityIndex is a pointer to the variable where getProximityType returns the index of c
|
||||||
// in the proximity chars of the input index.
|
// in the proximity chars of the input index.
|
||||||
// Notice : accented characters do not have a proximity list, so they are alone in their list. The
|
// Notice : accented characters do not have a proximity list, so they are alone in their list. The
|
||||||
// non-accented version of the character should be considered "close", but not the other keys close
|
// non-accented version of the character should be considered "close", but not the other keys close
|
||||||
// to the non-accented version.
|
// to the non-accented version.
|
||||||
ProximityType ProximityInfoState::getMatchedProximityId(const int index, const int c,
|
ProximityType ProximityInfoState::getProximityType(const int index, const int codePoint,
|
||||||
const bool checkProximityChars, int *proximityIndex) const {
|
const bool checkProximityChars, int *proximityIndex) const {
|
||||||
const int *currentCodePoints = getProximityCodePointsAt(index);
|
const int *currentCodePoints = getProximityCodePointsAt(index);
|
||||||
const int firstCodePoint = currentCodePoints[0];
|
const int firstCodePoint = currentCodePoints[0];
|
||||||
const int baseLowerC = toBaseLowerCase(c);
|
const int baseLowerC = toBaseLowerCase(codePoint);
|
||||||
|
|
||||||
// The first char in the array is what user typed. If it matches right away, that means the
|
// The first char in the array is what user typed. If it matches right away, that means the
|
||||||
// user typed that same char for this pos.
|
// user typed that same char for this pos.
|
||||||
if (firstCodePoint == baseLowerC || firstCodePoint == c) {
|
if (firstCodePoint == baseLowerC || firstCodePoint == codePoint) {
|
||||||
return EQUIVALENT_CHAR;
|
return EQUIVALENT_CHAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +222,8 @@ ProximityType ProximityInfoState::getMatchedProximityId(const int index, const i
|
||||||
int j = 1;
|
int j = 1;
|
||||||
while (j < MAX_PROXIMITY_CHARS_SIZE
|
while (j < MAX_PROXIMITY_CHARS_SIZE
|
||||||
&& currentCodePoints[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
|
&& currentCodePoints[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
|
||||||
const bool matched = (currentCodePoints[j] == baseLowerC || currentCodePoints[j] == c);
|
const bool matched = (currentCodePoints[j] == baseLowerC
|
||||||
|
|| currentCodePoints[j] == codePoint);
|
||||||
if (matched) {
|
if (matched) {
|
||||||
if (proximityIndex) {
|
if (proximityIndex) {
|
||||||
*proximityIndex = j;
|
*proximityIndex = j;
|
||||||
|
@ -236,7 +237,8 @@ ProximityType ProximityInfoState::getMatchedProximityId(const int index, const i
|
||||||
++j;
|
++j;
|
||||||
while (j < MAX_PROXIMITY_CHARS_SIZE
|
while (j < MAX_PROXIMITY_CHARS_SIZE
|
||||||
&& currentCodePoints[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
|
&& currentCodePoints[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
|
||||||
const bool matched = (currentCodePoints[j] == baseLowerC || currentCodePoints[j] == c);
|
const bool matched = (currentCodePoints[j] == baseLowerC
|
||||||
|
|| currentCodePoints[j] == codePoint);
|
||||||
if (matched) {
|
if (matched) {
|
||||||
if (proximityIndex) {
|
if (proximityIndex) {
|
||||||
*proximityIndex = j;
|
*proximityIndex = j;
|
||||||
|
@ -250,6 +252,21 @@ ProximityType ProximityInfoState::getMatchedProximityId(const int index, const i
|
||||||
return UNRELATED_CHAR;
|
return UNRELATED_CHAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProximityType ProximityInfoState::getProximityTypeG(const int index, const int codePoint) const {
|
||||||
|
if (!isUsed()) {
|
||||||
|
return UNRELATED_NOR_SUBSTITUTION_CHAR;
|
||||||
|
}
|
||||||
|
const int lowerCodePoint = toLowerCase(codePoint);
|
||||||
|
const int baseLowerCodePoint = toBaseCodePoint(lowerCodePoint);
|
||||||
|
for (int i = 0; i < static_cast<int>(mSampledSearchKeyVectors[index].size()); ++i) {
|
||||||
|
if (mSampledSearchKeyVectors[index][i] == lowerCodePoint
|
||||||
|
|| mSampledSearchKeyVectors[index][i] == baseLowerCodePoint) {
|
||||||
|
return EQUIVALENT_CHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return UNRELATED_NOR_SUBSTITUTION_CHAR;
|
||||||
|
}
|
||||||
|
|
||||||
bool ProximityInfoState::isKeyInSerchKeysAfterIndex(const int index, const int keyId) const {
|
bool ProximityInfoState::isKeyInSerchKeysAfterIndex(const int index, const int keyId) const {
|
||||||
ASSERT(keyId >= 0 && index >= 0 && index < mSampledInputSize);
|
ASSERT(keyId >= 0 && index >= 0 && index < mSampledInputSize);
|
||||||
return mSampledSearchKeySets[index].test(keyId);
|
return mSampledSearchKeySets[index].test(keyId);
|
||||||
|
|
|
@ -152,9 +152,11 @@ class ProximityInfoState {
|
||||||
float getPointToKeyLength(const int inputIndex, const int codePoint, const float scale) const;
|
float getPointToKeyLength(const int inputIndex, const int codePoint, const float scale) const;
|
||||||
float getPointToKeyLength_G(const int inputIndex, const int codePoint) const;
|
float getPointToKeyLength_G(const int inputIndex, const int codePoint) const;
|
||||||
|
|
||||||
ProximityType getMatchedProximityId(const int index, const int c,
|
ProximityType getProximityType(const int index, const int codePoint,
|
||||||
const bool checkProximityChars, int *proximityIndex = 0) const;
|
const bool checkProximityChars, int *proximityIndex = 0) const;
|
||||||
|
|
||||||
|
ProximityType getProximityTypeG(const int index, const int codePoint) const;
|
||||||
|
|
||||||
const std::vector<int> *getSearchKeyVector(const int index) const {
|
const std::vector<int> *getSearchKeyVector(const int index) const {
|
||||||
return &mSampledSearchKeyVectors[index];
|
return &mSampledSearchKeyVectors[index];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue