1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef LATINIME_TYPING_SCORING_H 18 #define LATINIME_TYPING_SCORING_H 19 20 #include "defines.h" 21 #include "suggest/core/policy/scoring.h" 22 #include "suggest/policyimpl/typing/scoring_params.h" 23 24 namespace latinime { 25 26 class DicNode; 27 class DicTraverseSession; 28 29 class TypingScoring : public Scoring { 30 public: 31 static const TypingScoring *getInstance() { return &sInstance; } 32 33 AK_FORCE_INLINE bool getMostProbableString( 34 const DicTraverseSession *const traverseSession, const int terminalSize, 35 const float languageWeight, int *const outputCodePoints, int *const type, 36 int *const freq) const { 37 return false; 38 } 39 40 AK_FORCE_INLINE void safetyNetForMostProbableString(const int terminalSize, 41 const int maxScore, int *const outputCodePoints, int *const frequencies) const { 42 } 43 44 AK_FORCE_INLINE void searchWordWithDoubleLetter(DicNode *terminals, 45 const int terminalSize, int *doubleLetterTerminalIndex, 46 DoubleLetterLevel *doubleLetterLevel) const { 47 } 48 49 AK_FORCE_INLINE float getAdjustedLanguageWeight(DicTraverseSession *const traverseSession, 50 DicNode *const terminals, const int size) const { 51 return 1.0f; 52 } 53 54 AK_FORCE_INLINE int calculateFinalScore(const float compoundDistance, 55 const int inputSize, const bool forceCommit) const { 56 const float maxDistance = ScoringParams::DISTANCE_WEIGHT_LANGUAGE 57 + static_cast<float>(inputSize) * ScoringParams::TYPING_MAX_OUTPUT_SCORE_PER_INPUT; 58 const float score = ScoringParams::TYPING_BASE_OUTPUT_SCORE 59 - compoundDistance / maxDistance 60 + (forceCommit ? ScoringParams::AUTOCORRECT_OUTPUT_THRESHOLD : 0.0f); 61 return static_cast<int>(score * SUGGEST_INTERFACE_OUTPUT_SCALE); 62 } 63 64 AK_FORCE_INLINE float getDoubleLetterDemotionDistanceCost(const int terminalIndex, 65 const int doubleLetterTerminalIndex, 66 const DoubleLetterLevel doubleLetterLevel) const { 67 return 0.0f; 68 } 69 70 AK_FORCE_INLINE bool doesAutoCorrectValidWord() const { 71 return false; 72 } 73 74 private: 75 DISALLOW_COPY_AND_ASSIGN(TypingScoring); 76 static const TypingScoring sInstance; 77 78 TypingScoring() {} 79 ~TypingScoring() {} 80 }; 81 } // namespace latinime 82 #endif // LATINIME_TYPING_SCORING_H 83