2009-03-13 22:11:42 +00:00
|
|
|
/*
|
|
|
|
**
|
|
|
|
** Copyright 2009, The Android Open Source Project
|
|
|
|
**
|
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
**
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
**
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2010-12-02 05:53:24 +00:00
|
|
|
#define LOG_TAG "LatinIME: dictionary.cpp"
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
#include "dictionary.h"
|
2010-12-01 10:09:29 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
namespace latinime {
|
|
|
|
|
2011-02-22 08:28:55 +00:00
|
|
|
// TODO: Change the type of all keyCodes to uint32_t
|
2011-01-07 06:01:51 +00:00
|
|
|
Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
|
|
|
|
int typedLetterMultiplier, int fullWordMultiplier,
|
2010-12-01 12:22:15 +00:00
|
|
|
int maxWordLength, int maxWords, int maxAlternatives)
|
2011-01-07 06:01:51 +00:00
|
|
|
: mDict((unsigned char*) dict), mDictSize(dictSize),
|
|
|
|
mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust),
|
2010-12-02 05:53:24 +00:00
|
|
|
// Checks whether it has the latest dictionary or the old dictionary
|
2010-12-08 08:05:39 +00:00
|
|
|
IS_LATEST_DICT_VERSION((((unsigned char*) dict)[0] & 0xFF) >= DICTIONARY_VERSION_MIN) {
|
|
|
|
if (DEBUG_DICT) {
|
|
|
|
if (MAX_WORD_LENGTH_INTERNAL < maxWordLength) {
|
|
|
|
LOGI("Max word length (%d) is greater than %d",
|
|
|
|
maxWordLength, MAX_WORD_LENGTH_INTERNAL);
|
2011-01-07 06:01:51 +00:00
|
|
|
LOGI("IN NATIVE SUGGEST Version: %d", (mDict[0] & 0xFF));
|
2010-12-08 08:05:39 +00:00
|
|
|
}
|
2010-12-02 11:19:59 +00:00
|
|
|
}
|
2011-12-14 06:04:58 +00:00
|
|
|
mCorrection = new Correction(typedLetterMultiplier, fullWordMultiplier);
|
2011-12-15 07:49:12 +00:00
|
|
|
mWordsPriorityQueuePool = new WordsPriorityQueuePool(
|
|
|
|
maxWords, SUB_QUEUE_MAX_WORDS, maxWordLength);
|
2011-01-07 06:01:51 +00:00
|
|
|
mUnigramDictionary = new UnigramDictionary(mDict, typedLetterMultiplier, fullWordMultiplier,
|
2010-12-02 09:11:54 +00:00
|
|
|
maxWordLength, maxWords, maxAlternatives, IS_LATEST_DICT_VERSION);
|
2011-01-07 06:01:51 +00:00
|
|
|
mBigramDictionary = new BigramDictionary(mDict, maxWordLength, maxAlternatives,
|
2010-12-02 09:11:54 +00:00
|
|
|
IS_LATEST_DICT_VERSION, hasBigram(), this);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-08 08:05:39 +00:00
|
|
|
Dictionary::~Dictionary() {
|
2011-12-14 06:04:58 +00:00
|
|
|
delete mCorrection;
|
2011-12-15 07:49:12 +00:00
|
|
|
delete mWordsPriorityQueuePool;
|
2010-12-01 12:22:15 +00:00
|
|
|
delete mUnigramDictionary;
|
|
|
|
delete mBigramDictionary;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-12-02 05:53:24 +00:00
|
|
|
|
|
|
|
bool Dictionary::hasBigram() {
|
2011-01-07 06:01:51 +00:00
|
|
|
return ((mDict[1] & 0xFF) == 1);
|
2010-12-02 05:53:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 08:28:55 +00:00
|
|
|
bool Dictionary::isValidWord(unsigned short *word, int length) {
|
2011-06-16 13:33:41 +00:00
|
|
|
return mUnigramDictionary->isValidWord(word, length);
|
2010-12-02 05:53:24 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
} // namespace latinime
|