Fix a bug on the calculation of the freq on the mistyped space error correction

Bug: 4402942

Change-Id: I0b611e3d0e8c25ca528ef7408c3949200e5cad85
main
satok 2011-05-18 15:31:04 +09:00
parent d2d21ce0be
commit d8db9f86d0
2 changed files with 17 additions and 8 deletions

View File

@ -451,8 +451,8 @@ inline static void multiplyRate(const int rate, int *freq) {
} }
inline static int calcFreqForSplitTwoWords( inline static int calcFreqForSplitTwoWords(
const int typedLetterMultiplier, const int firstWordLength, const int typedLetterMultiplier, const int firstWordLength, const int secondWordLength,
const int secondWordLength, const int firstFreq, const int secondFreq) { const int firstFreq, const int secondFreq, const bool isSpaceProximity) {
if (firstWordLength == 0 || secondWordLength == 0) { if (firstWordLength == 0 || secondWordLength == 0) {
return 0; return 0;
} }
@ -492,13 +492,22 @@ inline static int calcFreqForSplitTwoWords(
const int normalizedScoreDemotionRateOffset = (100 + 100 / totalLength); const int normalizedScoreDemotionRateOffset = (100 + 100 / totalLength);
multiplyRate(normalizedScoreDemotionRateOffset, &totalFreq); multiplyRate(normalizedScoreDemotionRateOffset, &totalFreq);
if (isSpaceProximity) {
// A word pair with one space proximity correction
if (DEBUG_DICT) {
LOGI("Found a word pair with space proximity correction.");
}
multiplyIntCapped(typedLetterMultiplier, &totalFreq);
multiplyRate(WORDS_WITH_PROXIMITY_CHARACTER_DEMOTION_RATE, &totalFreq);
}
multiplyRate(WORDS_WITH_MISSING_SPACE_CHARACTER_DEMOTION_RATE, &totalFreq); multiplyRate(WORDS_WITH_MISSING_SPACE_CHARACTER_DEMOTION_RATE, &totalFreq);
return totalFreq; return totalFreq;
} }
bool UnigramDictionary::getSplitTwoWordsSuggestion(const int inputLength, bool UnigramDictionary::getSplitTwoWordsSuggestion(const int inputLength,
const int firstWordStartPos, const int firstWordLength, const int secondWordStartPos, const int firstWordStartPos, const int firstWordLength, const int secondWordStartPos,
const int secondWordLength) { const int secondWordLength, const bool isSpaceProximity) {
if (inputLength >= MAX_WORD_LENGTH) return false; if (inputLength >= MAX_WORD_LENGTH) return false;
if (0 >= firstWordLength || 0 >= secondWordLength || firstWordStartPos >= secondWordStartPos if (0 >= firstWordLength || 0 >= secondWordLength || firstWordStartPos >= secondWordStartPos
|| firstWordStartPos < 0 || secondWordStartPos + secondWordLength > inputLength) || firstWordStartPos < 0 || secondWordStartPos + secondWordLength > inputLength)
@ -527,8 +536,8 @@ bool UnigramDictionary::getSplitTwoWordsSuggestion(const int inputLength,
word[i] = mWord[i - firstWordLength - 1]; word[i] = mWord[i - firstWordLength - 1];
} }
int pairFreq = calcFreqForSplitTwoWords( int pairFreq = calcFreqForSplitTwoWords(TYPED_LETTER_MULTIPLIER, firstWordLength,
TYPED_LETTER_MULTIPLIER, firstWordLength, secondWordLength, firstFreq, secondFreq); secondWordLength, firstFreq, secondFreq, isSpaceProximity);
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("Split two words: %d, %d, %d, %d, %d", firstFreq, secondFreq, pairFreq, inputLength, LOGI("Split two words: %d, %d, %d, %d, %d", firstFreq, secondFreq, pairFreq, inputLength,
TYPED_LETTER_MULTIPLIER); TYPED_LETTER_MULTIPLIER);
@ -539,13 +548,13 @@ bool UnigramDictionary::getSplitTwoWordsSuggestion(const int inputLength,
bool UnigramDictionary::getMissingSpaceWords(const int inputLength, const int missingSpacePos) { bool UnigramDictionary::getMissingSpaceWords(const int inputLength, const int missingSpacePos) {
return getSplitTwoWordsSuggestion( return getSplitTwoWordsSuggestion(
inputLength, 0, missingSpacePos, missingSpacePos, inputLength - missingSpacePos); inputLength, 0, missingSpacePos, missingSpacePos, inputLength - missingSpacePos, false);
} }
bool UnigramDictionary::getMistypedSpaceWords(const int inputLength, const int spaceProximityPos) { bool UnigramDictionary::getMistypedSpaceWords(const int inputLength, const int spaceProximityPos) {
return getSplitTwoWordsSuggestion( return getSplitTwoWordsSuggestion(
inputLength, 0, spaceProximityPos, spaceProximityPos + 1, inputLength, 0, spaceProximityPos, spaceProximityPos + 1,
inputLength - spaceProximityPos - 1); inputLength - spaceProximityPos - 1, true);
} }
// Keep this for comparing spec to new getWords // Keep this for comparing spec to new getWords

View File

@ -66,7 +66,7 @@ private:
const int nextLettersSize); const int nextLettersSize);
bool getSplitTwoWordsSuggestion(const int inputLength, bool getSplitTwoWordsSuggestion(const int inputLength,
const int firstWordStartPos, const int firstWordLength, const int firstWordStartPos, const int firstWordLength,
const int secondWordStartPos, const int secondWordLength); const int secondWordStartPos, const int secondWordLength, const bool isSpaceProximity);
bool getMissingSpaceWords(const int inputLength, const int missingSpacePos); bool getMissingSpaceWords(const int inputLength, const int missingSpacePos);
bool getMistypedSpaceWords(const int inputLength, const int spaceProximityPos); bool getMistypedSpaceWords(const int inputLength, const int spaceProximityPos);
// Keep getWordsOld for comparing performance between getWords and getWordsOld // Keep getWordsOld for comparing performance between getWords and getWordsOld