am 77e8e81a: Header cleanup. Moved a couple of functions from .h to .cpp.

* commit '77e8e81ad95cfc1eb8f8407fc872674b8d08bbe9':
  Header cleanup.  Moved a couple of functions from .h to .cpp.
main
Ken Wakasa 2012-08-02 05:07:43 -07:00 committed by Android Git Automerger
commit 6c465d9d26
12 changed files with 72 additions and 61 deletions

View File

@ -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,
// while a value of 15 represents the middle of the top step.
// See makedict.BinaryDictInputOutput for details.
const float stepSize = ((float)MAX_FREQ - unigramFreq) / (1.5f + MAX_BIGRAM_FREQ);
return (int)(unigramFreq + (bigramFreq + 1) * stepSize);
const float stepSize = (static_cast<float>(MAX_FREQ) - unigramFreq) / (1.5f + MAX_BIGRAM_FREQ);
return static_cast<int>(unigramFreq + (bigramFreq + 1) * stepSize);
}
// This returns a probability in log space.

View File

@ -16,6 +16,8 @@
#include <cstdlib>
#include "char_utils.h"
namespace latinime {
struct LatinCapitalSmallPair {

View File

@ -24,7 +24,6 @@
#include "char_utils.h"
#include "correction.h"
#include "defines.h"
#include "dictionary.h"
#include "proximity_info_state.h"
namespace latinime {
@ -95,11 +94,11 @@ inline static int getCurrentEditDistance(int *editDistanceTable, const int editD
//////////////////////
// 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);
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;
// Skip checking this node
if (mNeedsToTraverseAllNodes || isQuote(c)) {
if (mNeedsToTraverseAllNodes || isSingleQuote(c)) {
bool incremented = false;
if (mLastCharExceeded && mInputIndex == mInputLength - 1) {
// TODO: Do not check the proximity if EditDistance exceeds the threshold
@ -344,7 +343,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
mDistances[mOutputIndex] = mProximityInfoState.getNormalizedSquaredDistance(
mInputIndex, proximityIndex);
}
if (!isQuote(c)) {
if (!isSingleQuote(c)) {
incrementInputIndex();
incremented = true;
}
@ -791,7 +790,7 @@ int Correction::RankingAlgorithm::calculateFinalProbability(const int inputIndex
static const float MIN = 0.3f;
static const float R1 = NEUTRAL_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;
const float factor = max((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
* pow((float)TYPED_LETTER_MULTIPLIER,
(float)min(beforeLength, afterLength - spaceCount)) * FULL_WORD_MULTIPLIER;
* pow(static_cast<float>(TYPED_LETTER_MULTIPLIER),
static_cast<float>(min(beforeLength, afterLength - spaceCount)))
* FULL_WORD_MULTIPLIER;
// add a weight based on edit distance.
// distance <= max(afterLength, beforeLength) == afterLength,
// 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;
}
} // namespace latinime

View File

@ -197,7 +197,7 @@ class Correction {
inline void incrementInputIndex();
inline void incrementOutputIndex();
inline void startToTraverseAllNodes();
inline bool isQuote(const unsigned short c);
inline bool isSingleQuote(const unsigned short c);
inline CorrectionType processSkipChar(
const int32_t c, const bool isTerminal, const bool inputIndexIncremented);
inline CorrectionType processUnrelatedCorrectionType();

View File

@ -88,7 +88,7 @@ static inline void prof_out(void) {
AKLOGI("Error: You must call PROF_OPEN before PROF_CLOSE.");
}
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;
for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
all += profile_buf[i];
@ -98,7 +98,8 @@ static inline void prof_out(void) {
if (profile_buf[i]) {
AKLOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.",
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]);
}
}
}

View File

@ -16,10 +16,14 @@
#define LOG_TAG "LatinIME: dictionary.cpp"
#include <stdint.h>
#include "bigram_dictionary.h"
#include "binary_format.h"
#include "defines.h"
#include "dictionary.h"
#include "gesture_decoder_wrapper.h"
#include "unigram_dictionary.h"
namespace latinime {
@ -52,6 +56,37 @@ Dictionary::~Dictionary() {
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 {
return mUnigramDictionary->getFrequency(word, length);
}

View File

@ -17,18 +17,17 @@
#ifndef LATINIME_DICTIONARY_H
#define LATINIME_DICTIONARY_H
#include <map>
#include <stdint.h>
#include "bigram_dictionary.h"
#include "char_utils.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 {
class BigramDictionary;
class IncrementalDecoderInterface;
class ProximityInfo;
class UnigramDictionary;
class Dictionary {
public:
// Taken from SuggestedWords.java
@ -49,32 +48,10 @@ class Dictionary {
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 *frequencies, int *spaceIndices, int *outputTypes);
int 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);
}
unsigned short *outWords, int *frequencies, int *outputTypes) 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;
@ -82,7 +59,7 @@ class Dictionary {
int getDictSize() const { return mDictSize; }
int getMmapFd() const { return mMmapFd; }
int getDictBufAdjust() const { return mDictBufAdjust; }
~Dictionary();
virtual ~Dictionary();
// public static utility methods
// static inline methods should be defined in the header file

View File

@ -22,10 +22,9 @@
#define LOG_TAG "LatinIME: proximity_info.cpp"
#include "additional_proximity_chars.h"
#include "char_utils.h"
#include "defines.h"
#include "dictionary.h"
#include "proximity_info.h"
#include "proximity_info_state.h"
namespace latinime {
@ -216,7 +215,7 @@ int ProximityInfo::getKeyIndex(const int c) const {
void ProximityInfo::getCenters(int *centerXs, int *centerYs, int *codeToKeyIndex,
int *keyToCodeIndex, int *keyCount, int *keyWidth) const {
*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) {
const int code = mKeyCharCodes[i];

View File

@ -14,14 +14,12 @@
* limitations under the License.
*/
#include <cassert>
#include <cstring> // for memset()
#include <stdint.h>
#define LOG_TAG "LatinIME: proximity_info_state.cpp"
#include "additional_proximity_chars.h"
#include "defines.h"
#include "dictionary.h"
#include "proximity_info.h"
#include "proximity_info_state.h"
@ -131,8 +129,8 @@ float ProximityInfoState::calculateSquaredDistanceFromSweetSpotCenter(
const int keyIndex, const int inputIndex) const {
const float sweetSpotCenterX = mProximityInfo->getSweetSpotCenterXAt(keyIndex);
const float sweetSpotCenterY = mProximityInfo->getSweetSpotCenterYAt(keyIndex);
const float inputX = (float)mInputXCoordinates[inputIndex];
const float inputY = (float)mInputYCoordinates[inputIndex];
const float inputX = static_cast<float>(mInputXCoordinates[inputIndex]);
const float inputY = static_cast<float>(mInputYCoordinates[inputIndex]);
return square(inputX - sweetSpotCenterX) + square(inputY - sweetSpotCenterY);
}
} // namespace latinime

View File

@ -17,11 +17,9 @@
#ifndef LATINIME_PROXIMITY_INFO_STATE_H
#define LATINIME_PROXIMITY_INFO_STATE_H
#include <cassert>
#include <stdint.h>
#include <string>
#include "additional_proximity_chars.h"
#include "char_utils.h"
#include "defines.h"

View File

@ -19,13 +19,15 @@
#define LOG_TAG "LatinIME: unigram_dictionary.cpp"
#include "binary_format.h"
#include "char_utils.h"
#include "defines.h"
#include "dictionary.h"
#include "unigram_dictionary.h"
#include "binary_format.h"
#include "proximity_info.h"
#include "terminal_attributes.h"
#include "unigram_dictionary.h"
#include "words_priority_queue.h"
#include "words_priority_queue_pool.h"
namespace latinime {

View File

@ -18,7 +18,6 @@
#define LATINIME_WORDS_PRIORITY_QUEUE_H
#include <cstring> // for memcpy()
#include <iostream>
#include <queue>
#include "correction.h"