| OLD | NEW |
| (Empty) | |
| 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_BIGRAM_ENTRY_H |
| 18 #define LATINIME_BIGRAM_ENTRY_H |
| 19 |
| 20 #include "third_party/prediction/defines.h" |
| 21 #include "third_party/prediction/suggest/policyimpl/dictionary/structure/v4/ver4
_dict_constants.h" |
| 22 #include "third_party/prediction/suggest/policyimpl/dictionary/utils/historical_
info.h" |
| 23 |
| 24 namespace latinime { |
| 25 |
| 26 class BigramEntry { |
| 27 public: |
| 28 BigramEntry(const BigramEntry& bigramEntry) |
| 29 : mHasNext(bigramEntry.mHasNext), |
| 30 mProbability(bigramEntry.mProbability), |
| 31 mHistoricalInfo(), |
| 32 mTargetTerminalId(bigramEntry.mTargetTerminalId) {} |
| 33 |
| 34 // Entry with historical information. |
| 35 BigramEntry(const bool hasNext, |
| 36 const int probability, |
| 37 const int targetTerminalId) |
| 38 : mHasNext(hasNext), |
| 39 mProbability(probability), |
| 40 mHistoricalInfo(), |
| 41 mTargetTerminalId(targetTerminalId) {} |
| 42 |
| 43 // Entry with historical information. |
| 44 BigramEntry(const bool hasNext, |
| 45 const int probability, |
| 46 const HistoricalInfo* const historicalInfo, |
| 47 const int targetTerminalId) |
| 48 : mHasNext(hasNext), |
| 49 mProbability(probability), |
| 50 mHistoricalInfo(*historicalInfo), |
| 51 mTargetTerminalId(targetTerminalId) {} |
| 52 |
| 53 const BigramEntry getInvalidatedEntry() const { |
| 54 return updateTargetTerminalIdAndGetEntry( |
| 55 Ver4DictConstants::NOT_A_TERMINAL_ID); |
| 56 } |
| 57 |
| 58 const BigramEntry updateHasNextAndGetEntry(const bool hasNext) const { |
| 59 return BigramEntry(hasNext, mProbability, &mHistoricalInfo, |
| 60 mTargetTerminalId); |
| 61 } |
| 62 |
| 63 const BigramEntry updateTargetTerminalIdAndGetEntry( |
| 64 const int newTargetTerminalId) const { |
| 65 return BigramEntry(mHasNext, mProbability, &mHistoricalInfo, |
| 66 newTargetTerminalId); |
| 67 } |
| 68 |
| 69 const BigramEntry updateProbabilityAndGetEntry(const int probability) const { |
| 70 return BigramEntry(mHasNext, probability, &mHistoricalInfo, |
| 71 mTargetTerminalId); |
| 72 } |
| 73 |
| 74 const BigramEntry updateHistoricalInfoAndGetEntry( |
| 75 const HistoricalInfo* const historicalInfo) const { |
| 76 return BigramEntry(mHasNext, mProbability, historicalInfo, |
| 77 mTargetTerminalId); |
| 78 } |
| 79 |
| 80 bool isValid() const { |
| 81 return mTargetTerminalId != Ver4DictConstants::NOT_A_TERMINAL_ID; |
| 82 } |
| 83 |
| 84 bool hasNext() const { return mHasNext; } |
| 85 |
| 86 int getProbability() const { return mProbability; } |
| 87 |
| 88 bool hasHistoricalInfo() const { return mHistoricalInfo.isValid(); } |
| 89 |
| 90 const HistoricalInfo* getHistoricalInfo() const { return &mHistoricalInfo; } |
| 91 |
| 92 int getTargetTerminalId() const { return mTargetTerminalId; } |
| 93 |
| 94 private: |
| 95 // Copy constructor is public to use this class as a type of return value. |
| 96 DISALLOW_DEFAULT_CONSTRUCTOR(BigramEntry); |
| 97 DISALLOW_ASSIGNMENT_OPERATOR(BigramEntry); |
| 98 |
| 99 const bool mHasNext; |
| 100 const int mProbability; |
| 101 const HistoricalInfo mHistoricalInfo; |
| 102 const int mTargetTerminalId; |
| 103 }; |
| 104 } // namespace latinime |
| 105 #endif /* LATINIME_BIGRAM_ENTRY_H */ |
| OLD | NEW |