Home | History | Annotate | Download | only in policy
      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 
     22 namespace latinime {
     23 
     24 class DicNode;
     25 class DicTraverseSession;
     26 struct DicNode_InputStateG;
     27 class MultiBigramMap;
     28 
     29 class 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 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             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 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     virtual ErrorType getErrorType(const CorrectionType correctionType,
     84             const DicTraverseSession *const traverseSession,
     85             const DicNode *const parentDicNode, const DicNode *const dicNode) const = 0;
     86 
     87     Weighting() {}
     88     virtual ~Weighting() {}
     89 
     90  private:
     91     DISALLOW_COPY_AND_ASSIGN(Weighting);
     92 
     93     static float getSpatialCost(const Weighting *const weighting,
     94             const CorrectionType correctionType, const DicTraverseSession *const traverseSession,
     95             const DicNode *const parentDicNode, const DicNode *const dicNode,
     96             DicNode_InputStateG *const inputStateG);
     97     static float getLanguageCost(const Weighting *const weighting,
     98             const CorrectionType correctionType, const DicTraverseSession *const traverseSession,
     99             const DicNode *const parentDicNode, const DicNode *const dicNode,
    100             MultiBigramMap *const multiBigramMap);
    101     // TODO: Move to TypingWeighting and GestureWeighting?
    102     static int getForwardInputCount(const CorrectionType correctionType);
    103 };
    104 } // namespace latinime
    105 #endif // LATINIME_WEIGHTING_H
    106