1 /* 2 * Copyright (C) 2010 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_DICTIONARY_H 18 #define LATINIME_BIGRAM_DICTIONARY_H 19 20 #include <map> 21 #include <stdint.h> 22 23 #include "defines.h" 24 25 namespace latinime { 26 27 class BigramDictionary { 28 public: 29 BigramDictionary(const uint8_t *const streamStart); 30 int getBigrams(const int *word, int length, int *inputCodePoints, int inputSize, int *outWords, 31 int *frequencies, int *outputTypes) const; 32 void fillBigramAddressToProbabilityMapAndFilter(const int *prevWord, const int prevWordLength, 33 std::map<int, int> *map, uint8_t *filter) const; 34 bool isValidBigram(const int *word1, int length1, const int *word2, int length2) const; 35 ~BigramDictionary(); 36 private: 37 DISALLOW_IMPLICIT_CONSTRUCTORS(BigramDictionary); 38 void addWordBigram(int *word, int length, int probability, int *bigramProbability, 39 int *bigramCodePoints, int *outputTypes) const; 40 bool checkFirstCharacter(int *word, int *inputCodePoints) const; 41 int getBigramListPositionForWord(const int *prevWord, const int prevWordLength, 42 const bool forceLowerCaseSearch) const; 43 44 const uint8_t *const DICT_ROOT; 45 // TODO: Re-implement proximity correction for bigram correction 46 static const int MAX_ALTERNATIVES = 1; 47 }; 48 } // namespace latinime 49 #endif // LATINIME_BIGRAM_DICTIONARY_H 50