/* * Copyright (C) 2013 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_UTILS_H #define LATINIME_PROXIMITY_INFO_STATE_UTILS_H #include #include #include "defines.h" #include "hash_map_compat.h" namespace latinime { class ProximityInfo; class ProximityInfoParams; class ProximityInfoStateUtils { public: typedef hash_map_compat NearKeysDistanceMap; typedef std::bitset NearKeycodesSet; static int trimLastTwoTouchPoints(std::vector *sampledInputXs, std::vector *sampledInputYs, std::vector *sampledInputTimes, std::vector *sampledLengthCache, std::vector *sampledInputIndice); static int updateTouchPoints(const ProximityInfo *const proximityInfo, const int maxPointToKeyLength, const int *const inputProximities, const int *const inputXCoordinates, const int *const inputYCoordinates, const int *const times, const int *const pointerIds, const float verticalSweetSpotScale, const int inputSize, const bool isGeometric, const int pointerId, const int pushTouchPointStartIndex, std::vector *sampledInputXs, std::vector *sampledInputYs, std::vector *sampledInputTimes, std::vector *sampledLengthCache, std::vector *sampledInputIndice); static const int *getProximityCodePointsAt(const int *const inputProximities, const int index); static int getPrimaryCodePointAt(const int *const inputProximities, const int index); static void popInputData(std::vector *sampledInputXs, std::vector *sampledInputYs, std::vector *sampledInputTimes, std::vector *sampledLengthCache, std::vector *sampledInputIndice); static float refreshSpeedRates(const int inputSize, const int *const xCoordinates, const int *const yCoordinates, const int *const times, const int lastSavedInputSize, const int sampledInputSize, const std::vector *const sampledInputXs, const std::vector *const sampledInputYs, const std::vector *const sampledInputTimes, const std::vector *const sampledLengthCache, const std::vector *const sampledInputIndice, std::vector *sampledSpeedRates, std::vector *sampledDirections); static void refreshBeelineSpeedRates(const int mostCommonKeyWidth, const float averageSpeed, const int inputSize, const int *const xCoordinates, const int *const yCoordinates, const int *times, const int sampledInputSize, const std::vector *const sampledInputXs, const std::vector *const sampledInputYs, const std::vector *const inputIndice, std::vector *beelineSpeedPercentiles); static float getDirection(const std::vector *const sampledInputXs, const std::vector *const sampledInputYs, const int index0, const int index1); static void updateAlignPointProbabilities(const float maxPointToKeyLength, const int mostCommonKeyWidth, const int keyCount, const int start, const int sampledInputSize, const std::vector *const sampledInputXs, const std::vector *const sampledInputYs, const std::vector *const sampledSpeedRates, const std::vector *const sampledLengthCache, const std::vector *const sampledNormalizedSquaredLengthCache, std::vector *sampledNearKeySets, std::vector > *charProbabilities); static void updateSampledSearchKeySets(const ProximityInfo *const proximityInfo, const int sampledInputSize, const int lastSavedInputSize, const std::vector *const sampledLengthCache, const std::vector *const sampledNearKeySets, std::vector *sampledSearchKeySets, std::vector > *sampledSearchKeyVectors); static float getPointToKeyByIdLength(const float maxPointToKeyLength, const std::vector *const sampledNormalizedSquaredLengthCache, const int keyCount, const int inputIndex, const int keyId); static void initGeometricDistanceInfos(const ProximityInfo *const proximityInfo, const int sampledInputSize, const int lastSavedInputSize, const float verticalSweetSpotScale, const std::vector *const sampledInputXs, const std::vector *const sampledInputYs, std::vector *sampledNearKeySets, std::vector *sampledNormalizedSquaredLengthCache); static void initPrimaryInputWord(const int inputSize, const int *const inputProximities, int *primaryInputWord); static void initNormalizedSquaredDistances(const ProximityInfo *const proximityInfo, const int inputSize, const int *inputXCoordinates, const int *inputYCoordinates, const int *const inputProximities, const std::vector *const sampledInputXs, const std::vector *const sampledInputYs, int *normalizedSquaredDistances); static void dump(const bool isGeometric, const int inputSize, const int *const inputXCoordinates, const int *const inputYCoordinates, const int sampledInputSize, const std::vector *const sampledInputXs, const std::vector *const sampledInputYs, const std::vector *const sampledTimes, const std::vector *const sampledSpeedRates, const std::vector *const sampledBeelineSpeedPercentiles); static bool checkAndReturnIsContinuousSuggestionPossible(const int inputSize, const int *const xCoordinates, const int *const yCoordinates, const int *const times, const int sampledInputSize, const std::vector *const sampledInputXs, const std::vector *const sampledInputYs, const std::vector *const sampledTimes, const std::vector *const sampledInputIndices); // TODO: Move to most_probable_string_utils.h static float getMostProbableString(const ProximityInfo *const proximityInfo, const int sampledInputSize, const std::vector > *const charProbabilities, int *const codePointBuf); private: DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfoStateUtils); static float updateNearKeysDistances(const ProximityInfo *const proximityInfo, const float maxPointToKeyLength, const int x, const int y, const float verticalSweetSpotScale, NearKeysDistanceMap *const currentNearKeysDistances); static bool isPrevLocalMin(const NearKeysDistanceMap *const currentNearKeysDistances, const NearKeysDistanceMap *const prevNearKeysDistances, const NearKeysDistanceMap *const prevPrevNearKeysDistances); static float getPointScore(const int mostCommonKeyWidth, const int x, const int y, const int time, const bool lastPoint, const float nearest, const float sumAngle, const NearKeysDistanceMap *const currentNearKeysDistances, const NearKeysDistanceMap *const prevNearKeysDistances, const NearKeysDistanceMap *const prevPrevNearKeysDistances, std::vector *sampledInputXs, std::vector *sampledInputYs); static bool pushTouchPoint(const ProximityInfo *const proximityInfo, const int maxPointToKeyLength, const int inputIndex, const int nodeCodePoint, int x, int y, const int time, const float verticalSweetSpotScale, const bool doSampling, const bool isLastPoint, const float sumAngle, NearKeysDistanceMap *const currentNearKeysDistances, const NearKeysDistanceMap *const prevNearKeysDistances, const NearKeysDistanceMap *const prevPrevNearKeysDistances, std::vector *sampledInputXs, std::vector *sampledInputYs, std::vector *sampledInputTimes, std::vector *sampledLengthCache, std::vector *sampledInputIndice); static float calculateBeelineSpeedRate(const int mostCommonKeyWidth, const float averageSpeed, const int id, const int inputSize, const int *const xCoordinates, const int *const yCoordinates, const int *times, const int sampledInputSize, const std::vector *const sampledInputXs, const std::vector *const sampledInputYs, const std::vector *const inputIndice); static float getPointAngle(const std::vector *const sampledInputXs, const std::vector *const sampledInputYs, const int index); static float getPointsAngle(const std::vector *const sampledInputXs, const std::vector *const sampledInputYs, const int index0, const int index1, const int index2); static bool suppressCharProbabilities(const int mostCommonKeyWidth, const int sampledInputSize, const std::vector *const lengthCache, const int index0, const int index1, std::vector > *charProbabilities); static float calculateSquaredDistanceFromSweetSpotCenter( const ProximityInfo *const proximityInfo, const std::vector *const sampledInputXs, const std::vector *const sampledInputYs, const int keyIndex, const int inputIndex); static float calculateNormalizedSquaredDistance(const ProximityInfo *const proximityInfo, const std::vector *const sampledInputXs, const std::vector *const sampledInputYs, const int keyIndex, const int inputIndex); }; } // namespace latinime #endif // LATINIME_PROXIMITY_INFO_STATE_UTILS_H