ver4_bigram_list_policy.h revision 804f7450fc94ad47c2a12ec9c1183a244f3f1a17
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_VER4_BIGRAM_LIST_POLICY_H 18#define LATINIME_VER4_BIGRAM_LIST_POLICY_H 19 20#include "defines.h" 21#include "suggest/core/policy/dictionary_bigrams_structure_policy.h" 22#include "suggest/policyimpl/dictionary/structure/v4/content/bigram_entry.h" 23 24namespace latinime { 25 26class BigramDictContent; 27class BigramProperty; 28class HeaderPolicy; 29class TerminalPositionLookupTable; 30 31class Ver4BigramListPolicy : public DictionaryBigramsStructurePolicy { 32 public: 33 Ver4BigramListPolicy(BigramDictContent *const bigramDictContent, 34 const TerminalPositionLookupTable *const terminalPositionLookupTable, 35 const HeaderPolicy *const headerPolicy) 36 : mBigramDictContent(bigramDictContent), 37 mTerminalPositionLookupTable(terminalPositionLookupTable), 38 mHeaderPolicy(headerPolicy) {} 39 40 void getNextBigram(int *const outBigramPos, int *const outProbability, 41 bool *const outHasNext, int *const bigramEntryPos) const; 42 43 void skipAllBigrams(int *const pos) const { 44 // Do nothing because we don't need to skip bigram lists in ver4 dictionaries. 45 } 46 47 bool addNewEntry(const int terminalId, const int newTargetTerminalId, 48 const BigramProperty *const bigramProperty, bool *const outAddedNewEntry); 49 50 bool removeEntry(const int terminalId, const int targetTerminalId); 51 52 bool updateAllBigramEntriesAndDeleteUselessEntries(const int terminalId, 53 int *const outBigramCount); 54 55 int getBigramEntryConut(const int terminalId); 56 57 private: 58 DISALLOW_IMPLICIT_CONSTRUCTORS(Ver4BigramListPolicy); 59 60 int getEntryPosToUpdate(const int targetTerminalIdToFind, const int bigramListPos, 61 int *const outTailEntryPos) const; 62 63 const BigramEntry createUpdatedBigramEntryFrom(const BigramEntry *const originalBigramEntry, 64 const BigramProperty *const bigramProperty) const; 65 66 BigramDictContent *const mBigramDictContent; 67 const TerminalPositionLookupTable *const mTerminalPositionLookupTable; 68 const HeaderPolicy *const mHeaderPolicy; 69}; 70} // namespace latinime 71#endif /* LATINIME_VER4_BIGRAM_LIST_POLICY_H */ 72