weighting.h revision 252412d7eb4573f91588b06b0fe49ef9f0ac38ac
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_WEIGHTING_H 18#define LATINIME_WEIGHTING_H 19 20#include "defines.h" 21#include "hash_map_compat.h" 22 23namespace latinime { 24 25class DicNode; 26class DicTraverseSession; 27struct DicNode_InputStateG; 28 29class Weighting { 30 public: 31 static void addCostAndForwardInputIndex(const Weighting *const weighting, 32 const CorrectionType correctionType, 33 const DicTraverseSession *const traverseSession, 34 const DicNode *const parentDicNode, DicNode *const dicNode, 35 hash_map_compat<int, int16_t> *const bigramCacheMap); 36 37 protected: 38 virtual float getTerminalSpatialCost(const DicTraverseSession *const traverseSession, 39 const DicNode *const dicNode) const = 0; 40 41 virtual float getOmissionCost( 42 const DicNode *const parentDicNode, const DicNode *const dicNode) const = 0; 43 44 virtual float getMatchedCost( 45 const DicTraverseSession *const traverseSession, const DicNode *const dicNode, 46 DicNode_InputStateG *inputStateG) const = 0; 47 48 virtual bool isProximityDicNode(const DicTraverseSession *const traverseSession, 49 const DicNode *const dicNode) const = 0; 50 51 virtual float getTranspositionCost( 52 const DicTraverseSession *const traverseSession, const DicNode *const parentDicNode, 53 const DicNode *const dicNode) const = 0; 54 55 virtual float getInsertionCost( 56 const DicTraverseSession *const traverseSession, 57 const DicNode *const parentDicNode, const DicNode *const dicNode) const = 0; 58 59 virtual float getNewWordCost(const DicTraverseSession *const traverseSession, 60 const DicNode *const dicNode) const = 0; 61 62 virtual float getNewWordBigramCost( 63 const DicTraverseSession *const traverseSession, const DicNode *const dicNode, 64 hash_map_compat<int, int16_t> *const bigramCacheMap) const = 0; 65 66 virtual float getCompletionCost( 67 const DicTraverseSession *const traverseSession, 68 const DicNode *const dicNode) const = 0; 69 70 virtual float getTerminalLanguageCost( 71 const DicTraverseSession *const traverseSession, const DicNode *const dicNode, 72 float dicNodeLanguageImprobability) const = 0; 73 74 virtual bool needsToNormalizeCompoundDistance() const = 0; 75 76 virtual float getAdditionalProximityCost() const = 0; 77 78 virtual float getSubstitutionCost() const = 0; 79 80 virtual float getSpaceSubstitutionCost(const DicTraverseSession *const traverseSession, 81 const DicNode *const dicNode) const = 0; 82 83 Weighting() {} 84 virtual ~Weighting() {} 85 86 private: 87 DISALLOW_COPY_AND_ASSIGN(Weighting); 88 89 static float getSpatialCost(const Weighting *const weighting, 90 const CorrectionType correctionType, const DicTraverseSession *const traverseSession, 91 const DicNode *const parentDicNode, const DicNode *const dicNode, 92 DicNode_InputStateG *const inputStateG); 93 static float getLanguageCost(const Weighting *const weighting, 94 const CorrectionType correctionType, const DicTraverseSession *const traverseSession, 95 const DicNode *const parentDicNode, const DicNode *const dicNode, 96 hash_map_compat<int, int16_t> *const bigramCacheMap); 97 // TODO: Move to TypingWeighting and GestureWeighting? 98 static bool isEditCorrection(const CorrectionType correctionType); 99 // TODO: Move to TypingWeighting and GestureWeighting? 100 static bool isProximityCorrection(const Weighting *const weighting, 101 const CorrectionType correctionType, const DicTraverseSession *const traverseSession, 102 const DicNode *const dicNode); 103 // TODO: Move to TypingWeighting and GestureWeighting? 104 static int getForwardInputCount(const CorrectionType correctionType); 105}; 106} // namespace latinime 107#endif // LATINIME_WEIGHTING_H 108