am 29432f84: Create a new directory for layout-related implementations
* commit '29432f843a8cd6ffb2be286104964592e80d77c9': Create a new directory for layout-related implementationsmain
commit
f002debdfe
|
@ -53,10 +53,6 @@ LATIN_IME_CORE_SRC_FILES := \
|
||||||
dictionary.cpp \
|
dictionary.cpp \
|
||||||
dic_traverse_wrapper.cpp \
|
dic_traverse_wrapper.cpp \
|
||||||
digraph_utils.cpp \
|
digraph_utils.cpp \
|
||||||
proximity_info.cpp \
|
|
||||||
proximity_info_params.cpp \
|
|
||||||
proximity_info_state.cpp \
|
|
||||||
proximity_info_state_utils.cpp \
|
|
||||||
unigram_dictionary.cpp \
|
unigram_dictionary.cpp \
|
||||||
words_priority_queue.cpp \
|
words_priority_queue.cpp \
|
||||||
suggest/core/suggest.cpp \
|
suggest/core/suggest.cpp \
|
||||||
|
@ -64,6 +60,11 @@ LATIN_IME_CORE_SRC_FILES := \
|
||||||
dic_node.cpp \
|
dic_node.cpp \
|
||||||
dic_node_utils.cpp \
|
dic_node_utils.cpp \
|
||||||
dic_nodes_cache.cpp) \
|
dic_nodes_cache.cpp) \
|
||||||
|
$(addprefix suggest/core/layout/, \
|
||||||
|
proximity_info.cpp \
|
||||||
|
proximity_info_params.cpp \
|
||||||
|
proximity_info_state.cpp \
|
||||||
|
proximity_info_state_utils.cpp) \
|
||||||
suggest/core/policy/weighting.cpp \
|
suggest/core/policy/weighting.cpp \
|
||||||
suggest/core/session/dic_traverse_session.cpp \
|
suggest/core/session/dic_traverse_session.cpp \
|
||||||
suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp \
|
suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp \
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
#define LOG_TAG "LatinIME: jni: ProximityInfo"
|
#define LOG_TAG "LatinIME: jni: ProximityInfo"
|
||||||
|
|
||||||
#include "com_android_inputmethod_keyboard_ProximityInfo.h"
|
#include "com_android_inputmethod_keyboard_ProximityInfo.h"
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
#include "jni_common.h"
|
#include "jni_common.h"
|
||||||
#include "proximity_info.h"
|
#include "suggest/core/layout/proximity_info.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
#include "char_utils.h"
|
#include "char_utils.h"
|
||||||
#include "correction.h"
|
#include "correction.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "proximity_info_state.h"
|
#include "suggest/core/layout/proximity_info_state.h"
|
||||||
#include "suggest_utils.h"
|
#include "suggest/core/layout/touch_position_correction_utils.h"
|
||||||
#include "suggest/policyimpl/utils/edit_distance.h"
|
#include "suggest/policyimpl/utils/edit_distance.h"
|
||||||
#include "suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy.h"
|
#include "suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy.h"
|
||||||
|
|
||||||
|
@ -676,8 +676,8 @@ inline static bool isUpperCase(unsigned short c) {
|
||||||
if (i < adjustedProximityMatchedCount) {
|
if (i < adjustedProximityMatchedCount) {
|
||||||
multiplyIntCapped(typedLetterMultiplier, &finalFreq);
|
multiplyIntCapped(typedLetterMultiplier, &finalFreq);
|
||||||
}
|
}
|
||||||
const float factor =
|
const float factor = TouchPositionCorrectionUtils::getLengthScalingFactor(
|
||||||
SuggestUtils::getLengthScalingFactor(static_cast<float>(squaredDistance));
|
static_cast<float>(squaredDistance));
|
||||||
if (factor > 0.0f) {
|
if (factor > 0.0f) {
|
||||||
multiplyRate(static_cast<int>(factor * 100.0f), &finalFreq);
|
multiplyRate(static_cast<int>(factor * 100.0f), &finalFreq);
|
||||||
} else if (squaredDistance == PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO) {
|
} else if (squaredDistance == PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO) {
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include "correction_state.h"
|
#include "correction_state.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "proximity_info_state.h"
|
#include "suggest/core/layout/proximity_info_state.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2012 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_GEOMETRY_UTILS_H
|
|
||||||
#define LATINIME_GEOMETRY_UTILS_H
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
#include "defines.h"
|
|
||||||
|
|
||||||
#define ROUND_FLOAT_10000(f) ((f) < 1000.0f && (f) > 0.001f) \
|
|
||||||
? (floorf((f) * 10000.0f) / 10000.0f) : (f)
|
|
||||||
|
|
||||||
namespace latinime {
|
|
||||||
|
|
||||||
static inline float SQUARE_FLOAT(const float x) { return x * x; }
|
|
||||||
|
|
||||||
static AK_FORCE_INLINE float getAngle(const int x1, const int y1, const int x2, const int y2) {
|
|
||||||
const int dx = x1 - x2;
|
|
||||||
const int dy = y1 - y2;
|
|
||||||
if (dx == 0 && dy == 0) return 0.0f;
|
|
||||||
return atan2f(static_cast<float>(dy), static_cast<float>(dx));
|
|
||||||
}
|
|
||||||
|
|
||||||
static AK_FORCE_INLINE float getAngleDiff(const float a1, const float a2) {
|
|
||||||
const float deltaA = fabsf(a1 - a2);
|
|
||||||
const float diff = ROUND_FLOAT_10000(deltaA);
|
|
||||||
if (diff > M_PI_F) {
|
|
||||||
const float normalizedDiff = 2.0f * M_PI_F - diff;
|
|
||||||
return ROUND_FLOAT_10000(normalizedDiff);
|
|
||||||
}
|
|
||||||
return diff;
|
|
||||||
}
|
|
||||||
|
|
||||||
static AK_FORCE_INLINE int getDistanceInt(const int x1, const int y1, const int x2,
|
|
||||||
const int y2) {
|
|
||||||
return static_cast<int>(hypotf(static_cast<float>(x1 - x2), static_cast<float>(y1 - y2)));
|
|
||||||
}
|
|
||||||
} // namespace latinime
|
|
||||||
#endif // LATINIME_GEOMETRY_UTILS_H
|
|
|
@ -22,8 +22,8 @@
|
||||||
#include "dic_node_utils.h"
|
#include "dic_node_utils.h"
|
||||||
#include "dic_node_vector.h"
|
#include "dic_node_vector.h"
|
||||||
#include "multi_bigram_map.h"
|
#include "multi_bigram_map.h"
|
||||||
#include "proximity_info.h"
|
#include "suggest/core/layout/proximity_info.h"
|
||||||
#include "proximity_info_state.h"
|
#include "suggest/core/layout/proximity_info_state.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2012 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_GEOMETRY_UTILS_H
|
||||||
|
#define LATINIME_GEOMETRY_UTILS_H
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
|
#define ROUND_FLOAT_10000(f) ((f) < 1000.0f && (f) > 0.001f) \
|
||||||
|
? (floorf((f) * 10000.0f) / 10000.0f) : (f)
|
||||||
|
|
||||||
|
namespace latinime {
|
||||||
|
|
||||||
|
class GeometryUtils {
|
||||||
|
public:
|
||||||
|
static inline float SQUARE_FLOAT(const float x) { return x * x; }
|
||||||
|
|
||||||
|
static AK_FORCE_INLINE float getAngle(const int x1, const int y1, const int x2, const int y2) {
|
||||||
|
const int dx = x1 - x2;
|
||||||
|
const int dy = y1 - y2;
|
||||||
|
if (dx == 0 && dy == 0) return 0.0f;
|
||||||
|
return atan2f(static_cast<float>(dy), static_cast<float>(dx));
|
||||||
|
}
|
||||||
|
|
||||||
|
static AK_FORCE_INLINE float getAngleDiff(const float a1, const float a2) {
|
||||||
|
const float deltaA = fabsf(a1 - a2);
|
||||||
|
const float diff = ROUND_FLOAT_10000(deltaA);
|
||||||
|
if (diff > M_PI_F) {
|
||||||
|
const float normalizedDiff = 2.0f * M_PI_F - diff;
|
||||||
|
return ROUND_FLOAT_10000(normalizedDiff);
|
||||||
|
}
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
static AK_FORCE_INLINE int getDistanceInt(const int x1, const int y1, const int x2,
|
||||||
|
const int y2) {
|
||||||
|
return static_cast<int>(hypotf(static_cast<float>(x1 - x2), static_cast<float>(y1 - y2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
DISALLOW_IMPLICIT_CONSTRUCTORS(GeometryUtils);
|
||||||
|
};
|
||||||
|
} // namespace latinime
|
||||||
|
#endif // LATINIME_GEOMETRY_UTILS_H
|
|
@ -14,6 +14,8 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "suggest/core/layout/proximity_info.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
@ -22,10 +24,9 @@
|
||||||
#include "additional_proximity_chars.h"
|
#include "additional_proximity_chars.h"
|
||||||
#include "char_utils.h"
|
#include "char_utils.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "geometry_utils.h"
|
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
#include "proximity_info.h"
|
#include "suggest/core/layout/geometry_utils.h"
|
||||||
#include "proximity_info_params.h"
|
#include "suggest/core/layout/proximity_info_params.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr,
|
||||||
MOST_COMMON_KEY_WIDTH_SQUARE(mostCommonKeyWidth * mostCommonKeyWidth),
|
MOST_COMMON_KEY_WIDTH_SQUARE(mostCommonKeyWidth * mostCommonKeyWidth),
|
||||||
MOST_COMMON_KEY_HEIGHT(mostCommonKeyHeight),
|
MOST_COMMON_KEY_HEIGHT(mostCommonKeyHeight),
|
||||||
NORMALIZED_SQUARED_MOST_COMMON_KEY_HYPOTENUSE(1.0f +
|
NORMALIZED_SQUARED_MOST_COMMON_KEY_HYPOTENUSE(1.0f +
|
||||||
SQUARE_FLOAT(static_cast<float>(mostCommonKeyHeight) /
|
GeometryUtils::SQUARE_FLOAT(static_cast<float>(mostCommonKeyHeight) /
|
||||||
static_cast<float>(mostCommonKeyWidth))),
|
static_cast<float>(mostCommonKeyWidth))),
|
||||||
CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth),
|
CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth),
|
||||||
CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight),
|
CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight),
|
||||||
|
@ -150,7 +151,7 @@ float ProximityInfo::getNormalizedSquaredDistanceFromCenterFloatG(
|
||||||
const float touchY = static_cast<float>(y);
|
const float touchY = static_cast<float>(y);
|
||||||
const float keyWidth = static_cast<float>(getMostCommonKeyWidth());
|
const float keyWidth = static_cast<float>(getMostCommonKeyWidth());
|
||||||
return ProximityInfoUtils::getSquaredDistanceFloat(centerX, centerY, touchX, touchY)
|
return ProximityInfoUtils::getSquaredDistanceFloat(centerX, centerY, touchX, touchY)
|
||||||
/ SQUARE_FLOAT(keyWidth);
|
/ GeometryUtils::SQUARE_FLOAT(keyWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ProximityInfo::getCodePointOf(const int keyIndex) const {
|
int ProximityInfo::getCodePointOf(const int keyIndex) const {
|
||||||
|
@ -173,7 +174,7 @@ void ProximityInfo::initializeG() {
|
||||||
for (int i = 0; i < KEY_COUNT; i++) {
|
for (int i = 0; i < KEY_COUNT; i++) {
|
||||||
mKeyKeyDistancesG[i][i] = 0;
|
mKeyKeyDistancesG[i][i] = 0;
|
||||||
for (int j = i + 1; j < KEY_COUNT; j++) {
|
for (int j = i + 1; j < KEY_COUNT; j++) {
|
||||||
mKeyKeyDistancesG[i][j] = getDistanceInt(
|
mKeyKeyDistancesG[i][j] = GeometryUtils::getDistanceInt(
|
||||||
mCenterXsG[i], mCenterYsG[i], mCenterXsG[j], mCenterYsG[j]);
|
mCenterXsG[i], mCenterYsG[i], mCenterXsG[j], mCenterYsG[j]);
|
||||||
mKeyKeyDistancesG[j][i] = mKeyKeyDistancesG[i][j];
|
mKeyKeyDistancesG[j][i] = mKeyKeyDistancesG[i][j];
|
||||||
}
|
}
|
|
@ -20,7 +20,7 @@
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "hash_map_compat.h"
|
#include "hash_map_compat.h"
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
#include "proximity_info_utils.h"
|
#include "suggest/core/layout/proximity_info_utils.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "proximity_info_params.h"
|
#include "suggest/core/layout/proximity_info_params.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
const float ProximityInfoParams::NOT_A_DISTANCE_FLOAT = -1.0f;
|
const float ProximityInfoParams::NOT_A_DISTANCE_FLOAT = -1.0f;
|
|
@ -14,6 +14,8 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "suggest/core/layout/proximity_info_state.h"
|
||||||
|
|
||||||
#include <cstring> // for memset() and memcpy()
|
#include <cstring> // for memset() and memcpy()
|
||||||
#include <sstream> // for debug prints
|
#include <sstream> // for debug prints
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -21,10 +23,9 @@
|
||||||
#define LOG_TAG "LatinIME: proximity_info_state.cpp"
|
#define LOG_TAG "LatinIME: proximity_info_state.cpp"
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "geometry_utils.h"
|
#include "suggest/core/layout/geometry_utils.h"
|
||||||
#include "proximity_info.h"
|
#include "suggest/core/layout/proximity_info.h"
|
||||||
#include "proximity_info_state.h"
|
#include "suggest/core/layout/proximity_info_state_utils.h"
|
||||||
#include "proximity_info_state_utils.h"
|
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
|
@ -23,8 +23,8 @@
|
||||||
#include "char_utils.h"
|
#include "char_utils.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "hash_map_compat.h"
|
#include "hash_map_compat.h"
|
||||||
#include "proximity_info_params.h"
|
#include "suggest/core/layout/proximity_info_params.h"
|
||||||
#include "proximity_info_state_utils.h"
|
#include "suggest/core/layout/proximity_info_state_utils.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
|
@ -14,16 +14,17 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "suggest/core/layout/proximity_info_state_utils.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring> // for memset()
|
#include <cstring> // for memset()
|
||||||
#include <sstream> // for debug prints
|
#include <sstream> // for debug prints
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "geometry_utils.h"
|
#include "suggest/core/layout/geometry_utils.h"
|
||||||
#include "proximity_info.h"
|
#include "suggest/core/layout/proximity_info.h"
|
||||||
#include "proximity_info_params.h"
|
#include "suggest/core/layout/proximity_info_params.h"
|
||||||
#include "proximity_info_state_utils.h"
|
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
@ -103,12 +104,12 @@ namespace latinime {
|
||||||
const int time = times ? times[i] : -1;
|
const int time = times ? times[i] : -1;
|
||||||
|
|
||||||
if (i > 1) {
|
if (i > 1) {
|
||||||
const float prevAngle = getAngle(
|
const float prevAngle = GeometryUtils::getAngle(
|
||||||
inputXCoordinates[i - 2], inputYCoordinates[i - 2],
|
inputXCoordinates[i - 2], inputYCoordinates[i - 2],
|
||||||
inputXCoordinates[i - 1], inputYCoordinates[i - 1]);
|
inputXCoordinates[i - 1], inputYCoordinates[i - 1]);
|
||||||
const float currentAngle = getAngle(
|
const float currentAngle = GeometryUtils::getAngle(
|
||||||
inputXCoordinates[i - 1], inputYCoordinates[i - 1], x, y);
|
inputXCoordinates[i - 1], inputYCoordinates[i - 1], x, y);
|
||||||
sumAngle += getAngleDiff(prevAngle, currentAngle);
|
sumAngle += GeometryUtils::getAngleDiff(prevAngle, currentAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pushTouchPoint(proximityInfo, maxPointToKeyLength, i, c, x, y, time,
|
if (pushTouchPoint(proximityInfo, maxPointToKeyLength, i, c, x, y, time,
|
||||||
|
@ -157,7 +158,8 @@ namespace latinime {
|
||||||
const float sweetSpotCenterY = proximityInfo->getSweetSpotCenterYAt(keyIndex);
|
const float sweetSpotCenterY = proximityInfo->getSweetSpotCenterYAt(keyIndex);
|
||||||
const float inputX = static_cast<float>((*sampledInputXs)[inputIndex]);
|
const float inputX = static_cast<float>((*sampledInputXs)[inputIndex]);
|
||||||
const float inputY = static_cast<float>((*sampledInputYs)[inputIndex]);
|
const float inputY = static_cast<float>((*sampledInputYs)[inputIndex]);
|
||||||
return SQUARE_FLOAT(inputX - sweetSpotCenterX) + SQUARE_FLOAT(inputY - sweetSpotCenterY);
|
return GeometryUtils::SQUARE_FLOAT(inputX - sweetSpotCenterX)
|
||||||
|
+ GeometryUtils::SQUARE_FLOAT(inputY - sweetSpotCenterY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ float ProximityInfoStateUtils::calculateNormalizedSquaredDistance(
|
/* static */ float ProximityInfoStateUtils::calculateNormalizedSquaredDistance(
|
||||||
|
@ -174,7 +176,8 @@ namespace latinime {
|
||||||
}
|
}
|
||||||
const float squaredDistance = calculateSquaredDistanceFromSweetSpotCenter(proximityInfo,
|
const float squaredDistance = calculateSquaredDistanceFromSweetSpotCenter(proximityInfo,
|
||||||
sampledInputXs, sampledInputYs, keyIndex, inputIndex);
|
sampledInputXs, sampledInputYs, keyIndex, inputIndex);
|
||||||
const float squaredRadius = SQUARE_FLOAT(proximityInfo->getSweetSpotRadiiAt(keyIndex));
|
const float squaredRadius = GeometryUtils::SQUARE_FLOAT(
|
||||||
|
proximityInfo->getSweetSpotRadiiAt(keyIndex));
|
||||||
return squaredDistance / squaredRadius;
|
return squaredDistance / squaredRadius;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +288,7 @@ namespace latinime {
|
||||||
if (i < sampledInputSize - 1 && j >= (*sampledInputIndice)[i + 1]) {
|
if (i < sampledInputSize - 1 && j >= (*sampledInputIndice)[i + 1]) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
length += getDistanceInt(xCoordinates[j], yCoordinates[j],
|
length += GeometryUtils::getDistanceInt(xCoordinates[j], yCoordinates[j],
|
||||||
xCoordinates[j + 1], yCoordinates[j + 1]);
|
xCoordinates[j + 1], yCoordinates[j + 1]);
|
||||||
duration += times[j + 1] - times[j];
|
duration += times[j + 1] - times[j];
|
||||||
}
|
}
|
||||||
|
@ -296,7 +299,7 @@ namespace latinime {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// TODO: use mSampledLengthCache instead?
|
// TODO: use mSampledLengthCache instead?
|
||||||
length += getDistanceInt(xCoordinates[j], yCoordinates[j],
|
length += GeometryUtils::getDistanceInt(xCoordinates[j], yCoordinates[j],
|
||||||
xCoordinates[j + 1], yCoordinates[j + 1]);
|
xCoordinates[j + 1], yCoordinates[j + 1]);
|
||||||
duration += times[j + 1] - times[j];
|
duration += times[j + 1] - times[j];
|
||||||
}
|
}
|
||||||
|
@ -349,7 +352,7 @@ namespace latinime {
|
||||||
const int y1 = (*sampledInputYs)[index0];
|
const int y1 = (*sampledInputYs)[index0];
|
||||||
const int x2 = (*sampledInputXs)[index1];
|
const int x2 = (*sampledInputXs)[index1];
|
||||||
const int y2 = (*sampledInputYs)[index1];
|
const int y2 = (*sampledInputYs)[index1];
|
||||||
return getAngle(x1, y1, x2, y2);
|
return GeometryUtils::getAngle(x1, y1, x2, y2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculating point to key distance for all near keys and returning the distance between
|
// Calculating point to key distance for all near keys and returning the distance between
|
||||||
|
@ -411,9 +414,9 @@ namespace latinime {
|
||||||
}
|
}
|
||||||
|
|
||||||
const int baseSampleRate = mostCommonKeyWidth;
|
const int baseSampleRate = mostCommonKeyWidth;
|
||||||
const int distPrev = getDistanceInt(sampledInputXs->back(), sampledInputYs->back(),
|
const int distPrev = GeometryUtils::getDistanceInt(sampledInputXs->back(),
|
||||||
(*sampledInputXs)[size - 2], (*sampledInputYs)[size - 2])
|
sampledInputYs->back(), (*sampledInputXs)[size - 2],
|
||||||
* ProximityInfoParams::DISTANCE_BASE_SCALE;
|
(*sampledInputYs)[size - 2]) * ProximityInfoParams::DISTANCE_BASE_SCALE;
|
||||||
float score = 0.0f;
|
float score = 0.0f;
|
||||||
|
|
||||||
// Location
|
// Location
|
||||||
|
@ -425,10 +428,11 @@ namespace latinime {
|
||||||
score += ProximityInfoParams::LOCALMIN_DISTANCE_AND_NEAR_TO_KEY_SCORE;
|
score += ProximityInfoParams::LOCALMIN_DISTANCE_AND_NEAR_TO_KEY_SCORE;
|
||||||
}
|
}
|
||||||
// Angle
|
// Angle
|
||||||
const float angle1 = getAngle(x, y, sampledInputXs->back(), sampledInputYs->back());
|
const float angle1 = GeometryUtils::getAngle(x, y, sampledInputXs->back(),
|
||||||
const float angle2 = getAngle(sampledInputXs->back(), sampledInputYs->back(),
|
sampledInputYs->back());
|
||||||
|
const float angle2 = GeometryUtils::getAngle(sampledInputXs->back(), sampledInputYs->back(),
|
||||||
(*sampledInputXs)[size - 2], (*sampledInputYs)[size - 2]);
|
(*sampledInputXs)[size - 2], (*sampledInputYs)[size - 2]);
|
||||||
const float angleDiff = getAngleDiff(angle1, angle2);
|
const float angleDiff = GeometryUtils::getAngleDiff(angle1, angle2);
|
||||||
|
|
||||||
// Save corner
|
// Save corner
|
||||||
if (distPrev > baseSampleRate * ProximityInfoParams::CORNER_CHECK_DISTANCE_THRESHOLD_SCALE
|
if (distPrev > baseSampleRate * ProximityInfoParams::CORNER_CHECK_DISTANCE_THRESHOLD_SCALE
|
||||||
|
@ -472,13 +476,13 @@ namespace latinime {
|
||||||
}
|
}
|
||||||
// Check if the last point should be skipped.
|
// Check if the last point should be skipped.
|
||||||
if (isLastPoint && size > 0) {
|
if (isLastPoint && size > 0) {
|
||||||
if (getDistanceInt(x, y, sampledInputXs->back(), sampledInputYs->back())
|
if (GeometryUtils::getDistanceInt(x, y, sampledInputXs->back(), sampledInputYs->back())
|
||||||
* ProximityInfoParams::LAST_POINT_SKIP_DISTANCE_SCALE < mostCommonKeyWidth) {
|
* ProximityInfoParams::LAST_POINT_SKIP_DISTANCE_SCALE < mostCommonKeyWidth) {
|
||||||
// This point is not used because it's too close to the previous point.
|
// This point is not used because it's too close to the previous point.
|
||||||
if (DEBUG_GEO_FULL) {
|
if (DEBUG_GEO_FULL) {
|
||||||
AKLOGI("p0: size = %zd, x = %d, y = %d, lx = %d, ly = %d, dist = %d, "
|
AKLOGI("p0: size = %zd, x = %d, y = %d, lx = %d, ly = %d, dist = %d, "
|
||||||
"width = %d", size, x, y, sampledInputXs->back(),
|
"width = %d", size, x, y, sampledInputXs->back(),
|
||||||
sampledInputYs->back(), getDistanceInt(
|
sampledInputYs->back(), GeometryUtils::getDistanceInt(
|
||||||
x, y, sampledInputXs->back(), sampledInputYs->back()),
|
x, y, sampledInputXs->back(), sampledInputYs->back()),
|
||||||
mostCommonKeyWidth
|
mostCommonKeyWidth
|
||||||
/ ProximityInfoParams::LAST_POINT_SKIP_DISTANCE_SCALE);
|
/ ProximityInfoParams::LAST_POINT_SKIP_DISTANCE_SCALE);
|
||||||
|
@ -499,7 +503,7 @@ namespace latinime {
|
||||||
// Pushing point information.
|
// Pushing point information.
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
sampledLengthCache->push_back(
|
sampledLengthCache->push_back(
|
||||||
sampledLengthCache->back() + getDistanceInt(
|
sampledLengthCache->back() + GeometryUtils::getDistanceInt(
|
||||||
x, y, sampledInputXs->back(), sampledInputYs->back()));
|
x, y, sampledInputXs->back(), sampledInputYs->back()));
|
||||||
} else {
|
} else {
|
||||||
sampledLengthCache->push_back(0);
|
sampledLengthCache->push_back(0);
|
||||||
|
@ -540,7 +544,8 @@ namespace latinime {
|
||||||
while (start > 0 && tempBeelineDistance < lookupRadius) {
|
while (start > 0 && tempBeelineDistance < lookupRadius) {
|
||||||
tempTime += times[start] - times[start - 1];
|
tempTime += times[start] - times[start - 1];
|
||||||
--start;
|
--start;
|
||||||
tempBeelineDistance = getDistanceInt(x0, y0, xCoordinates[start], yCoordinates[start]);
|
tempBeelineDistance = GeometryUtils::getDistanceInt(x0, y0, xCoordinates[start],
|
||||||
|
yCoordinates[start]);
|
||||||
}
|
}
|
||||||
// Exclusive unless this is an edge point
|
// Exclusive unless this is an edge point
|
||||||
if (start > 0 && start < actualInputIndex) {
|
if (start > 0 && start < actualInputIndex) {
|
||||||
|
@ -553,7 +558,8 @@ namespace latinime {
|
||||||
while (end < (inputSize - 1) && tempBeelineDistance < lookupRadius) {
|
while (end < (inputSize - 1) && tempBeelineDistance < lookupRadius) {
|
||||||
tempTime += times[end + 1] - times[end];
|
tempTime += times[end + 1] - times[end];
|
||||||
++end;
|
++end;
|
||||||
tempBeelineDistance = getDistanceInt(x0, y0, xCoordinates[end], yCoordinates[end]);
|
tempBeelineDistance = GeometryUtils::getDistanceInt(x0, y0, xCoordinates[end],
|
||||||
|
yCoordinates[end]);
|
||||||
}
|
}
|
||||||
// Exclusive unless this is an edge point
|
// Exclusive unless this is an edge point
|
||||||
if (end > actualInputIndex && end < (inputSize - 1)) {
|
if (end > actualInputIndex && end < (inputSize - 1)) {
|
||||||
|
@ -571,7 +577,7 @@ namespace latinime {
|
||||||
const int y2 = yCoordinates[start];
|
const int y2 = yCoordinates[start];
|
||||||
const int x3 = xCoordinates[end];
|
const int x3 = xCoordinates[end];
|
||||||
const int y3 = yCoordinates[end];
|
const int y3 = yCoordinates[end];
|
||||||
const int beelineDistance = getDistanceInt(x2, y2, x3, y3);
|
const int beelineDistance = GeometryUtils::getDistanceInt(x2, y2, x3, y3);
|
||||||
int adjustedStartTime = times[start];
|
int adjustedStartTime = times[start];
|
||||||
if (start == 0 && actualInputIndex == 0 && inputSize > 1) {
|
if (start == 0 && actualInputIndex == 0 && inputSize > 1) {
|
||||||
adjustedStartTime += ProximityInfoParams::FIRST_POINT_TIME_OFFSET_MILLIS;
|
adjustedStartTime += ProximityInfoParams::FIRST_POINT_TIME_OFFSET_MILLIS;
|
||||||
|
@ -613,7 +619,7 @@ namespace latinime {
|
||||||
}
|
}
|
||||||
const float previousDirection = getDirection(sampledInputXs, sampledInputYs, index - 1, index);
|
const float previousDirection = getDirection(sampledInputXs, sampledInputYs, index - 1, index);
|
||||||
const float nextDirection = getDirection(sampledInputXs, sampledInputYs, index, index + 1);
|
const float nextDirection = getDirection(sampledInputXs, sampledInputYs, index, index + 1);
|
||||||
const float directionDiff = getAngleDiff(previousDirection, nextDirection);
|
const float directionDiff = GeometryUtils::getAngleDiff(previousDirection, nextDirection);
|
||||||
return directionDiff;
|
return directionDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -636,7 +642,7 @@ namespace latinime {
|
||||||
}
|
}
|
||||||
const float previousDirection = getDirection(sampledInputXs, sampledInputYs, index0, index1);
|
const float previousDirection = getDirection(sampledInputXs, sampledInputYs, index0, index1);
|
||||||
const float nextDirection = getDirection(sampledInputXs, sampledInputYs, index1, index2);
|
const float nextDirection = getDirection(sampledInputXs, sampledInputYs, index1, index2);
|
||||||
return getAngleDiff(previousDirection, nextDirection);
|
return GeometryUtils::getAngleDiff(previousDirection, nextDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function basically converts from a length to an edit distance. Accordingly, it's obviously
|
// This function basically converts from a length to an edit distance. Accordingly, it's obviously
|
|
@ -22,8 +22,8 @@
|
||||||
#include "additional_proximity_chars.h"
|
#include "additional_proximity_chars.h"
|
||||||
#include "char_utils.h"
|
#include "char_utils.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "geometry_utils.h"
|
|
||||||
#include "hash_map_compat.h"
|
#include "hash_map_compat.h"
|
||||||
|
#include "suggest/core/layout/geometry_utils.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
class ProximityInfoUtils {
|
class ProximityInfoUtils {
|
||||||
|
@ -87,7 +87,7 @@ class ProximityInfoUtils {
|
||||||
|
|
||||||
static inline float getSquaredDistanceFloat(const float x1, const float y1, const float x2,
|
static inline float getSquaredDistanceFloat(const float x1, const float y1, const float x2,
|
||||||
const float y2) {
|
const float y2) {
|
||||||
return SQUARE_FLOAT(x1 - x2) + SQUARE_FLOAT(y1 - y2);
|
return GeometryUtils::SQUARE_FLOAT(x1 - x2) + GeometryUtils::SQUARE_FLOAT(y1 - y2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline float pointToLineSegSquaredDistanceFloat(const float x, const float y,
|
static inline float pointToLineSegSquaredDistanceFloat(const float x, const float y,
|
||||||
|
@ -98,7 +98,8 @@ class ProximityInfoUtils {
|
||||||
const float ray2y = y2 - y1;
|
const float ray2y = y2 - y1;
|
||||||
|
|
||||||
const float dotProduct = ray1x * ray2x + ray1y * ray2y;
|
const float dotProduct = ray1x * ray2x + ray1y * ray2y;
|
||||||
const float lineLengthSqr = SQUARE_FLOAT(ray2x) + SQUARE_FLOAT(ray2y);
|
const float lineLengthSqr = GeometryUtils::SQUARE_FLOAT(ray2x)
|
||||||
|
+ GeometryUtils::SQUARE_FLOAT(ray2y);
|
||||||
const float projectionLengthSqr = dotProduct / lineLengthSqr;
|
const float projectionLengthSqr = dotProduct / lineLengthSqr;
|
||||||
|
|
||||||
float projectionX;
|
float projectionX;
|
||||||
|
@ -121,12 +122,14 @@ class ProximityInfoUtils {
|
||||||
public:
|
public:
|
||||||
NormalDistribution(const float u, const float sigma)
|
NormalDistribution(const float u, const float sigma)
|
||||||
: mU(u), mSigma(sigma),
|
: mU(u), mSigma(sigma),
|
||||||
mPreComputedNonExpPart(1.0f / sqrtf(2.0f * M_PI_F * SQUARE_FLOAT(sigma))),
|
mPreComputedNonExpPart(1.0f / sqrtf(2.0f * M_PI_F
|
||||||
mPreComputedExponentPart(-1.0f / (2.0f * SQUARE_FLOAT(sigma))) {}
|
* GeometryUtils::SQUARE_FLOAT(sigma))),
|
||||||
|
mPreComputedExponentPart(-1.0f / (2.0f * GeometryUtils::SQUARE_FLOAT(sigma))) {}
|
||||||
|
|
||||||
float getProbabilityDensity(const float x) const {
|
float getProbabilityDensity(const float x) const {
|
||||||
const float shiftedX = x - mU;
|
const float shiftedX = x - mU;
|
||||||
return mPreComputedNonExpPart * expf(mPreComputedExponentPart * SQUARE_FLOAT(shiftedX));
|
return mPreComputedNonExpPart
|
||||||
|
* expf(mPreComputedExponentPart * GeometryUtils::SQUARE_FLOAT(shiftedX));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
|
@ -14,14 +14,14 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LATINIME_SUGGEST_UTILS_H
|
#ifndef LATINIME_TOUCH_POSITION_CORRECTION_UTILS_H
|
||||||
#define LATINIME_SUGGEST_UTILS_H
|
#define LATINIME_TOUCH_POSITION_CORRECTION_UTILS_H
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "proximity_info_params.h"
|
#include "proximity_info_params.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
class SuggestUtils {
|
class TouchPositionCorrectionUtils {
|
||||||
public:
|
public:
|
||||||
// TODO: (OLD) Remove
|
// TODO: (OLD) Remove
|
||||||
static float getLengthScalingFactor(const float normalizedSquaredDistance) {
|
static float getLengthScalingFactor(const float normalizedSquaredDistance) {
|
||||||
|
@ -82,7 +82,7 @@ class SuggestUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
DISALLOW_IMPLICIT_CONSTRUCTORS(SuggestUtils);
|
DISALLOW_IMPLICIT_CONSTRUCTORS(TouchPositionCorrectionUtils);
|
||||||
};
|
};
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
#endif // LATINIME_SUGGEST_UTILS_H
|
#endif // LATINIME_TOUCH_POSITION_CORRECTION_UTILS_H
|
|
@ -23,8 +23,8 @@
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
#include "multi_bigram_map.h"
|
#include "multi_bigram_map.h"
|
||||||
#include "proximity_info_state.h"
|
|
||||||
#include "suggest/core/dicnode/dic_nodes_cache.h"
|
#include "suggest/core/dicnode/dic_nodes_cache.h"
|
||||||
|
#include "suggest/core/layout/proximity_info_state.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,11 @@
|
||||||
#include "char_utils.h"
|
#include "char_utils.h"
|
||||||
#include "dictionary.h"
|
#include "dictionary.h"
|
||||||
#include "digraph_utils.h"
|
#include "digraph_utils.h"
|
||||||
#include "proximity_info.h"
|
|
||||||
#include "suggest/core/dicnode/dic_node.h"
|
#include "suggest/core/dicnode/dic_node.h"
|
||||||
#include "suggest/core/dicnode/dic_node_priority_queue.h"
|
#include "suggest/core/dicnode/dic_node_priority_queue.h"
|
||||||
#include "suggest/core/dicnode/dic_node_vector.h"
|
#include "suggest/core/dicnode/dic_node_vector.h"
|
||||||
#include "suggest/core/dictionary/shortcut_utils.h"
|
#include "suggest/core/dictionary/shortcut_utils.h"
|
||||||
|
#include "suggest/core/layout/proximity_info.h"
|
||||||
#include "suggest/core/policy/scoring.h"
|
#include "suggest/core/policy/scoring.h"
|
||||||
#include "suggest/core/policy/traversal.h"
|
#include "suggest/core/policy/traversal.h"
|
||||||
#include "suggest/core/policy/weighting.h"
|
#include "suggest/core/policy/weighting.h"
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
|
|
||||||
#include "char_utils.h"
|
#include "char_utils.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "proximity_info_state.h"
|
|
||||||
#include "suggest/core/dicnode/dic_node.h"
|
#include "suggest/core/dicnode/dic_node.h"
|
||||||
#include "suggest/core/dicnode/dic_node_vector.h"
|
#include "suggest/core/dicnode/dic_node_vector.h"
|
||||||
|
#include "suggest/core/layout/proximity_info_state.h"
|
||||||
#include "suggest/core/policy/traversal.h"
|
#include "suggest/core/policy/traversal.h"
|
||||||
#include "suggest/core/session/dic_traverse_session.h"
|
#include "suggest/core/session/dic_traverse_session.h"
|
||||||
#include "suggest/policyimpl/typing/scoring_params.h"
|
#include "suggest/policyimpl/typing/scoring_params.h"
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
#define LATINIME_TYPING_WEIGHTING_H
|
#define LATINIME_TYPING_WEIGHTING_H
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "suggest_utils.h"
|
|
||||||
#include "suggest/core/dicnode/dic_node_utils.h"
|
#include "suggest/core/dicnode/dic_node_utils.h"
|
||||||
|
#include "suggest/core/layout/touch_position_correction_utils.h"
|
||||||
#include "suggest/core/policy/weighting.h"
|
#include "suggest/core/policy/weighting.h"
|
||||||
#include "suggest/core/session/dic_traverse_session.h"
|
#include "suggest/core/session/dic_traverse_session.h"
|
||||||
#include "suggest/policyimpl/typing/scoring_params.h"
|
#include "suggest/policyimpl/typing/scoring_params.h"
|
||||||
|
@ -74,7 +74,7 @@ class TypingWeighting : public Weighting {
|
||||||
// the keyboard (like accented letters)
|
// the keyboard (like accented letters)
|
||||||
const float normalizedSquaredLength = traverseSession->getProximityInfoState(0)
|
const float normalizedSquaredLength = traverseSession->getProximityInfoState(0)
|
||||||
->getPointToKeyLength(pointIndex, dicNode->getNodeCodePoint());
|
->getPointToKeyLength(pointIndex, dicNode->getNodeCodePoint());
|
||||||
const float normalizedDistance = SuggestUtils::getSweetSpotFactor(
|
const float normalizedDistance = TouchPositionCorrectionUtils::getSweetSpotFactor(
|
||||||
traverseSession->isTouchPositionCorrectionEnabled(), normalizedSquaredLength);
|
traverseSession->isTouchPositionCorrectionEnabled(), normalizedSquaredLength);
|
||||||
const float weightedDistance = ScoringParams::DISTANCE_WEIGHT_LENGTH * normalizedDistance;
|
const float weightedDistance = ScoringParams::DISTANCE_WEIGHT_LENGTH * normalizedDistance;
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,8 @@ class SuggestOptions{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
DISALLOW_IMPLICIT_CONSTRUCTORS(SuggestOptions);
|
||||||
|
|
||||||
// Need to update com.android.inputmethod.latin.NativeSuggestOptions when you add, remove or
|
// Need to update com.android.inputmethod.latin.NativeSuggestOptions when you add, remove or
|
||||||
// reorder options.
|
// reorder options.
|
||||||
static const int IS_GESTURE = 0;
|
static const int IS_GESTURE = 0;
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "dictionary.h"
|
#include "dictionary.h"
|
||||||
#include "digraph_utils.h"
|
#include "digraph_utils.h"
|
||||||
#include "proximity_info.h"
|
#include "suggest/core/layout/proximity_info.h"
|
||||||
#include "terminal_attributes.h"
|
#include "terminal_attributes.h"
|
||||||
#include "unigram_dictionary.h"
|
#include "unigram_dictionary.h"
|
||||||
#include "words_priority_queue.h"
|
#include "words_priority_queue.h"
|
||||||
|
|
Loading…
Reference in New Issue