Home | History | Annotate | Download | only in src
      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 namespace latinime {
     21 
     22 class Dictionary;
     23 class BigramDictionary {
     24 public:
     25     BigramDictionary(const unsigned char *dict, int maxWordLength, int maxAlternatives,
     26             const bool isLatestDictVersion, const bool hasBigram, Dictionary *parentDictionary);
     27     int getBigrams(unsigned short *word, int length, int *codes, int codesSize,
     28             unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams,
     29             int maxAlternatives);
     30     ~BigramDictionary();
     31 private:
     32     bool addWordBigram(unsigned short *word, int length, int frequency);
     33     int getBigramAddress(int *pos, bool advance);
     34     int getBigramFreq(int *pos);
     35     void searchForTerminalNode(int addressLookingFor, int frequency);
     36     bool getFirstBitOfByte(int *pos) { return (DICT[*pos] & 0x80) > 0; }
     37     bool getSecondBitOfByte(int *pos) { return (DICT[*pos] & 0x40) > 0; }
     38     bool checkFirstCharacter(unsigned short *word);
     39 
     40     const unsigned char *DICT;
     41     const int MAX_WORD_LENGTH;
     42     const int MAX_ALTERNATIVES;
     43     const bool IS_LATEST_DICT_VERSION;
     44     const bool HAS_BIGRAM;
     45 
     46     Dictionary *mParentDictionary;
     47     int *mBigramFreq;
     48     int mMaxBigrams;
     49     unsigned short *mBigramChars;
     50     int *mInputCodes;
     51     int mInputLength;
     52 };
     53 
     54 } // namespace latinime
     55 
     56 #endif // LATINIME_BIGRAM_DICTIONARY_H
     57