Home | History | Annotate | Download | only in src
      1 /*
      2 **
      3 ** Copyright 2009, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 #include <stdio.h>
     19 
     20 #define LOG_TAG "LatinIME: dictionary.cpp"
     21 
     22 #include "dictionary.h"
     23 
     24 namespace latinime {
     25 
     26 // TODO: Change the type of all keyCodes to uint32_t
     27 Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
     28         int typedLetterMultiplier, int fullWordMultiplier,
     29         int maxWordLength, int maxWords, int maxAlternatives)
     30     : mDict((unsigned char*) dict), mDictSize(dictSize),
     31     mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust),
     32     // Checks whether it has the latest dictionary or the old dictionary
     33     IS_LATEST_DICT_VERSION((((unsigned char*) dict)[0] & 0xFF) >= DICTIONARY_VERSION_MIN) {
     34     if (DEBUG_DICT) {
     35         if (MAX_WORD_LENGTH_INTERNAL < maxWordLength) {
     36             LOGI("Max word length (%d) is greater than %d",
     37                     maxWordLength, MAX_WORD_LENGTH_INTERNAL);
     38             LOGI("IN NATIVE SUGGEST Version: %d", (mDict[0] & 0xFF));
     39         }
     40     }
     41     mUnigramDictionary = new UnigramDictionary(mDict, typedLetterMultiplier, fullWordMultiplier,
     42             maxWordLength, maxWords, maxAlternatives, IS_LATEST_DICT_VERSION);
     43     mBigramDictionary = new BigramDictionary(mDict, maxWordLength, maxAlternatives,
     44             IS_LATEST_DICT_VERSION, hasBigram(), this);
     45 }
     46 
     47 Dictionary::~Dictionary() {
     48     delete mUnigramDictionary;
     49     delete mBigramDictionary;
     50 }
     51 
     52 bool Dictionary::hasBigram() {
     53     return ((mDict[1] & 0xFF) == 1);
     54 }
     55 
     56 bool Dictionary::isValidWord(unsigned short *word, int length) {
     57     return mUnigramDictionary->isValidWord(word, length);
     58 }
     59 
     60 } // namespace latinime
     61