2012-06-05 08:55:52 +00:00
|
|
|
/*
|
|
|
|
* 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_PROXIMITY_INFO_STATE_H
|
|
|
|
#define LATINIME_PROXIMITY_INFO_STATE_H
|
|
|
|
|
2012-08-24 05:51:15 +00:00
|
|
|
#include <cstring> // for memset()
|
2012-08-23 06:46:43 +00:00
|
|
|
#include <vector>
|
2012-06-05 08:55:52 +00:00
|
|
|
|
2012-06-08 06:29:44 +00:00
|
|
|
#include "char_utils.h"
|
2012-06-05 08:55:52 +00:00
|
|
|
#include "defines.h"
|
2012-08-31 12:22:14 +00:00
|
|
|
#include "hash_map_compat.h"
|
2013-01-21 09:29:27 +00:00
|
|
|
#include "proximity_info_params.h"
|
2013-01-21 07:33:24 +00:00
|
|
|
#include "proximity_info_state_utils.h"
|
2012-06-05 08:55:52 +00:00
|
|
|
|
|
|
|
namespace latinime {
|
|
|
|
|
|
|
|
class ProximityInfo;
|
|
|
|
|
|
|
|
class ProximityInfoState {
|
|
|
|
public:
|
|
|
|
/////////////////////////////////////////
|
|
|
|
// Defined in proximity_info_state.cpp //
|
|
|
|
/////////////////////////////////////////
|
2012-08-24 05:45:54 +00:00
|
|
|
void initInputParams(const int pointerId, const float maxPointToKeyLength,
|
2012-10-29 09:06:22 +00:00
|
|
|
const ProximityInfo *proximityInfo, const int *const inputCodes,
|
2012-08-24 06:19:56 +00:00
|
|
|
const int inputSize, const int *xCoordinates, const int *yCoordinates,
|
|
|
|
const int *const times, const int *const pointerIds, const bool isGeometric);
|
2012-06-05 08:55:52 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////
|
|
|
|
// Defined here //
|
|
|
|
/////////////////////////////////////////
|
2012-11-02 17:50:47 +00:00
|
|
|
AK_FORCE_INLINE ProximityInfoState()
|
2012-11-16 14:06:41 +00:00
|
|
|
: mProximityInfo(0), mMaxPointToKeyLength(0.0f), mAverageSpeed(0.0f),
|
2013-01-21 02:37:54 +00:00
|
|
|
mHasTouchPositionCorrectionData(false), mMostCommonKeyWidthSquare(0),
|
2012-08-24 05:51:15 +00:00
|
|
|
mKeyCount(0), mCellHeight(0), mCellWidth(0), mGridHeight(0), mGridWidth(0),
|
2013-03-29 09:49:50 +00:00
|
|
|
mIsContinuousSuggestionPossible(false), mSampledInputXs(), mSampledInputYs(),
|
|
|
|
mSampledTimes(), mSampledInputIndice(), mSampledLengthCache(),
|
|
|
|
mBeelineSpeedPercentiles(), mSampledDistanceCache_G(), mSpeedRates(), mDirections(),
|
|
|
|
mCharProbabilities(), mSampledNearKeySets(), mSampledSearchKeySets(),
|
|
|
|
mSampledSearchKeyVectors(), mTouchPositionCorrectionEnabled(false),
|
|
|
|
mSampledInputSize(0), mMostProbableStringProbability(0.0f) {
|
2013-01-17 10:46:12 +00:00
|
|
|
memset(mInputProximities, 0, sizeof(mInputProximities));
|
2012-08-24 05:51:15 +00:00
|
|
|
memset(mNormalizedSquaredDistances, 0, sizeof(mNormalizedSquaredDistances));
|
|
|
|
memset(mPrimaryInputWord, 0, sizeof(mPrimaryInputWord));
|
2013-01-24 08:08:30 +00:00
|
|
|
memset(mMostProbableString, 0, sizeof(mMostProbableString));
|
2012-08-24 05:51:15 +00:00
|
|
|
}
|
|
|
|
|
2012-11-02 17:50:47 +00:00
|
|
|
// Non virtual inline destructor -- never inherit this class
|
|
|
|
AK_FORCE_INLINE ~ProximityInfoState() {}
|
2012-06-05 08:55:52 +00:00
|
|
|
|
2012-10-29 09:06:22 +00:00
|
|
|
inline int getPrimaryCodePointAt(const int index) const {
|
|
|
|
return getProximityCodePointsAt(index)[0];
|
2012-06-05 08:55:52 +00:00
|
|
|
}
|
|
|
|
|
2013-01-24 08:08:30 +00:00
|
|
|
inline bool sameAsTyped(const int *word, int length) const {
|
|
|
|
if (length != mSampledInputSize) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const int *inputProximities = mInputProximities;
|
|
|
|
while (length--) {
|
|
|
|
if (*inputProximities != *word) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
inputProximities += MAX_PROXIMITY_CHARS_SIZE;
|
|
|
|
word++;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-02 17:50:47 +00:00
|
|
|
AK_FORCE_INLINE bool existsCodePointInProximityAt(const int index, const int c) const {
|
2012-10-29 09:06:22 +00:00
|
|
|
const int *codePoints = getProximityCodePointsAt(index);
|
2012-06-05 08:55:52 +00:00
|
|
|
int i = 0;
|
2013-01-22 04:14:53 +00:00
|
|
|
while (codePoints[i] > 0 && i < MAX_PROXIMITY_CHARS_SIZE) {
|
2012-10-29 09:06:22 +00:00
|
|
|
if (codePoints[i++] == c) {
|
2012-06-05 08:55:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool existsAdjacentProximityChars(const int index) const {
|
2012-11-16 10:03:36 +00:00
|
|
|
if (index < 0 || index >= mSampledInputSize) return false;
|
2012-10-29 09:06:22 +00:00
|
|
|
const int currentCodePoint = getPrimaryCodePointAt(index);
|
2012-06-05 08:55:52 +00:00
|
|
|
const int leftIndex = index - 1;
|
2012-10-29 09:06:22 +00:00
|
|
|
if (leftIndex >= 0 && existsCodePointInProximityAt(leftIndex, currentCodePoint)) {
|
2012-06-05 08:55:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const int rightIndex = index + 1;
|
2012-11-16 10:03:36 +00:00
|
|
|
if (rightIndex < mSampledInputSize
|
|
|
|
&& existsCodePointInProximityAt(rightIndex, currentCodePoint)) {
|
2012-06-05 08:55:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int getNormalizedSquaredDistance(
|
|
|
|
const int inputIndex, const int proximityIndex) const {
|
2012-06-08 06:29:44 +00:00
|
|
|
return mNormalizedSquaredDistances[
|
2013-01-22 04:14:53 +00:00
|
|
|
inputIndex * MAX_PROXIMITY_CHARS_SIZE + proximityIndex];
|
2012-06-05 08:55:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 09:06:22 +00:00
|
|
|
inline const int *getPrimaryInputWord() const {
|
2012-06-05 08:55:52 +00:00
|
|
|
return mPrimaryInputWord;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool touchPositionCorrectionEnabled() const {
|
|
|
|
return mTouchPositionCorrectionEnabled;
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:46:43 +00:00
|
|
|
bool isUsed() const {
|
2012-11-16 10:03:36 +00:00
|
|
|
return mSampledInputSize > 0;
|
2012-08-23 06:46:43 +00:00
|
|
|
}
|
|
|
|
|
2012-12-10 10:12:46 +00:00
|
|
|
int size() const {
|
2012-11-16 10:03:36 +00:00
|
|
|
return mSampledInputSize;
|
2012-08-27 05:39:17 +00:00
|
|
|
}
|
|
|
|
|
2012-09-06 11:55:45 +00:00
|
|
|
int getInputX(const int index) const {
|
2012-11-16 10:03:36 +00:00
|
|
|
return mSampledInputXs[index];
|
2012-08-27 05:39:17 +00:00
|
|
|
}
|
|
|
|
|
2012-09-06 11:55:45 +00:00
|
|
|
int getInputY(const int index) const {
|
2012-11-16 10:03:36 +00:00
|
|
|
return mSampledInputYs[index];
|
2012-08-27 05:39:17 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:01:59 +00:00
|
|
|
bool hasSpaceProximity(const int index) const;
|
|
|
|
|
2012-09-06 11:55:45 +00:00
|
|
|
int getLengthCache(const int index) const {
|
2013-01-22 08:00:43 +00:00
|
|
|
return mSampledLengthCache[index];
|
2012-08-27 05:39:17 +00:00
|
|
|
}
|
|
|
|
|
2013-03-29 09:49:50 +00:00
|
|
|
bool isContinuousSuggestionPossible() const {
|
|
|
|
return mIsContinuousSuggestionPossible;
|
2012-09-07 12:04:12 +00:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:57:08 +00:00
|
|
|
float getPointToKeyByIdLength(const int inputIndex, const int keyId) const;
|
2013-02-27 21:57:32 +00:00
|
|
|
float getPointToKeyLength(const int inputIndex, const int codePoint) const;
|
2012-08-23 06:46:43 +00:00
|
|
|
|
2013-02-28 05:17:25 +00:00
|
|
|
ProximityType getProximityType(const int index, const int codePoint,
|
2012-11-02 09:29:03 +00:00
|
|
|
const bool checkProximityChars, int *proximityIndex = 0) const;
|
|
|
|
|
2013-02-28 05:17:25 +00:00
|
|
|
ProximityType getProximityTypeG(const int index, const int codePoint) const;
|
|
|
|
|
2013-02-07 19:46:03 +00:00
|
|
|
const std::vector<int> *getSearchKeyVector(const int index) const {
|
|
|
|
return &mSampledSearchKeyVectors[index];
|
|
|
|
}
|
2012-09-04 08:00:24 +00:00
|
|
|
|
2012-11-16 14:06:41 +00:00
|
|
|
float getSpeedRate(const int index) const {
|
|
|
|
return mSpeedRates[index];
|
|
|
|
}
|
|
|
|
|
2012-11-22 11:15:40 +00:00
|
|
|
AK_FORCE_INLINE int getBeelineSpeedPercentile(const int id) const {
|
|
|
|
return mBeelineSpeedPercentiles[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
AK_FORCE_INLINE DoubleLetterLevel getDoubleLetterLevel(const int id) const {
|
|
|
|
const int beelineSpeedRate = getBeelineSpeedPercentile(id);
|
|
|
|
if (beelineSpeedRate == 0) {
|
|
|
|
return A_STRONG_DOUBLE_LETTER;
|
2013-01-21 09:29:27 +00:00
|
|
|
} else if (beelineSpeedRate
|
|
|
|
< ProximityInfoParams::MIN_DOUBLE_LETTER_BEELINE_SPEED_PERCENTILE) {
|
2012-11-22 11:15:40 +00:00
|
|
|
return A_DOUBLE_LETTER;
|
|
|
|
} else {
|
|
|
|
return NOT_A_DOUBLE_LETTER;
|
|
|
|
}
|
2012-09-24 11:02:57 +00:00
|
|
|
}
|
2012-10-09 10:57:08 +00:00
|
|
|
|
2012-10-11 11:24:41 +00:00
|
|
|
float getDirection(const int index) const {
|
|
|
|
return mDirections[index];
|
|
|
|
}
|
2012-10-11 04:08:06 +00:00
|
|
|
// get xy direction
|
|
|
|
float getDirection(const int x, const int y) const;
|
|
|
|
|
2012-12-17 06:20:58 +00:00
|
|
|
float getMostProbableString(int *const codePointBuf) const;
|
2012-10-11 04:08:06 +00:00
|
|
|
|
|
|
|
float getProbability(const int index, const int charCode) const;
|
|
|
|
|
|
|
|
float getLineToKeyDistance(
|
|
|
|
const int from, const int to, const int keyId, const bool extend) const;
|
|
|
|
|
|
|
|
bool isKeyInSerchKeysAfterIndex(const int index, const int keyId) const;
|
2013-01-29 10:20:04 +00:00
|
|
|
|
2012-06-05 08:55:52 +00:00
|
|
|
private:
|
2012-06-14 18:25:50 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(ProximityInfoState);
|
2012-06-08 06:29:44 +00:00
|
|
|
/////////////////////////////////////////
|
|
|
|
// Defined in proximity_info_state.cpp //
|
|
|
|
/////////////////////////////////////////
|
|
|
|
float calculateNormalizedSquaredDistance(const int keyIndex, const int inputIndex) const;
|
2012-06-05 08:55:52 +00:00
|
|
|
|
2012-06-08 06:29:44 +00:00
|
|
|
float calculateSquaredDistanceFromSweetSpotCenter(
|
|
|
|
const int keyIndex, const int inputIndex) const;
|
|
|
|
|
|
|
|
/////////////////////////////////////////
|
|
|
|
// Defined here //
|
|
|
|
/////////////////////////////////////////
|
2012-06-05 08:55:52 +00:00
|
|
|
|
2012-10-29 09:06:22 +00:00
|
|
|
inline const int *getProximityCodePointsAt(const int index) const {
|
2013-01-21 07:33:24 +00:00
|
|
|
return ProximityInfoStateUtils::getProximityCodePointsAt(mInputProximities, index);
|
2012-08-16 10:34:02 +00:00
|
|
|
}
|
2012-08-31 12:22:14 +00:00
|
|
|
|
2012-06-08 06:29:44 +00:00
|
|
|
// const
|
|
|
|
const ProximityInfo *mProximityInfo;
|
2012-08-23 06:46:43 +00:00
|
|
|
float mMaxPointToKeyLength;
|
2012-11-16 14:06:41 +00:00
|
|
|
float mAverageSpeed;
|
2012-06-08 06:29:44 +00:00
|
|
|
bool mHasTouchPositionCorrectionData;
|
|
|
|
int mMostCommonKeyWidthSquare;
|
|
|
|
int mKeyCount;
|
|
|
|
int mCellHeight;
|
|
|
|
int mCellWidth;
|
|
|
|
int mGridHeight;
|
|
|
|
int mGridWidth;
|
2013-03-29 09:49:50 +00:00
|
|
|
bool mIsContinuousSuggestionPossible;
|
2012-06-05 08:55:52 +00:00
|
|
|
|
2012-11-16 10:03:36 +00:00
|
|
|
std::vector<int> mSampledInputXs;
|
|
|
|
std::vector<int> mSampledInputYs;
|
2013-01-22 08:00:43 +00:00
|
|
|
std::vector<int> mSampledTimes;
|
|
|
|
std::vector<int> mSampledInputIndice;
|
|
|
|
std::vector<int> mSampledLengthCache;
|
2012-11-22 11:15:40 +00:00
|
|
|
std::vector<int> mBeelineSpeedPercentiles;
|
2013-01-23 07:47:17 +00:00
|
|
|
std::vector<float> mSampledDistanceCache_G;
|
2012-11-16 14:06:41 +00:00
|
|
|
std::vector<float> mSpeedRates;
|
2012-10-11 11:24:41 +00:00
|
|
|
std::vector<float> mDirections;
|
2012-10-09 10:57:08 +00:00
|
|
|
// probabilities of skipping or mapping to a key for each point.
|
|
|
|
std::vector<hash_map_compat<int, float> > mCharProbabilities;
|
2012-10-11 04:08:06 +00:00
|
|
|
// The vector for the key code set which holds nearby keys for each sampled input point
|
|
|
|
// 1. Used to calculate the probability of the key
|
2013-02-07 19:46:03 +00:00
|
|
|
// 2. Used to calculate mSampledSearchKeySets
|
|
|
|
std::vector<ProximityInfoStateUtils::NearKeycodesSet> mSampledNearKeySets;
|
2012-10-11 04:08:06 +00:00
|
|
|
// The vector for the key code set which holds nearby keys of some trailing sampled input points
|
|
|
|
// for each sampled input point. These nearby keys contain the next characters which can be in
|
|
|
|
// the dictionary. Specifically, currently we are looking for keys nearby trailing sampled
|
|
|
|
// inputs including the current input point.
|
2013-02-07 19:46:03 +00:00
|
|
|
std::vector<ProximityInfoStateUtils::NearKeycodesSet> mSampledSearchKeySets;
|
|
|
|
std::vector<std::vector<int> > mSampledSearchKeyVectors;
|
2012-06-05 08:55:52 +00:00
|
|
|
bool mTouchPositionCorrectionEnabled;
|
2013-01-22 04:14:53 +00:00
|
|
|
int mInputProximities[MAX_PROXIMITY_CHARS_SIZE * MAX_WORD_LENGTH];
|
|
|
|
int mNormalizedSquaredDistances[MAX_PROXIMITY_CHARS_SIZE * MAX_WORD_LENGTH];
|
2012-11-16 10:03:36 +00:00
|
|
|
int mSampledInputSize;
|
2013-01-11 16:18:00 +00:00
|
|
|
int mPrimaryInputWord[MAX_WORD_LENGTH];
|
2013-01-24 08:08:30 +00:00
|
|
|
float mMostProbableStringProbability;
|
|
|
|
int mMostProbableString[MAX_WORD_LENGTH];
|
2012-06-05 08:55:52 +00:00
|
|
|
};
|
|
|
|
} // namespace latinime
|
|
|
|
#endif // LATINIME_PROXIMITY_INFO_STATE_H
|