1 /*
2  * Copyright (C) 2012 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_DIC_NODE_STATE_INPUT_H
18 #define LATINIME_DIC_NODE_STATE_INPUT_H
19 
20 #include "defines.h"
21 
22 namespace latinime {
23 
24 // TODO: Have a .cpp for this class
25 class DicNodeStateInput {
26  public:
DicNodeStateInput()27     DicNodeStateInput() {}
~DicNodeStateInput()28     ~DicNodeStateInput() {}
29 
init()30     void init() {
31         for (int i = 0; i < MAX_POINTER_COUNT_G; i++) {
32             // TODO: The initial value for mInputIndex should be -1?
33             //mInputIndex[i] = i == 0 ? 0 : -1;
34             mInputIndex[i] = 0;
35             mPrevCodePoint[i] = NOT_A_CODE_POINT;
36             mTerminalDiffCost[i] = static_cast<float>(MAX_VALUE_FOR_WEIGHTING);
37         }
38     }
39 
init(const DicNodeStateInput * const src,const bool resetTerminalDiffCost)40     void init(const DicNodeStateInput *const src, const bool resetTerminalDiffCost) {
41         for (int i = 0; i < MAX_POINTER_COUNT_G; i++) {
42              mInputIndex[i] = src->mInputIndex[i];
43              mPrevCodePoint[i] = src->mPrevCodePoint[i];
44              mTerminalDiffCost[i] = resetTerminalDiffCost ?
45                      static_cast<float>(MAX_VALUE_FOR_WEIGHTING) : src->mTerminalDiffCost[i];
46          }
47     }
48 
updateInputIndexG(const int pointerId,const int inputIndex,const int prevCodePoint,const float terminalDiffCost,const float rawLength)49     void updateInputIndexG(const int pointerId, const int inputIndex,
50             const int prevCodePoint, const float terminalDiffCost, const float rawLength) {
51         mInputIndex[pointerId] = inputIndex;
52         mPrevCodePoint[pointerId] = prevCodePoint;
53         mTerminalDiffCost[pointerId] = terminalDiffCost;
54     }
55 
initByCopy(const DicNodeStateInput * const src)56     void initByCopy(const DicNodeStateInput *const src) {
57         init(src, false);
58     }
59 
60     // For transposition
setPrevCodePoint(const int pointerId,const int c)61     void setPrevCodePoint(const int pointerId, const int c) {
62         mPrevCodePoint[pointerId] = c;
63     }
64 
forwardInputIndex(const int pointerId,const int val)65     void forwardInputIndex(const int pointerId, const int val) {
66         if (mInputIndex[pointerId] < 0) {
67             mInputIndex[pointerId] = val;
68         } else {
69             mInputIndex[pointerId] = mInputIndex[pointerId] + val;
70         }
71     }
72 
getInputIndex(const int pointerId)73     int getInputIndex(const int pointerId) const {
74         // when "inputIndex" exceeds "inputSize", auto-completion needs to be done
75         return mInputIndex[pointerId];
76     }
77 
getPrevCodePoint(const int pointerId)78     int getPrevCodePoint(const int pointerId) const {
79         return mPrevCodePoint[pointerId];
80     }
81 
getTerminalDiffCost(const int pointerId)82     float getTerminalDiffCost(const int pointerId) const {
83         return mTerminalDiffCost[pointerId];
84     }
85 
86  private:
87     DISALLOW_COPY_AND_ASSIGN(DicNodeStateInput);
88 
89     int mInputIndex[MAX_POINTER_COUNT_G];
90     int mPrevCodePoint[MAX_POINTER_COUNT_G];
91     float mTerminalDiffCost[MAX_POINTER_COUNT_G];
92 };
93 } // namespace latinime
94 #endif // LATINIME_DIC_NODE_STATE_INPUT_H
95