am 19304724
: Merge "Cleanup getProximityType" into jb-mr2-dev
* commit '1930472404104139f93c5a88d29bfc8b837fb198': Cleanup getProximityType
This commit is contained in:
commit
81d43233f5
4 changed files with 44 additions and 21 deletions
|
@ -214,7 +214,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
|||
bool incremented = false;
|
||||
if (mLastCharExceeded && mInputIndex == mInputSize - 1) {
|
||||
// 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);
|
||||
if (isEquivalentChar(matchId)) {
|
||||
mLastCharExceeded = false;
|
||||
|
@ -268,7 +268,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
|||
|
||||
bool secondTransposing = false;
|
||||
if (mTransposedCount % 2 == 1) {
|
||||
if (isEquivalentChar(mProximityInfoState.getMatchedProximityId(
|
||||
if (isEquivalentChar(mProximityInfoState.getProximityType(
|
||||
mInputIndex - 1, c, false))) {
|
||||
++mTransposedCount;
|
||||
secondTransposing = true;
|
||||
|
@ -300,7 +300,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
|||
|
||||
ProximityType matchedProximityCharId = secondTransposing
|
||||
? EQUIVALENT_CHAR
|
||||
: mProximityInfoState.getMatchedProximityId(
|
||||
: mProximityInfoState.getProximityType(
|
||||
mInputIndex, c, checkProximityChars, &proximityIndex);
|
||||
|
||||
if (UNRELATED_CHAR == matchedProximityCharId
|
||||
|
@ -308,7 +308,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
|||
if (canTryCorrection && mOutputIndex > 0
|
||||
&& mCorrectionStates[mOutputIndex].mProximityMatching
|
||||
&& mCorrectionStates[mOutputIndex].mExceeding
|
||||
&& isEquivalentChar(mProximityInfoState.getMatchedProximityId(
|
||||
&& isEquivalentChar(mProximityInfoState.getProximityType(
|
||||
mInputIndex, mWord[mOutputIndex - 1], false))) {
|
||||
if (DEBUG_CORRECTION
|
||||
&& (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,
|
||||
// but we already know that "excessive char correction" just happened
|
||||
// so that we just need to check "mProximityCount == 0".
|
||||
matchedProximityCharId = mProximityInfoState.getMatchedProximityId(
|
||||
matchedProximityCharId = mProximityInfoState.getProximityType(
|
||||
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
|
||||
&& !mCorrectionStates[mOutputIndex].mTransposing
|
||||
&& mCorrectionStates[mOutputIndex - 1].mTransposing
|
||||
&& isEquivalentChar(mProximityInfoState.getMatchedProximityId(
|
||||
&& isEquivalentChar(mProximityInfoState.getProximityType(
|
||||
mInputIndex, mWord[mOutputIndex - 1], false))
|
||||
&& isEquivalentChar(
|
||||
mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) {
|
||||
mProximityInfoState.getProximityType(mInputIndex + 1, c, false))) {
|
||||
// Conversion t->e
|
||||
// Example:
|
||||
// occaisional -> occa sional
|
||||
|
@ -359,7 +359,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
|||
&& !mCorrectionStates[mOutputIndex].mTransposing
|
||||
&& mCorrectionStates[mOutputIndex - 1].mTransposing
|
||||
&& isEquivalentChar(
|
||||
mProximityInfoState.getMatchedProximityId(mInputIndex - 1, c, false))) {
|
||||
mProximityInfoState.getProximityType(mInputIndex - 1, c, false))) {
|
||||
// Conversion t->s
|
||||
// Example:
|
||||
// chcolate -> chocolate
|
||||
|
@ -371,7 +371,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
|||
&& mCorrectionStates[mOutputIndex].mProximityMatching
|
||||
&& mCorrectionStates[mOutputIndex].mSkipping
|
||||
&& isEquivalentChar(
|
||||
mProximityInfoState.getMatchedProximityId(mInputIndex - 1, c, false))) {
|
||||
mProximityInfoState.getProximityType(mInputIndex - 1, c, false))) {
|
||||
// Conversion p->s
|
||||
// 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.
|
||||
|
@ -383,7 +383,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
|||
&& mCorrectionStates[mOutputIndex].mSkipping
|
||||
&& mCorrectionStates[mOutputIndex].mAdditionalProximityMatching
|
||||
&& isProximityCharOrEquivalentChar(
|
||||
mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) {
|
||||
mProximityInfoState.getProximityType(mInputIndex + 1, c, false))) {
|
||||
// Conversion s->a
|
||||
incrementInputIndex();
|
||||
--mSkippedCount;
|
||||
|
@ -392,7 +392,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons
|
|||
mDistances[mOutputIndex] = ADDITIONAL_PROXIMITY_CHAR_DISTANCE_INFO;
|
||||
} else if ((mExceeding || mTransposing) && mInputIndex - 1 < mInputSize
|
||||
&& isEquivalentChar(
|
||||
mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) {
|
||||
mProximityInfoState.getProximityType(mInputIndex + 1, c, false))) {
|
||||
// 1.2. Excessive or transpose correction
|
||||
if (mTransposing) {
|
||||
++mTransposedCount;
|
||||
|
@ -614,7 +614,7 @@ inline static bool isUpperCase(unsigned short c) {
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ class ProximityInfo {
|
|||
int getKeyCenterYOfKeyIdG(int keyId) 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 inputSize, int *allInputCodes) const {
|
||||
ProximityInfoUtils::initializeProximities(inputCodes, inputXCoordinates, inputYCoordinates,
|
||||
|
@ -79,10 +79,14 @@ class ProximityInfo {
|
|||
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);
|
||||
}
|
||||
|
||||
AK_FORCE_INLINE bool isCodePointOnKeyboard(const int codePoint) const {
|
||||
return getKeyIndexOf(codePoint) != NOT_AN_INDEX;
|
||||
}
|
||||
|
||||
private:
|
||||
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
|
||||
// a character close to what the user typed.
|
||||
// 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.
|
||||
// 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
|
||||
// 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 int *currentCodePoints = getProximityCodePointsAt(index);
|
||||
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
|
||||
// user typed that same char for this pos.
|
||||
if (firstCodePoint == baseLowerC || firstCodePoint == c) {
|
||||
if (firstCodePoint == baseLowerC || firstCodePoint == codePoint) {
|
||||
return EQUIVALENT_CHAR;
|
||||
}
|
||||
|
||||
|
@ -222,7 +222,8 @@ ProximityType ProximityInfoState::getMatchedProximityId(const int index, const i
|
|||
int j = 1;
|
||||
while (j < MAX_PROXIMITY_CHARS_SIZE
|
||||
&& 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 (proximityIndex) {
|
||||
*proximityIndex = j;
|
||||
|
@ -236,7 +237,8 @@ ProximityType ProximityInfoState::getMatchedProximityId(const int index, const i
|
|||
++j;
|
||||
while (j < MAX_PROXIMITY_CHARS_SIZE
|
||||
&& 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 (proximityIndex) {
|
||||
*proximityIndex = j;
|
||||
|
@ -250,6 +252,21 @@ ProximityType ProximityInfoState::getMatchedProximityId(const int index, const i
|
|||
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 {
|
||||
ASSERT(keyId >= 0 && index >= 0 && index < mSampledInputSize);
|
||||
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_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;
|
||||
|
||||
ProximityType getProximityTypeG(const int index, const int codePoint) const;
|
||||
|
||||
const std::vector<int> *getSearchKeyVector(const int index) const {
|
||||
return &mSampledSearchKeyVectors[index];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue