Header cleanup. Moved a couple of functions from .h to .cpp.
Change-Id: Ifd12a7632f75395bd0ef5e394d5c2abd6cbe28c6main
parent
ffe36cdc6d
commit
77e8e81ad9
|
@ -572,8 +572,8 @@ inline int BinaryFormat::computeFrequencyForBigram(const int unigramFreq, const
|
||||||
// 0 for the bigram frequency represents the middle of the 16th step from the top,
|
// 0 for the bigram frequency represents the middle of the 16th step from the top,
|
||||||
// while a value of 15 represents the middle of the top step.
|
// while a value of 15 represents the middle of the top step.
|
||||||
// See makedict.BinaryDictInputOutput for details.
|
// See makedict.BinaryDictInputOutput for details.
|
||||||
const float stepSize = ((float)MAX_FREQ - unigramFreq) / (1.5f + MAX_BIGRAM_FREQ);
|
const float stepSize = (static_cast<float>(MAX_FREQ) - unigramFreq) / (1.5f + MAX_BIGRAM_FREQ);
|
||||||
return (int)(unigramFreq + (bigramFreq + 1) * stepSize);
|
return static_cast<int>(unigramFreq + (bigramFreq + 1) * stepSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This returns a probability in log space.
|
// This returns a probability in log space.
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
#include "char_utils.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
struct LatinCapitalSmallPair {
|
struct LatinCapitalSmallPair {
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include "char_utils.h"
|
#include "char_utils.h"
|
||||||
#include "correction.h"
|
#include "correction.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "dictionary.h"
|
|
||||||
#include "proximity_info_state.h"
|
#include "proximity_info_state.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
@ -95,11 +94,11 @@ inline static int getCurrentEditDistance(int *editDistanceTable, const int editD
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// inline functions //
|
// inline functions //
|
||||||
//////////////////////
|
//////////////////////
|
||||||
static const char QUOTE = '\'';
|
static const char SINGLE_QUOTE = '\'';
|
||||||
|
|
||||||
inline bool Correction::isQuote(const unsigned short c) {
|
inline bool Correction::isSingleQuote(const unsigned short c) {
|
||||||
const unsigned short userTypedChar = mProximityInfoState.getPrimaryCharAt(mInputIndex);
|
const unsigned short userTypedChar = mProximityInfoState.getPrimaryCharAt(mInputIndex);
|
||||||
return (c == QUOTE && userTypedChar != QUOTE);
|
return (c == SINGLE_QUOTE && userTypedChar != SINGLE_QUOTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
|
@ -326,7 +325,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
mDistances[mOutputIndex] = NOT_A_DISTANCE;
|
mDistances[mOutputIndex] = NOT_A_DISTANCE;
|
||||||
|
|
||||||
// Skip checking this node
|
// Skip checking this node
|
||||||
if (mNeedsToTraverseAllNodes || isQuote(c)) {
|
if (mNeedsToTraverseAllNodes || isSingleQuote(c)) {
|
||||||
bool incremented = false;
|
bool incremented = false;
|
||||||
if (mLastCharExceeded && mInputIndex == mInputLength - 1) {
|
if (mLastCharExceeded && mInputIndex == mInputLength - 1) {
|
||||||
// TODO: Do not check the proximity if EditDistance exceeds the threshold
|
// TODO: Do not check the proximity if EditDistance exceeds the threshold
|
||||||
|
@ -344,7 +343,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
mDistances[mOutputIndex] = mProximityInfoState.getNormalizedSquaredDistance(
|
mDistances[mOutputIndex] = mProximityInfoState.getNormalizedSquaredDistance(
|
||||||
mInputIndex, proximityIndex);
|
mInputIndex, proximityIndex);
|
||||||
}
|
}
|
||||||
if (!isQuote(c)) {
|
if (!isSingleQuote(c)) {
|
||||||
incrementInputIndex();
|
incrementInputIndex();
|
||||||
incremented = true;
|
incremented = true;
|
||||||
}
|
}
|
||||||
|
@ -791,7 +790,7 @@ int Correction::RankingAlgorithm::calculateFinalProbability(const int inputIndex
|
||||||
static const float MIN = 0.3f;
|
static const float MIN = 0.3f;
|
||||||
static const float R1 = NEUTRAL_SCORE_SQUARED_RADIUS;
|
static const float R1 = NEUTRAL_SCORE_SQUARED_RADIUS;
|
||||||
static const float R2 = HALF_SCORE_SQUARED_RADIUS;
|
static const float R2 = HALF_SCORE_SQUARED_RADIUS;
|
||||||
const float x = (float)squaredDistance
|
const float x = static_cast<float>(squaredDistance)
|
||||||
/ ProximityInfoState::NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR;
|
/ ProximityInfoState::NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR;
|
||||||
const float factor = max((x < R1)
|
const float factor = max((x < R1)
|
||||||
? (A * (R1 - x) + B * x) / R1
|
? (A * (R1 - x) + B * x) / R1
|
||||||
|
@ -1133,13 +1132,14 @@ float Correction::RankingAlgorithm::calcNormalizedScore(const unsigned short *be
|
||||||
}
|
}
|
||||||
|
|
||||||
const float maxScore = score >= S_INT_MAX ? S_INT_MAX : MAX_INITIAL_SCORE
|
const float maxScore = score >= S_INT_MAX ? S_INT_MAX : MAX_INITIAL_SCORE
|
||||||
* pow((float)TYPED_LETTER_MULTIPLIER,
|
* pow(static_cast<float>(TYPED_LETTER_MULTIPLIER),
|
||||||
(float)min(beforeLength, afterLength - spaceCount)) * FULL_WORD_MULTIPLIER;
|
static_cast<float>(min(beforeLength, afterLength - spaceCount)))
|
||||||
|
* FULL_WORD_MULTIPLIER;
|
||||||
|
|
||||||
// add a weight based on edit distance.
|
// add a weight based on edit distance.
|
||||||
// distance <= max(afterLength, beforeLength) == afterLength,
|
// distance <= max(afterLength, beforeLength) == afterLength,
|
||||||
// so, 0 <= distance / afterLength <= 1
|
// so, 0 <= distance / afterLength <= 1
|
||||||
const float weight = 1.0 - (float) distance / afterLength;
|
const float weight = 1.0f - static_cast<float>(distance) / static_cast<float>(afterLength);
|
||||||
return (score / maxScore) * weight;
|
return (score / maxScore) * weight;
|
||||||
}
|
}
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
|
|
|
@ -197,7 +197,7 @@ class Correction {
|
||||||
inline void incrementInputIndex();
|
inline void incrementInputIndex();
|
||||||
inline void incrementOutputIndex();
|
inline void incrementOutputIndex();
|
||||||
inline void startToTraverseAllNodes();
|
inline void startToTraverseAllNodes();
|
||||||
inline bool isQuote(const unsigned short c);
|
inline bool isSingleQuote(const unsigned short c);
|
||||||
inline CorrectionType processSkipChar(
|
inline CorrectionType processSkipChar(
|
||||||
const int32_t c, const bool isTerminal, const bool inputIndexIncremented);
|
const int32_t c, const bool isTerminal, const bool inputIndexIncremented);
|
||||||
inline CorrectionType processUnrelatedCorrectionType();
|
inline CorrectionType processUnrelatedCorrectionType();
|
||||||
|
|
|
@ -88,7 +88,7 @@ static inline void prof_out(void) {
|
||||||
AKLOGI("Error: You must call PROF_OPEN before PROF_CLOSE.");
|
AKLOGI("Error: You must call PROF_OPEN before PROF_CLOSE.");
|
||||||
}
|
}
|
||||||
AKLOGI("Total time is %6.3f ms.",
|
AKLOGI("Total time is %6.3f ms.",
|
||||||
profile_buf[PROF_BUF_SIZE - 1] * 1000 / (float)CLOCKS_PER_SEC);
|
profile_buf[PROF_BUF_SIZE - 1] * 1000.0f / static_cast<float>(CLOCKS_PER_SEC));
|
||||||
float all = 0;
|
float all = 0;
|
||||||
for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
|
for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
|
||||||
all += profile_buf[i];
|
all += profile_buf[i];
|
||||||
|
@ -98,7 +98,8 @@ static inline void prof_out(void) {
|
||||||
if (profile_buf[i]) {
|
if (profile_buf[i]) {
|
||||||
AKLOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.",
|
AKLOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.",
|
||||||
i, (profile_buf[i] * 100 / all),
|
i, (profile_buf[i] * 100 / all),
|
||||||
profile_buf[i] * 1000 / (float)CLOCKS_PER_SEC, profile_counter[i]);
|
profile_buf[i] * 1000.0f / static_cast<float>(CLOCKS_PER_SEC),
|
||||||
|
profile_counter[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,14 @@
|
||||||
|
|
||||||
#define LOG_TAG "LatinIME: dictionary.cpp"
|
#define LOG_TAG "LatinIME: dictionary.cpp"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "bigram_dictionary.h"
|
||||||
#include "binary_format.h"
|
#include "binary_format.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "dictionary.h"
|
#include "dictionary.h"
|
||||||
#include "gesture_decoder_wrapper.h"
|
#include "gesture_decoder_wrapper.h"
|
||||||
|
#include "unigram_dictionary.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
@ -52,6 +56,37 @@ Dictionary::~Dictionary() {
|
||||||
delete mGestureDecoder;
|
delete mGestureDecoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Dictionary::getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates,
|
||||||
|
int *times, int *pointerIds, int *codes, int codesSize, int *prevWordChars,
|
||||||
|
int prevWordLength, int commitPoint, bool isGesture,
|
||||||
|
bool useFullEditDistance, unsigned short *outWords,
|
||||||
|
int *frequencies, int *spaceIndices, int *outputTypes) {
|
||||||
|
int result = 0;
|
||||||
|
if (isGesture) {
|
||||||
|
mGestureDecoder->setPrevWord(prevWordChars, prevWordLength);
|
||||||
|
result = mGestureDecoder->getSuggestions(proximityInfo, xcoordinates, ycoordinates,
|
||||||
|
times, pointerIds, codes, codesSize, commitPoint,
|
||||||
|
outWords, frequencies, spaceIndices, outputTypes);
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
std::map<int, int> bigramMap;
|
||||||
|
uint8_t bigramFilter[BIGRAM_FILTER_BYTE_SIZE];
|
||||||
|
mBigramDictionary->fillBigramAddressToFrequencyMapAndFilter(prevWordChars,
|
||||||
|
prevWordLength, &bigramMap, bigramFilter);
|
||||||
|
result = mUnigramDictionary->getSuggestions(proximityInfo, xcoordinates,
|
||||||
|
ycoordinates, codes, codesSize, &bigramMap, bigramFilter,
|
||||||
|
useFullEditDistance, outWords, frequencies, outputTypes);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int Dictionary::getBigrams(const int32_t *word, int length, int *codes, int codesSize,
|
||||||
|
unsigned short *outWords, int *frequencies, int *outputTypes) const {
|
||||||
|
if (length <= 0) return 0;
|
||||||
|
return mBigramDictionary->getBigrams(word, length, codes, codesSize, outWords, frequencies,
|
||||||
|
outputTypes);
|
||||||
|
}
|
||||||
|
|
||||||
int Dictionary::getFrequency(const int32_t *word, int length) const {
|
int Dictionary::getFrequency(const int32_t *word, int length) const {
|
||||||
return mUnigramDictionary->getFrequency(word, length);
|
return mUnigramDictionary->getFrequency(word, length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,18 +17,17 @@
|
||||||
#ifndef LATINIME_DICTIONARY_H
|
#ifndef LATINIME_DICTIONARY_H
|
||||||
#define LATINIME_DICTIONARY_H
|
#define LATINIME_DICTIONARY_H
|
||||||
|
|
||||||
#include <map>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "bigram_dictionary.h"
|
|
||||||
#include "char_utils.h"
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "incremental_decoder_interface.h"
|
|
||||||
#include "proximity_info.h"
|
|
||||||
#include "unigram_dictionary.h"
|
|
||||||
#include "words_priority_queue_pool.h"
|
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
class BigramDictionary;
|
||||||
|
class IncrementalDecoderInterface;
|
||||||
|
class ProximityInfo;
|
||||||
|
class UnigramDictionary;
|
||||||
|
|
||||||
class Dictionary {
|
class Dictionary {
|
||||||
public:
|
public:
|
||||||
// Taken from SuggestedWords.java
|
// Taken from SuggestedWords.java
|
||||||
|
@ -49,32 +48,10 @@ class Dictionary {
|
||||||
int *times, int *pointerIds, int *codes, int codesSize, int *prevWordChars,
|
int *times, int *pointerIds, int *codes, int codesSize, int *prevWordChars,
|
||||||
int prevWordLength, int commitPoint, bool isGesture,
|
int prevWordLength, int commitPoint, bool isGesture,
|
||||||
bool useFullEditDistance, unsigned short *outWords,
|
bool useFullEditDistance, unsigned short *outWords,
|
||||||
int *frequencies, int *spaceIndices, int *outputTypes) {
|
int *frequencies, int *spaceIndices, int *outputTypes);
|
||||||
int result = 0;
|
|
||||||
if (isGesture) {
|
|
||||||
mGestureDecoder->setPrevWord(prevWordChars, prevWordLength);
|
|
||||||
result = mGestureDecoder->getSuggestions(proximityInfo, xcoordinates, ycoordinates,
|
|
||||||
times, pointerIds, codes, codesSize, commitPoint,
|
|
||||||
outWords, frequencies, spaceIndices, outputTypes);
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
std::map<int, int> bigramMap;
|
|
||||||
uint8_t bigramFilter[BIGRAM_FILTER_BYTE_SIZE];
|
|
||||||
mBigramDictionary->fillBigramAddressToFrequencyMapAndFilter(prevWordChars,
|
|
||||||
prevWordLength, &bigramMap, bigramFilter);
|
|
||||||
result = mUnigramDictionary->getSuggestions(proximityInfo, xcoordinates,
|
|
||||||
ycoordinates, codes, codesSize, &bigramMap, bigramFilter,
|
|
||||||
useFullEditDistance, outWords, frequencies, outputTypes);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int getBigrams(const int32_t *word, int length, int *codes, int codesSize,
|
int getBigrams(const int32_t *word, int length, int *codes, int codesSize,
|
||||||
unsigned short *outWords, int *frequencies, int *outputTypes) const {
|
unsigned short *outWords, int *frequencies, int *outputTypes) const;
|
||||||
if (length <= 0) return 0;
|
|
||||||
return mBigramDictionary->getBigrams(word, length, codes, codesSize, outWords, frequencies,
|
|
||||||
outputTypes);
|
|
||||||
}
|
|
||||||
|
|
||||||
int getFrequency(const int32_t *word, int length) const;
|
int getFrequency(const int32_t *word, int length) const;
|
||||||
bool isValidBigram(const int32_t *word1, int length1, const int32_t *word2, int length2) const;
|
bool isValidBigram(const int32_t *word1, int length1, const int32_t *word2, int length2) const;
|
||||||
|
@ -82,7 +59,7 @@ class Dictionary {
|
||||||
int getDictSize() const { return mDictSize; }
|
int getDictSize() const { return mDictSize; }
|
||||||
int getMmapFd() const { return mMmapFd; }
|
int getMmapFd() const { return mMmapFd; }
|
||||||
int getDictBufAdjust() const { return mDictBufAdjust; }
|
int getDictBufAdjust() const { return mDictBufAdjust; }
|
||||||
~Dictionary();
|
virtual ~Dictionary();
|
||||||
|
|
||||||
// public static utility methods
|
// public static utility methods
|
||||||
// static inline methods should be defined in the header file
|
// static inline methods should be defined in the header file
|
||||||
|
|
|
@ -22,10 +22,9 @@
|
||||||
#define LOG_TAG "LatinIME: proximity_info.cpp"
|
#define LOG_TAG "LatinIME: proximity_info.cpp"
|
||||||
|
|
||||||
#include "additional_proximity_chars.h"
|
#include "additional_proximity_chars.h"
|
||||||
|
#include "char_utils.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "dictionary.h"
|
|
||||||
#include "proximity_info.h"
|
#include "proximity_info.h"
|
||||||
#include "proximity_info_state.h"
|
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
@ -216,7 +215,7 @@ int ProximityInfo::getKeyIndex(const int c) const {
|
||||||
void ProximityInfo::getCenters(int *centerXs, int *centerYs, int *codeToKeyIndex,
|
void ProximityInfo::getCenters(int *centerXs, int *centerYs, int *codeToKeyIndex,
|
||||||
int *keyToCodeIndex, int *keyCount, int *keyWidth) const {
|
int *keyToCodeIndex, int *keyCount, int *keyWidth) const {
|
||||||
*keyCount = KEY_COUNT;
|
*keyCount = KEY_COUNT;
|
||||||
*keyWidth = sqrt((float)MOST_COMMON_KEY_WIDTH_SQUARE);
|
*keyWidth = sqrt(static_cast<float>(MOST_COMMON_KEY_WIDTH_SQUARE));
|
||||||
|
|
||||||
for (int i = 0; i < KEY_COUNT; ++i) {
|
for (int i = 0; i < KEY_COUNT; ++i) {
|
||||||
const int code = mKeyCharCodes[i];
|
const int code = mKeyCharCodes[i];
|
||||||
|
|
|
@ -14,14 +14,12 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cassert>
|
#include <cstring> // for memset()
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define LOG_TAG "LatinIME: proximity_info_state.cpp"
|
#define LOG_TAG "LatinIME: proximity_info_state.cpp"
|
||||||
|
|
||||||
#include "additional_proximity_chars.h"
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "dictionary.h"
|
|
||||||
#include "proximity_info.h"
|
#include "proximity_info.h"
|
||||||
#include "proximity_info_state.h"
|
#include "proximity_info_state.h"
|
||||||
|
|
||||||
|
@ -131,8 +129,8 @@ float ProximityInfoState::calculateSquaredDistanceFromSweetSpotCenter(
|
||||||
const int keyIndex, const int inputIndex) const {
|
const int keyIndex, const int inputIndex) const {
|
||||||
const float sweetSpotCenterX = mProximityInfo->getSweetSpotCenterXAt(keyIndex);
|
const float sweetSpotCenterX = mProximityInfo->getSweetSpotCenterXAt(keyIndex);
|
||||||
const float sweetSpotCenterY = mProximityInfo->getSweetSpotCenterYAt(keyIndex);
|
const float sweetSpotCenterY = mProximityInfo->getSweetSpotCenterYAt(keyIndex);
|
||||||
const float inputX = (float)mInputXCoordinates[inputIndex];
|
const float inputX = static_cast<float>(mInputXCoordinates[inputIndex]);
|
||||||
const float inputY = (float)mInputYCoordinates[inputIndex];
|
const float inputY = static_cast<float>(mInputYCoordinates[inputIndex]);
|
||||||
return square(inputX - sweetSpotCenterX) + square(inputY - sweetSpotCenterY);
|
return square(inputX - sweetSpotCenterX) + square(inputY - sweetSpotCenterY);
|
||||||
}
|
}
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
|
|
|
@ -17,11 +17,9 @@
|
||||||
#ifndef LATINIME_PROXIMITY_INFO_STATE_H
|
#ifndef LATINIME_PROXIMITY_INFO_STATE_H
|
||||||
#define LATINIME_PROXIMITY_INFO_STATE_H
|
#define LATINIME_PROXIMITY_INFO_STATE_H
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "additional_proximity_chars.h"
|
|
||||||
#include "char_utils.h"
|
#include "char_utils.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,15 @@
|
||||||
|
|
||||||
#define LOG_TAG "LatinIME: unigram_dictionary.cpp"
|
#define LOG_TAG "LatinIME: unigram_dictionary.cpp"
|
||||||
|
|
||||||
|
#include "binary_format.h"
|
||||||
#include "char_utils.h"
|
#include "char_utils.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "dictionary.h"
|
#include "dictionary.h"
|
||||||
#include "unigram_dictionary.h"
|
#include "proximity_info.h"
|
||||||
|
|
||||||
#include "binary_format.h"
|
|
||||||
#include "terminal_attributes.h"
|
#include "terminal_attributes.h"
|
||||||
|
#include "unigram_dictionary.h"
|
||||||
|
#include "words_priority_queue.h"
|
||||||
|
#include "words_priority_queue_pool.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#define LATINIME_WORDS_PRIORITY_QUEUE_H
|
#define LATINIME_WORDS_PRIORITY_QUEUE_H
|
||||||
|
|
||||||
#include <cstring> // for memcpy()
|
#include <cstring> // for memcpy()
|
||||||
#include <iostream>
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
#include "correction.h"
|
#include "correction.h"
|
||||||
|
|
Loading…
Reference in New Issue