Loading native/jni/src/binary_format.h +2 −2 Original line number Diff line number Diff line Loading @@ -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. Loading native/jni/src/char_utils.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #include <cstdlib> #include "char_utils.h" namespace latinime { struct LatinCapitalSmallPair { Loading native/jni/src/correction.cpp +10 −10 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ #include "char_utils.h" #include "correction.h" #include "defines.h" #include "dictionary.h" #include "proximity_info_state.h" namespace latinime { Loading Loading @@ -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); } //////////////// Loading Loading @@ -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 Loading @@ -344,7 +343,7 @@ Correction::CorrectionType Correction::processCharAndCalcState( mDistances[mOutputIndex] = mProximityInfoState.getNormalizedSquaredDistance( mInputIndex, proximityIndex); } if (!isQuote(c)) { if (!isSingleQuote(c)) { incrementInputIndex(); incremented = true; } Loading Loading @@ -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 Loading Loading @@ -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 native/jni/src/correction.h +1 −1 Original line number Diff line number Diff line Loading @@ -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(); Loading native/jni/src/defines.h +3 −2 Original line number Diff line number Diff line Loading @@ -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]; Loading @@ -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]); } } } Loading Loading
native/jni/src/binary_format.h +2 −2 Original line number Diff line number Diff line Loading @@ -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. Loading
native/jni/src/char_utils.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #include <cstdlib> #include "char_utils.h" namespace latinime { struct LatinCapitalSmallPair { Loading
native/jni/src/correction.cpp +10 −10 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ #include "char_utils.h" #include "correction.h" #include "defines.h" #include "dictionary.h" #include "proximity_info_state.h" namespace latinime { Loading Loading @@ -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); } //////////////// Loading Loading @@ -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 Loading @@ -344,7 +343,7 @@ Correction::CorrectionType Correction::processCharAndCalcState( mDistances[mOutputIndex] = mProximityInfoState.getNormalizedSquaredDistance( mInputIndex, proximityIndex); } if (!isQuote(c)) { if (!isSingleQuote(c)) { incrementInputIndex(); incremented = true; } Loading Loading @@ -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 Loading Loading @@ -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
native/jni/src/correction.h +1 −1 Original line number Diff line number Diff line Loading @@ -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(); Loading
native/jni/src/defines.h +3 −2 Original line number Diff line number Diff line Loading @@ -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]; Loading @@ -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]); } } } Loading