From a10b1a88443a16bb1b5af1af63d0ed501b25f55d Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Tue, 8 Jan 2013 17:23:43 +0900 Subject: [PATCH] Misc small cleanups Change-Id: Iea61e6c76a9a0437a1b2e8143f6ab5b09a8e211e --- ...droid_inputmethod_keyboard_ProximityInfo.h | 4 +- ...droid_inputmethod_latin_BinaryDictionary.h | 4 +- ...oid_inputmethod_latin_DicTraverseSession.h | 3 +- native/jni/jni_common.h | 4 +- native/jni/src/correction.cpp | 25 +++++-------- native/jni/src/correction.h | 3 +- native/jni/src/defines.h | 4 +- native/jni/src/dic_traverse_wrapper.h | 4 +- native/jni/src/hash_map_compat.h | 4 +- native/jni/src/suggest/suggest_interface.h | 4 +- native/jni/src/unigram_dictionary.cpp | 5 +-- native/jni/src/unigram_dictionary.h | 37 +++++++++---------- native/jni/src/words_priority_queue.h | 4 +- 13 files changed, 44 insertions(+), 61 deletions(-) diff --git a/native/jni/com_android_inputmethod_keyboard_ProximityInfo.h b/native/jni/com_android_inputmethod_keyboard_ProximityInfo.h index 51fa895d3..f35287144 100644 --- a/native/jni/com_android_inputmethod_keyboard_ProximityInfo.h +++ b/native/jni/com_android_inputmethod_keyboard_ProximityInfo.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, The Android Open Source Project + * Copyright (C) 2011 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. @@ -20,8 +20,6 @@ #include "jni.h" namespace latinime { - int register_ProximityInfo(JNIEnv *env); - } // namespace latinime #endif // _COM_ANDROID_INPUTMETHOD_KEYBOARD_PROXIMITYINFO_H diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.h b/native/jni/com_android_inputmethod_latin_BinaryDictionary.h index b9e944f07..1951ba0fc 100644 --- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.h +++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, The Android Open Source Project + * Copyright (C) 2011 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. @@ -20,8 +20,6 @@ #include "jni.h" namespace latinime { - int register_BinaryDictionary(JNIEnv *env); - } // namespace latinime #endif // _COM_ANDROID_INPUTMETHOD_LATIN_BINARYDICTIONARY_H diff --git a/native/jni/com_android_inputmethod_latin_DicTraverseSession.h b/native/jni/com_android_inputmethod_latin_DicTraverseSession.h index 37531e96b..dec130f16 100644 --- a/native/jni/com_android_inputmethod_latin_DicTraverseSession.h +++ b/native/jni/com_android_inputmethod_latin_DicTraverseSession.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012, The Android Open Source Project + * 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. @@ -17,7 +17,6 @@ #ifndef _COM_ANDROID_INPUTMETHOD_LATIN_DICTRAVERSESESSION_H #define _COM_ANDROID_INPUTMETHOD_LATIN_DICTRAVERSESESSION_H -#include "defines.h" #include "jni.h" namespace latinime { diff --git a/native/jni/jni_common.h b/native/jni/jni_common.h index 993f97e80..f960b05a6 100644 --- a/native/jni/jni_common.h +++ b/native/jni/jni_common.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, The Android Open Source Project + * Copyright (C) 2011 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. @@ -20,9 +20,7 @@ #include "jni.h" namespace latinime { - int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods, int numMethods); - } // namespace latinime #endif // LATINIME_JNI_COMMON_H diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp index 46ca91105..24221c98c 100644 --- a/native/jni/src/correction.cpp +++ b/native/jni/src/correction.cpp @@ -71,8 +71,7 @@ void Correction::resetCorrection() { mTotalTraverseCount = 0; } -void Correction::initCorrection(const ProximityInfo *pi, const int inputSize, - const int maxDepth) { +void Correction::initCorrection(const ProximityInfo *pi, const int inputSize, const int maxDepth) { mProximityInfo = pi; mInputSize = inputSize; mMaxDepth = maxDepth; @@ -168,8 +167,7 @@ bool Correction::initProcessState(const int outputIndex) { return true; } -int Correction::goDownTree( - const int parentIndex, const int childCount, const int firstChildPos) { +int Correction::goDownTree(const int parentIndex, const int childCount, const int firstChildPos) { mCorrectionStates[mOutputIndex].mParentIndex = parentIndex; mCorrectionStates[mOutputIndex].mChildCount = childCount; mCorrectionStates[mOutputIndex].mSiblingPos = firstChildPos; @@ -532,8 +530,7 @@ inline static bool isUpperCase(unsigned short c) { // RankingAlgorithm // ////////////////////// -/* static */ -int Correction::RankingAlgorithm::calculateFinalProbability(const int inputIndex, +/* static */ int Correction::RankingAlgorithm::calculateFinalProbability(const int inputIndex, const int outputIndex, const int freq, int *editDistanceTable, const Correction *correction, const int inputSize) { const int excessivePos = correction->getExcessivePos(); @@ -794,10 +791,9 @@ int Correction::RankingAlgorithm::calculateFinalProbability(const int inputIndex return finalFreq; } -/* static */ -int Correction::RankingAlgorithm::calcFreqForSplitMultipleWords( - const int *freqArray, const int *wordLengthArray, const int wordCount, - const Correction *correction, const bool isSpaceProximity, const int *word) { +/* static */ int Correction::RankingAlgorithm::calcFreqForSplitMultipleWords(const int *freqArray, + const int *wordLengthArray, const int wordCount, const Correction *correction, + const bool isSpaceProximity, const int *word) { const int typedLetterMultiplier = correction->TYPED_LETTER_MULTIPLIER; bool firstCapitalizedWordDemotion = false; @@ -965,8 +961,8 @@ inline static int editDistanceInternal(int *editDistanceTable, const int *before return dp[li * lo - 1]; } -int Correction::RankingAlgorithm::editDistance(const int *before, const int beforeLength, - const int *after, const int afterLength) { +/* static */ int Correction::RankingAlgorithm::editDistance(const int *before, + const int beforeLength, const int *after, const int afterLength) { int table[(beforeLength + 1) * (afterLength + 1)]; return editDistanceInternal(table, before, beforeLength, after, afterLength); } @@ -993,9 +989,8 @@ int Correction::RankingAlgorithm::editDistance(const int *before, const int befo // the result. // So, we can normalize original score by dividing powf(2, min(b.l(),a.l())) * 255 * 2. -/* static */ -float Correction::RankingAlgorithm::calcNormalizedScore(const int *before, const int beforeLength, - const int *after, const int afterLength, const int score) { +/* static */ float Correction::RankingAlgorithm::calcNormalizedScore(const int *before, + const int beforeLength, const int *after, const int afterLength, const int score) { if (0 == beforeLength || 0 == afterLength) { return 0.0f; } diff --git a/native/jni/src/correction.h b/native/jni/src/correction.h index 4184c6429..046935579 100644 --- a/native/jni/src/correction.h +++ b/native/jni/src/correction.h @@ -58,8 +58,7 @@ class Correction { // Non virtual inline destructor -- never inherit this class ~Correction() {} void resetCorrection(); - void initCorrection( - const ProximityInfo *pi, const int inputSize, const int maxWordLength); + void initCorrection(const ProximityInfo *pi, const int inputSize, const int maxWordLength); void initCorrectionState(const int rootPos, const int childCount, const bool traverseAll); // TODO: remove diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h index 7b127a2af..46595d80a 100644 --- a/native/jni/src/defines.h +++ b/native/jni/src/defines.h @@ -1,11 +1,11 @@ /* - * Copyright (C) 2010, The Android Open Source Project + * Copyright (C) 2010 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 + * 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, diff --git a/native/jni/src/dic_traverse_wrapper.h b/native/jni/src/dic_traverse_wrapper.h index 22cf1b1a1..9a1db3852 100644 --- a/native/jni/src/dic_traverse_wrapper.h +++ b/native/jni/src/dic_traverse_wrapper.h @@ -1,11 +1,11 @@ /* - * Copyright (C) 2012, The Android Open Source Project + * 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 + * 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, diff --git a/native/jni/src/hash_map_compat.h b/native/jni/src/hash_map_compat.h index 116359a73..a1e982bc4 100644 --- a/native/jni/src/hash_map_compat.h +++ b/native/jni/src/hash_map_compat.h @@ -1,11 +1,11 @@ /* - * Copyright (C) 2012, The Android Open Source Project + * 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 + * 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, diff --git a/native/jni/src/suggest/suggest_interface.h b/native/jni/src/suggest/suggest_interface.h index de58e7918..0fb54266c 100644 --- a/native/jni/src/suggest/suggest_interface.h +++ b/native/jni/src/suggest/suggest_interface.h @@ -28,8 +28,8 @@ class SuggestInterface { virtual int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs, int *times, int *pointerIds, int *codes, int inputSize, int commitPoint, int *outWords, int *frequencies, int *outputIndices, int *outputTypes) const = 0; - SuggestInterface() {}; - virtual ~SuggestInterface() {}; + SuggestInterface() {} + virtual ~SuggestInterface() {} private: DISALLOW_COPY_AND_ASSIGN(SuggestInterface); }; diff --git a/native/jni/src/unigram_dictionary.cpp b/native/jni/src/unigram_dictionary.cpp index def4a5bf8..ebeef13b9 100644 --- a/native/jni/src/unigram_dictionary.cpp +++ b/native/jni/src/unigram_dictionary.cpp @@ -365,7 +365,7 @@ void UnigramDictionary::getSuggestionCandidates(const bool useFullEditDistance, } void UnigramDictionary::onTerminal(const int probability, - const TerminalAttributes& terminalAttributes, Correction *correction, + const TerminalAttributes &terminalAttributes, Correction *correction, WordsPriorityQueuePool *queuePool, const bool addToMasterQueue, const int currentWordIndex) const { const int inputIndex = correction->getInputIndex(); @@ -390,8 +390,7 @@ void UnigramDictionary::onTerminal(const int probability, const int shortcutProbability = finalProbability > 0 ? finalProbability - 1 : 0; // Please note that the shortcut candidates will be added to the master queue only. - TerminalAttributes::ShortcutIterator iterator = - terminalAttributes.getShortcutIterator(); + TerminalAttributes::ShortcutIterator iterator = terminalAttributes.getShortcutIterator(); while (iterator.hasNextShortcutTarget()) { // TODO: addWord only supports weak ordering, meaning we have no means // to control the order of the shortcuts relative to one another or to the word. diff --git a/native/jni/src/unigram_dictionary.h b/native/jni/src/unigram_dictionary.h index 3162e46e5..f5850b4f4 100644 --- a/native/jni/src/unigram_dictionary.h +++ b/native/jni/src/unigram_dictionary.h @@ -59,14 +59,13 @@ class UnigramDictionary { WordsPriorityQueuePool *queuePool) const; int getDigraphReplacement(const int *codes, const int i, const int codesSize, const digraph_t *const digraphs, const unsigned int digraphsSize) const; - void getWordWithDigraphSuggestionsRec(ProximityInfo *proximityInfo, - const int *xcoordinates, const int *ycoordinates, const int *codesBuffer, - int *xCoordinatesBuffer, int *yCoordinatesBuffer, const int codesBufferSize, - const std::map *bigramMap, const uint8_t *bigramFilter, - const bool useFullEditDistance, const int *codesSrc, const int codesRemain, - const int currentDepth, int *codesDest, Correction *correction, - WordsPriorityQueuePool *queuePool, const digraph_t *const digraphs, - const unsigned int digraphsSize) const; + void getWordWithDigraphSuggestionsRec(ProximityInfo *proximityInfo, const int *xcoordinates, + const int *ycoordinates, const int *codesBuffer, int *xCoordinatesBuffer, + int *yCoordinatesBuffer, const int codesBufferSize, const std::map *bigramMap, + const uint8_t *bigramFilter, const bool useFullEditDistance, const int *codesSrc, + const int codesRemain, const int currentDepth, int *codesDest, Correction *correction, + WordsPriorityQueuePool *queuePool, const digraph_t *const digraphs, + const unsigned int digraphsSize) const; void initSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates, const int *ycoordinates, const int *codes, const int codesSize, Correction *correction) const; @@ -79,12 +78,11 @@ class UnigramDictionary { const std::map *bigramMap, const uint8_t *bigramFilter, Correction *correction, WordsPriorityQueuePool *queuePool, const bool doAutoCompletion, const int maxErrors, const int currentWordIndex) const; - void getSplitMultipleWordsSuggestions(ProximityInfo *proximityInfo, - const int *xcoordinates, const int *ycoordinates, const int *codes, - const bool useFullEditDistance, const int inputSize, - Correction *correction, WordsPriorityQueuePool *queuePool, + void getSplitMultipleWordsSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates, + const int *ycoordinates, const int *codes, const bool useFullEditDistance, + const int inputSize, Correction *correction, WordsPriorityQueuePool *queuePool, const bool hasAutoCorrectionCandidate) const; - void onTerminal(const int freq, const TerminalAttributes& terminalAttributes, + void onTerminal(const int freq, const TerminalAttributes &terminalAttributes, Correction *correction, WordsPriorityQueuePool *queuePool, const bool addToMasterQueue, const int currentWordIndex) const; // Process a node by considering proximity, missing and excessive character @@ -96,14 +94,13 @@ class UnigramDictionary { Correction *correction, int *word) const; int getMostFrequentWordLikeInner(const int *const inWord, const int inputSize, int *outWord) const; - int getSubStringSuggestion( - ProximityInfo *proximityInfo, const int *xcoordinates, const int *ycoordinates, - const int *codes, const bool useFullEditDistance, Correction *correction, - WordsPriorityQueuePool *queuePool, const int inputSize, + int getSubStringSuggestion(ProximityInfo *proximityInfo, const int *xcoordinates, + const int *ycoordinates, const int *codes, const bool useFullEditDistance, + Correction *correction, WordsPriorityQueuePool *queuePool, const int inputSize, const bool hasAutoCorrectionCandidate, const int currentWordIndex, - const int inputWordStartPos, const int inputWordLength, - const int outputWordStartPos, const bool isSpaceProximity, int *freqArray, - int *wordLengthArray, int *outputWord, int *outputWordLength) const; + const int inputWordStartPos, const int inputWordLength, const int outputWordStartPos, + const bool isSpaceProximity, int *freqArray, int *wordLengthArray, int *outputWord, + int *outputWordLength) const; void getMultiWordsSuggestionRec(ProximityInfo *proximityInfo, const int *xcoordinates, const int *ycoordinates, const int *codes, const bool useFullEditDistance, const int inputSize, Correction *correction, WordsPriorityQueuePool *queuePool, diff --git a/native/jni/src/words_priority_queue.h b/native/jni/src/words_priority_queue.h index e613d2f8a..84b4b484f 100644 --- a/native/jni/src/words_priority_queue.h +++ b/native/jni/src/words_priority_queue.h @@ -28,7 +28,7 @@ namespace latinime { class WordsPriorityQueue { public: class SuggestedWord { - public: + public: int mScore; int mWord[MAX_WORD_LENGTH_INTERNAL]; int mWordLength; @@ -122,7 +122,7 @@ class WordsPriorityQueue { AK_FORCE_INLINE float getHighestNormalizedScore(const int *before, const int beforeLength, int **outWord, int *outScore, int *outLength) { if (!mHighestSuggestedWord) { - return 0.0; + return 0.0f; } return getNormalizedScore(mHighestSuggestedWord, before, beforeLength, outWord, outScore, outLength);