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: 27 DicNodeStateInput() {} 28 virtual ~DicNodeStateInput() {} 29 30 // TODO: Merge into DicNodeStatePrevWord::truncate 31 void truncate(const int commitPoint) { 32 mInputIndex[0] -= commitPoint; 33 } 34 35 void init() { 36 for (int i = 0; i < MAX_POINTER_COUNT_G; i++) { 37 // TODO: The initial value for mInputIndex should be -1? 38 //mInputIndex[i] = i == 0 ? 0 : -1; 39 mInputIndex[i] = 0; 40 mPrevCodePoint[i] = NOT_A_CODE_POINT; 41 mTerminalDiffCost[i] = static_cast<float>(MAX_VALUE_FOR_WEIGHTING); 42 } 43 } 44 45 void init(const DicNodeStateInput *const src, const bool resetTerminalDiffCost) { 46 for (int i = 0; i < MAX_POINTER_COUNT_G; i++) { 47 mInputIndex[i] = src->mInputIndex[i]; 48 mPrevCodePoint[i] = src->mPrevCodePoint[i]; 49 mTerminalDiffCost[i] = resetTerminalDiffCost ? 50 static_cast<float>(MAX_VALUE_FOR_WEIGHTING) : src->mTerminalDiffCost[i]; 51 } 52 } 53 54 void updateInputIndexG(const int pointerId, const int inputIndex, 55 const int prevCodePoint, const float terminalDiffCost, const float rawLength) { 56 mInputIndex[pointerId] = inputIndex; 57 mPrevCodePoint[pointerId] = prevCodePoint; 58 mTerminalDiffCost[pointerId] = terminalDiffCost; 59 } 60 61 void init(const DicNodeStateInput *const src) { 62 init(src, false); 63 } 64 65 // For transposition 66 void setPrevCodePoint(const int pointerId, const int c) { 67 mPrevCodePoint[pointerId] = c; 68 } 69 70 void forwardInputIndex(const int pointerId, const int val) { 71 if (mInputIndex[pointerId] < 0) { 72 mInputIndex[pointerId] = val; 73 } else { 74 mInputIndex[pointerId] = mInputIndex[pointerId] + val; 75 } 76 } 77 78 int getInputIndex(const int pointerId) const { 79 // when "inputIndex" exceeds "inputSize", auto-completion needs to be done 80 return mInputIndex[pointerId]; 81 } 82 83 int getPrevCodePoint(const int pointerId) const { 84 return mPrevCodePoint[pointerId]; 85 } 86 87 float getTerminalDiffCost(const int pointerId) const { 88 return mTerminalDiffCost[pointerId]; 89 } 90 91 private: 92 // Caution!!! 93 // Use a default copy constructor and an assign operator because shallow copies are ok 94 // for this class 95 int mInputIndex[MAX_POINTER_COUNT_G]; 96 int mPrevCodePoint[MAX_POINTER_COUNT_G]; 97 float mTerminalDiffCost[MAX_POINTER_COUNT_G]; 98 }; 99 } // namespace latinime 100 #endif // LATINIME_DIC_NODE_STATE_INPUT_H 101