weighting.h revision 75322cecb9fe02a0914b65c859cfbc2f4e1f70d9
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 22namespace latinime { 23 24class DicNode; 25class DicTraverseSession; 26struct DicNode_InputStateG; 27class MultiBigramMap; 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 MultiBigramMap *const multiBigramMap); 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 getNewWordSpatialCost(const DicTraverseSession *const traverseSession, 60 const DicNode *const dicNode, DicNode_InputStateG *const inputStateG) const = 0; 61 62 virtual float getNewWordBigramLanguageCost( 63 const DicTraverseSession *const traverseSession, const DicNode *const dicNode, 64 MultiBigramMap *const multiBigramMap) const = 0; 65 66 virtual float getCompletionCost( 67 const DicTraverseSession *const traverseSession, 68 const DicNode *const dicNode) const = 0; 69 70 virtual float getTerminalInsertionCost( 71 const DicTraverseSession *const traverseSession, 72 const DicNode *const dicNode) const = 0; 73 74 virtual float getTerminalLanguageCost( 75 const DicTraverseSession *const traverseSession, const DicNode *const dicNode, 76 float dicNodeLanguageImprobability) const = 0; 77 78 virtual bool needsToNormalizeCompoundDistance() const = 0; 79 80 virtual float getAdditionalProximityCost() const = 0; 81 82 virtual float getSubstitutionCost() const = 0; 83 84 virtual float getSpaceSubstitutionCost(const DicTraverseSession *const traverseSession, 85 const DicNode *const dicNode) const = 0; 86 87 virtual ErrorType getErrorType(const CorrectionType correctionType, 88 const DicTraverseSession *const traverseSession, 89 const DicNode *const parentDicNode, const DicNode *const dicNode) const = 0; 90 91 Weighting() {} 92 virtual ~Weighting() {} 93 94 private: 95 DISALLOW_COPY_AND_ASSIGN(Weighting); 96 97 static float getSpatialCost(const Weighting *const weighting, 98 const CorrectionType correctionType, const DicTraverseSession *const traverseSession, 99 const DicNode *const parentDicNode, const DicNode *const dicNode, 100 DicNode_InputStateG *const inputStateG); 101 static float getLanguageCost(const Weighting *const weighting, 102 const CorrectionType correctionType, const DicTraverseSession *const traverseSession, 103 const DicNode *const parentDicNode, const DicNode *const dicNode, 104 MultiBigramMap *const multiBigramMap); 105 // TODO: Move to TypingWeighting and GestureWeighting? 106 static int getForwardInputCount(const CorrectionType correctionType); 107}; 108} // namespace latinime 109#endif // LATINIME_WEIGHTING_H 110