aboutsummaryrefslogtreecommitdiffstats
path: root/native/src
diff options
context:
space:
mode:
Diffstat (limited to 'native/src')
-rw-r--r--native/src/correction.cpp14
-rw-r--r--native/src/correction.h3
-rw-r--r--native/src/defines_touch_position_correction.h61
-rw-r--r--native/src/proximity_info.cpp33
-rw-r--r--native/src/proximity_info.h15
-rw-r--r--native/src/unigram_dictionary.cpp30
-rw-r--r--native/src/unigram_dictionary.h15
7 files changed, 60 insertions, 111 deletions
diff --git a/native/src/correction.cpp b/native/src/correction.cpp
index d5bfed017..9a7e5f35d 100644
--- a/native/src/correction.cpp
+++ b/native/src/correction.cpp
@@ -62,7 +62,8 @@ void Correction::initCorrectionState(
}
void Correction::setCorrectionParams(const int skipPos, const int excessivePos,
- const int transposedPos, const int spaceProximityPos, const int missingSpacePos) {
+ const int transposedPos, const int spaceProximityPos, const int missingSpacePos,
+ const bool useFullEditDistance) {
// TODO: remove
mTransposedPos = transposedPos;
mExcessivePos = excessivePos;
@@ -74,6 +75,7 @@ void Correction::setCorrectionParams(const int skipPos, const int excessivePos,
mSpaceProximityPos = spaceProximityPos;
mMissingSpacePos = missingSpacePos;
+ mUseFullEditDistance = useFullEditDistance;
}
void Correction::checkState() {
@@ -439,7 +441,7 @@ inline static void multiplyIntCapped(const int multiplier, int *base) {
}
inline static int powerIntCapped(const int base, const int n) {
- if (n == 0) return 1;
+ if (n <= 0) return 1;
if (base == 2) {
return n < 31 ? 1 << n : S_INT_MAX;
} else {
@@ -529,6 +531,8 @@ int Correction::RankingAlgorithm::calculateFinalFreq(const int inputIndex, const
const int excessiveCount = correction->mExcessiveCount + correction->mTransposedCount % 2;
const int proximityMatchedCount = correction->mProximityCount;
const bool lastCharExceeded = correction->mLastCharExceeded;
+ const bool useFullEditDistance = correction->mUseFullEditDistance;
+ const int outputLength = outputIndex + 1;
if (skippedCount >= inputLength || inputLength == 0) {
return -1;
}
@@ -682,6 +686,12 @@ int Correction::RankingAlgorithm::calculateFinalFreq(const int inputIndex, const
multiplyIntCapped(fullWordMultiplier, &finalFreq);
}
+ if (useFullEditDistance && outputLength > inputLength + 1) {
+ const int diff = outputLength - inputLength - 1;
+ const int divider = diff < 31 ? 1 << diff : S_INT_MAX;
+ finalFreq = divider > finalFreq ? 1 : finalFreq / divider;
+ }
+
if (DEBUG_DICT_FULL) {
LOGI("calc: %d, %d", outputIndex, sameLength);
}
diff --git a/native/src/correction.h b/native/src/correction.h
index 41130ad77..ddb98b9d8 100644
--- a/native/src/correction.h
+++ b/native/src/correction.h
@@ -44,7 +44,7 @@ public:
// TODO: remove
void setCorrectionParams(const int skipPos, const int excessivePos, const int transposedPos,
- const int spaceProximityPos, const int missingSpacePos);
+ const int spaceProximityPos, const int missingSpacePos, const bool useFullEditDistance);
void checkState();
bool initProcessState(const int index);
@@ -111,6 +111,7 @@ private:
const int FULL_WORD_MULTIPLIER;
const ProximityInfo *mProximityInfo;
+ bool mUseFullEditDistance;
int mMaxEditDistance;
int mMaxDepth;
int mInputLength;
diff --git a/native/src/defines_touch_position_correction.h b/native/src/defines_touch_position_correction.h
deleted file mode 100644
index 122906804..000000000
--- a/native/src/defines_touch_position_correction.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
-**
-** Copyright 2011, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-#ifndef LATINIME_DEFINES_TOUCH_POSITION_CORRECTION_H
-#define LATINIME_DEFINES_TOUCH_POSITION_CORRECTION_H
-
-#define OUTER_SWEET_SPOT_RADIUS_RATIO 1.3
-
-static const char* TOUCH_POSITION_CORRECTION_GROUPS[] = {
- "qwertyuiop",
- "a",
- "sdfghjk",
- "l",
- "zxcvbnm",
-};
-
-// (center X) / (key width)
-static const float RELATIVE_TOUCH_CENTER_X[] = {
- 0, // qwertyuiop
- -0.26871, // a
- 0, // sdfghjk
- 0.028050, // l
- 0, // zxcvbnm
-};
-
-// (center Y) / (key height)
-static const float RELATIVE_TOUCH_CENTER_Y[] = {
- 0.192088, // qwertyuiop
- 0.214100, // a
- 0.216640, // sdfghjk
- 0.233288, // l
- 0.286598, // zxcvbnm
-};
-
-// (sweet spot radius) / ((key width) + (key height))
-static const float SWEET_SPOT_RADIUS[] = {
- 0.148955, // qwertyuiop
- 0.185437, // a
- 0.145522, // sdfghjk
- 0.156882, // l
- 0.144211, // zxcvbnm
-};
-
-#define CORRECTION_GROUP_COUNT \
- ((int)(sizeof(TOUCH_POSITION_CORRECTION_GROUPS) / sizeof(TOUCH_POSITION_CORRECTION_GROUPS[0])))
-
-#endif // LATINIME_DEFINES_TOUCH_POSITION_CORRECTION_H
diff --git a/native/src/proximity_info.cpp b/native/src/proximity_info.cpp
index 58842b92f..4ff6e0ac0 100644
--- a/native/src/proximity_info.cpp
+++ b/native/src/proximity_info.cpp
@@ -20,7 +20,6 @@
#define LOG_TAG "LatinIME: proximity_info.cpp"
-#include "defines_touch_position_correction.h"
#include "dictionary.h"
#include "proximity_info.h"
@@ -38,12 +37,13 @@ ProximityInfo::ProximityInfo(const int maxProximityCharsSize, const int keyboard
const int keyboardHeight, const int gridWidth, const int gridHeight,
const uint32_t *proximityCharsArray, const int keyCount, const int32_t *keyXCoordinates,
const int32_t *keyYCoordinates, const int32_t *keyWidths, const int32_t *keyHeights,
- const int32_t *keyCharCodes, int themeId)
+ const int32_t *keyCharCodes, const float *sweetSpotCenterXs, const float *sweetSpotCenterYs,
+ const float *sweetSpotRadii)
: MAX_PROXIMITY_CHARS_SIZE(maxProximityCharsSize), KEYBOARD_WIDTH(keyboardWidth),
KEYBOARD_HEIGHT(keyboardHeight), GRID_WIDTH(gridWidth), GRID_HEIGHT(gridHeight),
CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth),
CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight),
- KEY_COUNT(min(keyCount, MAX_KEY_COUNT_IN_A_KEYBOARD)), THEME_ID(themeId) {
+ KEY_COUNT(min(keyCount, MAX_KEY_COUNT_IN_A_KEYBOARD)) {
const int len = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE;
mProximityCharsArray = new uint32_t[len];
if (DEBUG_PROXIMITY_INFO) {
@@ -56,33 +56,24 @@ ProximityInfo::ProximityInfo(const int maxProximityCharsSize, const int keyboard
copyOrFillZero(mKeyWidths, keyWidths, KEY_COUNT * sizeof(mKeyWidths[0]));
copyOrFillZero(mKeyHeights, keyHeights, KEY_COUNT * sizeof(mKeyHeights[0]));
copyOrFillZero(mKeyCharCodes, keyCharCodes, KEY_COUNT * sizeof(mKeyCharCodes[0]));
+ copyOrFillZero(mSweetSpotCenterXs, sweetSpotCenterXs,
+ KEY_COUNT * sizeof(mSweetSpotCenterXs[0]));
+ copyOrFillZero(mSweetSpotCenterYs, sweetSpotCenterYs,
+ KEY_COUNT * sizeof(mSweetSpotCenterYs[0]));
+ copyOrFillZero(mSweetSpotRadii, sweetSpotRadii, KEY_COUNT * sizeof(mSweetSpotRadii[0]));
- initializeCodeToGroup();
initializeCodeToKeyIndex();
}
-// Build the reversed look up table from the char code to the index in its group.
-// see TOUCH_POSITION_CORRECTION_GROUPS
-void ProximityInfo::initializeCodeToGroup() {
- memset(mCodeToGroup, -1, (MAX_GROUPED_CHAR_CODE + 1) * sizeof(mCodeToGroup[0]));
- for (int i = 0; i < CORRECTION_GROUP_COUNT; ++i) {
- const char *group = TOUCH_POSITION_CORRECTION_GROUPS[i];
- for (int j = 0; group[j]; ++j) {
- const int code = group[j];
- if (0 <= code && code <= MAX_GROUPED_CHAR_CODE)
- mCodeToGroup[code] = i;
- }
- }
-}
-
// Build the reversed look up table from the char code to the index in mKeyXCoordinates,
// mKeyYCoordinates, mKeyWidths, mKeyHeights, mKeyCharCodes.
void ProximityInfo::initializeCodeToKeyIndex() {
- memset(mCodeToKeyIndex, -1, (MAX_GROUPED_CHAR_CODE + 1) * sizeof(mCodeToKeyIndex[0]));
+ memset(mCodeToKeyIndex, -1, (MAX_CHAR_CODE + 1) * sizeof(mCodeToKeyIndex[0]));
for (int i = 0; i < KEY_COUNT; ++i) {
const int code = mKeyCharCodes[i];
- if (0 <= code && code <= MAX_GROUPED_CHAR_CODE)
+ if (0 <= code && code <= MAX_CHAR_CODE) {
mCodeToKeyIndex[code] = i;
+ }
}
}
@@ -210,6 +201,6 @@ bool ProximityInfo::sameAsTyped(const unsigned short *word, int length) const {
}
const int ProximityInfo::MAX_KEY_COUNT_IN_A_KEYBOARD;
-const int ProximityInfo::MAX_GROUPED_CHAR_CODE;
+const int ProximityInfo::MAX_CHAR_CODE;
} // namespace latinime
diff --git a/native/src/proximity_info.h b/native/src/proximity_info.h
index 3190e73ef..b1e8236d3 100644
--- a/native/src/proximity_info.h
+++ b/native/src/proximity_info.h
@@ -37,7 +37,8 @@ public:
const int keybaordHeight, const int gridWidth, const int gridHeight,
const uint32_t *proximityCharsArray, const int keyCount, const int32_t *keyXCoordinates,
const int32_t *keyYCoordinates, const int32_t *keyWidths, const int32_t *keyHeights,
- const int32_t *keyCharCodes, int themeId);
+ const int32_t *keyCharCodes, const float *sweetSpotCenterXs,
+ const float *sweetSpotCenterYs, const float *sweetSpotRadii);
~ProximityInfo();
bool hasSpaceProximity(const int x, const int y) const;
void setInputParams(const int* inputCodes, const int inputLength);
@@ -55,11 +56,10 @@ public:
private:
// 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 TOUCH_POSITION_CORRECTION_GROUP
- static const int MAX_GROUPED_CHAR_CODE = 127;
+ // The upper limit of the char code in mCodeToKeyIndex
+ static const int MAX_CHAR_CODE = 127;
int getStartIndexFromCoordinates(const int x, const int y) const;
- void initializeCodeToGroup();
void initializeCodeToKeyIndex();
const int MAX_PROXIMITY_CHARS_SIZE;
const int KEYBOARD_WIDTH;
@@ -69,7 +69,6 @@ private:
const int CELL_WIDTH;
const int CELL_HEIGHT;
const int KEY_COUNT;
- const int THEME_ID;
const int *mInputCodes;
uint32_t *mProximityCharsArray;
int32_t mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
@@ -77,10 +76,12 @@ private:
int32_t mKeyWidths[MAX_KEY_COUNT_IN_A_KEYBOARD];
int32_t mKeyHeights[MAX_KEY_COUNT_IN_A_KEYBOARD];
int32_t mKeyCharCodes[MAX_KEY_COUNT_IN_A_KEYBOARD];
+ float mSweetSpotCenterXs[MAX_KEY_COUNT_IN_A_KEYBOARD];
+ float mSweetSpotCenterYs[MAX_KEY_COUNT_IN_A_KEYBOARD];
+ float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD];
int mInputLength;
unsigned short mPrimaryInputWord[MAX_WORD_LENGTH_INTERNAL];
- int mCodeToGroup[MAX_GROUPED_CHAR_CODE + 1];
- int mCodeToKeyIndex[MAX_GROUPED_CHAR_CODE + 1];
+ int mCodeToKeyIndex[MAX_CHAR_CODE + 1];
};
} // namespace latinime
diff --git a/native/src/unigram_dictionary.cpp b/native/src/unigram_dictionary.cpp
index 517dc843e..1b798a8f1 100644
--- a/native/src/unigram_dictionary.cpp
+++ b/native/src/unigram_dictionary.cpp
@@ -132,7 +132,8 @@ void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximit
memcpy(codesDest, codesSrc, remainingBytes);
getWordSuggestions(proximityInfo, xcoordinates, ycoordinates, codesBuffer,
- (codesDest - codesBuffer) / MAX_PROXIMITY_CHARS + codesRemain, outWords, frequencies);
+ (codesDest - codesBuffer) / MAX_PROXIMITY_CHARS + codesRemain, outWords, frequencies,
+ flags);
}
int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates,
@@ -146,7 +147,7 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo, const int *x
codesSize, flags, codes, codesSize, 0, codesBuffer, outWords, frequencies);
} else { // Normal processing
getWordSuggestions(proximityInfo, xcoordinates, ycoordinates, codes, codesSize,
- outWords, frequencies);
+ outWords, frequencies, flags);
}
PROF_START(20);
@@ -175,7 +176,7 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo, const int *x
void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
const int *xcoordinates, const int *ycoordinates, const int *codes, const int codesSize,
- unsigned short *outWords, int *frequencies) {
+ unsigned short *outWords, int *frequencies, const int flags) {
PROF_OPEN;
PROF_START(0);
@@ -187,9 +188,10 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
mCorrection->initCorrection(mProximityInfo, mInputLength, maxDepth);
PROF_END(0);
+ const bool useFullEditDistance = USE_FULL_EDIT_DISTANCE & flags;
// TODO: remove
PROF_START(1);
- getSuggestionCandidates();
+ getSuggestionCandidates(useFullEditDistance);
PROF_END(1);
PROF_START(2);
@@ -212,7 +214,7 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
if (DEBUG_DICT) {
LOGI("--- Suggest missing space characters %d", i);
}
- getMissingSpaceWords(mInputLength, i, mCorrection);
+ getMissingSpaceWords(mInputLength, i, mCorrection, useFullEditDistance);
}
}
PROF_END(5);
@@ -231,7 +233,7 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
i, x, y, proximityInfo->hasSpaceProximity(x, y));
}
if (proximityInfo->hasSpaceProximity(x, y)) {
- getMistypedSpaceWords(mInputLength, i, mCorrection);
+ getMistypedSpaceWords(mInputLength, i, mCorrection, useFullEditDistance);
}
}
}
@@ -315,10 +317,10 @@ bool UnigramDictionary::addWord(unsigned short *word, int length, int frequency)
static const char QUOTE = '\'';
static const char SPACE = ' ';
-void UnigramDictionary::getSuggestionCandidates() {
+void UnigramDictionary::getSuggestionCandidates(const bool useFullEditDistance) {
// TODO: Remove setCorrectionParams
mCorrection->setCorrectionParams(0, 0, 0,
- -1 /* spaceProximityPos */, -1 /* missingSpacePos */);
+ -1 /* spaceProximityPos */, -1 /* missingSpacePos */, useFullEditDistance);
int rootPosition = ROOT_POS;
// Get the number of children of root, then increment the position
int childCount = Dictionary::getCount(DICT_ROOT, &rootPosition);
@@ -349,16 +351,20 @@ void UnigramDictionary::getSuggestionCandidates() {
}
void UnigramDictionary::getMissingSpaceWords(
- const int inputLength, const int missingSpacePos, Correction *correction) {
+ const int inputLength, const int missingSpacePos, Correction *correction,
+ const bool useFullEditDistance) {
correction->setCorrectionParams(-1 /* skipPos */, -1 /* excessivePos */,
- -1 /* transposedPos */, -1 /* spaceProximityPos */, missingSpacePos);
+ -1 /* transposedPos */, -1 /* spaceProximityPos */, missingSpacePos,
+ useFullEditDistance);
getSplitTwoWordsSuggestion(inputLength, correction);
}
void UnigramDictionary::getMistypedSpaceWords(
- const int inputLength, const int spaceProximityPos, Correction *correction) {
+ const int inputLength, const int spaceProximityPos, Correction *correction,
+ const bool useFullEditDistance) {
correction->setCorrectionParams(-1 /* skipPos */, -1 /* excessivePos */,
- -1 /* transposedPos */, spaceProximityPos, -1 /* missingSpacePos */);
+ -1 /* transposedPos */, spaceProximityPos, -1 /* missingSpacePos */,
+ useFullEditDistance);
getSplitTwoWordsSuggestion(inputLength, correction);
}
diff --git a/native/src/unigram_dictionary.h b/native/src/unigram_dictionary.h
index 65746db8d..ef9709a89 100644
--- a/native/src/unigram_dictionary.h
+++ b/native/src/unigram_dictionary.h
@@ -78,7 +78,7 @@ private:
void getWordSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates,
const int *ycoordinates, const int *codes, const int codesSize,
- unsigned short *outWords, int *frequencies);
+ unsigned short *outWords, int *frequencies, const int flags);
bool isDigraph(const int* codes, const int i, const int codesSize) const;
void getWordWithDigraphSuggestionsRec(ProximityInfo *proximityInfo,
const int *xcoordinates, const int* ycoordinates, const int *codesBuffer,
@@ -87,13 +87,13 @@ private:
void initSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates,
const int *ycoordinates, const int *codes, const int codesSize,
unsigned short *outWords, int *frequencies);
- void getSuggestionCandidates();
+ void getSuggestionCandidates(const bool useFullEditDistance);
bool addWord(unsigned short *word, int length, int frequency);
void getSplitTwoWordsSuggestion(const int inputLength, Correction *correction);
- void getMissingSpaceWords(
- const int inputLength, const int missingSpacePos, Correction *correction);
- void getMistypedSpaceWords(
- const int inputLength, const int spaceProximityPos, Correction *correction);
+ void getMissingSpaceWords(const int inputLength, const int missingSpacePos,
+ Correction *correction, const bool useFullEditDistance);
+ void getMistypedSpaceWords(const int inputLength, const int spaceProximityPos,
+ Correction *correction, const bool useFullEditDistance);
void onTerminal(const int freq, Correction *correction);
bool needsToSkipCurrentNode(const unsigned short c,
const int inputIndex, const int skipPos, const int depth);
@@ -122,7 +122,8 @@ private:
// or something very bad (like, the apocalypse) will happen.
// Please update both at the same time.
enum {
- REQUIRES_GERMAN_UMLAUT_PROCESSING = 0x1
+ REQUIRES_GERMAN_UMLAUT_PROCESSING = 0x1,
+ USE_FULL_EDIT_DISTANCE = 0x2
};
static const struct digraph_t { int first; int second; } GERMAN_UMLAUT_DIGRAPHS[];