2009-03-13 22:11:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LATINIME_DICTIONARY_H
|
|
|
|
#define LATINIME_DICTIONARY_H
|
|
|
|
|
2012-05-02 07:00:24 +00:00
|
|
|
#include <map>
|
|
|
|
|
2010-12-01 12:22:15 +00:00
|
|
|
#include "bigram_dictionary.h"
|
2011-07-14 06:43:42 +00:00
|
|
|
#include "char_utils.h"
|
2011-12-14 06:04:58 +00:00
|
|
|
#include "correction.h"
|
2010-12-02 05:53:24 +00:00
|
|
|
#include "defines.h"
|
2011-02-22 08:28:55 +00:00
|
|
|
#include "proximity_info.h"
|
2010-12-01 12:22:15 +00:00
|
|
|
#include "unigram_dictionary.h"
|
2011-12-15 07:49:12 +00:00
|
|
|
#include "words_priority_queue_pool.h"
|
2010-12-01 12:22:15 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
namespace latinime {
|
|
|
|
|
|
|
|
class Dictionary {
|
2012-01-06 03:24:38 +00:00
|
|
|
public:
|
2011-01-07 06:01:51 +00:00
|
|
|
Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int typedLetterMultipler,
|
2012-03-28 09:21:04 +00:00
|
|
|
int fullWordMultiplier, int maxWordLength, int maxWords);
|
2011-12-14 06:04:58 +00:00
|
|
|
|
2011-02-22 08:28:55 +00:00
|
|
|
int getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates,
|
2012-04-24 09:06:51 +00:00
|
|
|
int *codes, int codesSize, const int32_t* prevWordChars, const int prevWordLength,
|
|
|
|
bool useFullEditDistance, unsigned short *outWords, int *frequencies) {
|
2012-05-02 07:00:24 +00:00
|
|
|
std::map<int, int> bigramMap;
|
2012-05-02 10:05:27 +00:00
|
|
|
uint8_t bigramFilter[BIGRAM_FILTER_BYTE_SIZE];
|
|
|
|
mBigramDictionary->fillBigramAddressToFrequencyMapAndFilter(prevWordChars,
|
|
|
|
prevWordLength, &bigramMap, bigramFilter);
|
2011-12-15 07:49:12 +00:00
|
|
|
return mUnigramDictionary->getSuggestions(proximityInfo, mWordsPriorityQueuePool,
|
2012-05-07 07:28:30 +00:00
|
|
|
mCorrection, xcoordinates, ycoordinates, codes, codesSize, &bigramMap,
|
|
|
|
bigramFilter, useFullEditDistance, outWords, frequencies);
|
2010-12-01 12:22:15 +00:00
|
|
|
}
|
|
|
|
|
2012-04-23 06:37:07 +00:00
|
|
|
int getBigrams(const int32_t *word, int length, int *codes, int codesSize,
|
2012-03-28 09:21:04 +00:00
|
|
|
unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams) {
|
2010-12-02 09:11:54 +00:00
|
|
|
return mBigramDictionary->getBigrams(word, length, codes, codesSize, outWords, frequencies,
|
2012-03-28 09:21:04 +00:00
|
|
|
maxWordLength, maxBigrams);
|
2010-12-01 12:22:15 +00:00
|
|
|
}
|
2011-02-22 08:28:55 +00:00
|
|
|
|
2012-04-23 06:37:07 +00:00
|
|
|
bool isValidWord(const int32_t *word, int length);
|
2011-01-07 06:01:51 +00:00
|
|
|
void *getDict() { return (void *)mDict; }
|
|
|
|
int getDictSize() { return mDictSize; }
|
|
|
|
int getMmapFd() { return mMmapFd; }
|
|
|
|
int getDictBufAdjust() { return mDictBufAdjust; }
|
2009-03-13 22:11:42 +00:00
|
|
|
~Dictionary();
|
2009-03-31 17:51:17 +00:00
|
|
|
|
2010-12-02 05:53:24 +00:00
|
|
|
// public static utility methods
|
|
|
|
// static inline methods should be defined in the header file
|
2010-12-02 09:11:54 +00:00
|
|
|
static int wideStrLen(unsigned short *str);
|
2011-06-17 03:45:17 +00:00
|
|
|
|
2012-01-06 03:24:38 +00:00
|
|
|
private:
|
2011-01-07 06:01:51 +00:00
|
|
|
const unsigned char *mDict;
|
|
|
|
|
|
|
|
// Used only for the mmap version of dictionary loading, but we use these as dummy variables
|
|
|
|
// also for the malloc version.
|
|
|
|
const int mDictSize;
|
|
|
|
const int mMmapFd;
|
|
|
|
const int mDictBufAdjust;
|
|
|
|
|
2010-12-01 12:22:15 +00:00
|
|
|
UnigramDictionary *mUnigramDictionary;
|
2011-01-07 06:01:51 +00:00
|
|
|
BigramDictionary *mBigramDictionary;
|
2011-12-15 07:49:12 +00:00
|
|
|
WordsPriorityQueuePool *mWordsPriorityQueuePool;
|
2011-12-14 06:04:58 +00:00
|
|
|
Correction *mCorrection;
|
2009-03-13 22:11:42 +00:00
|
|
|
};
|
|
|
|
|
2010-12-02 05:53:24 +00:00
|
|
|
// public static utility methods
|
|
|
|
// static inline methods should be defined in the header file
|
2010-12-02 09:11:54 +00:00
|
|
|
inline int Dictionary::wideStrLen(unsigned short *str) {
|
|
|
|
if (!str) return 0;
|
|
|
|
unsigned short *end = str;
|
|
|
|
while (*end)
|
|
|
|
end++;
|
|
|
|
return end - str;
|
|
|
|
}
|
2011-06-18 04:09:55 +00:00
|
|
|
} // namespace latinime
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
#endif // LATINIME_DICTIONARY_H
|