blob: 139d3f0d7860b0df3d6df4e156baf097441e9ec6 [file] [log] [blame]
The Android Open Source Project923bf412009-03-13 15:11:42 -07001/*
2 * Copyright (C) 2009 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_DICTIONARY_H
18#define LATINIME_DICTIONARY_H
19
satok30088252010-12-01 21:22:15 +090020#include "bigram_dictionary.h"
satokd24df432011-07-14 15:43:42 +090021#include "char_utils.h"
satok1147c7b2011-12-14 15:04:58 +090022#include "correction.h"
satoke808e432010-12-02 14:53:24 +090023#include "defines.h"
satok8fbd5522011-02-22 17:28:55 +090024#include "proximity_info.h"
satok30088252010-12-01 21:22:15 +090025#include "unigram_dictionary.h"
satoka7e5a5a2011-12-15 16:49:12 +090026#include "words_priority_queue_pool.h"
satok30088252010-12-01 21:22:15 +090027
The Android Open Source Project923bf412009-03-13 15:11:42 -070028namespace latinime {
29
30class Dictionary {
Ken Wakasae12e9b52012-01-06 12:24:38 +090031 public:
Ken Wakasae90b3332011-01-07 15:01:51 +090032 Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int typedLetterMultipler,
satok6ba8de22012-03-28 18:21:04 +090033 int fullWordMultiplier, int maxWordLength, int maxWords);
satok1147c7b2011-12-14 15:04:58 +090034
satok8fbd5522011-02-22 17:28:55 +090035 int getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates,
Jean Chalardc2bbc6a2011-02-25 17:56:53 +090036 int *codes, int codesSize, int flags, unsigned short *outWords, int *frequencies) {
satoka7e5a5a2011-12-15 16:49:12 +090037 return mUnigramDictionary->getSuggestions(proximityInfo, mWordsPriorityQueuePool,
satok1147c7b2011-12-14 15:04:58 +090038 mCorrection, xcoordinates, ycoordinates, codes,
Jean Chalardc2bbc6a2011-02-25 17:56:53 +090039 codesSize, flags, outWords, frequencies);
satok30088252010-12-01 21:22:15 +090040 }
41
42 // TODO: Call mBigramDictionary instead of mUnigramDictionary
Jae Yong Sung80aa14f2010-07-26 11:43:29 -070043 int getBigrams(unsigned short *word, int length, int *codes, int codesSize,
satok6ba8de22012-03-28 18:21:04 +090044 unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams) {
satok18c28f42010-12-02 18:11:54 +090045 return mBigramDictionary->getBigrams(word, length, codes, codesSize, outWords, frequencies,
satok6ba8de22012-03-28 18:21:04 +090046 maxWordLength, maxBigrams);
satok30088252010-12-01 21:22:15 +090047 }
satok8fbd5522011-02-22 17:28:55 +090048
satoke808e432010-12-02 14:53:24 +090049 bool isValidWord(unsigned short *word, int length);
Ken Wakasae90b3332011-01-07 15:01:51 +090050 void *getDict() { return (void *)mDict; }
51 int getDictSize() { return mDictSize; }
52 int getMmapFd() { return mMmapFd; }
53 int getDictBufAdjust() { return mDictBufAdjust; }
The Android Open Source Project923bf412009-03-13 15:11:42 -070054 ~Dictionary();
Amith Yamasanicc3e5c72009-03-31 10:51:17 -070055
satoke808e432010-12-02 14:53:24 +090056 // public static utility methods
57 // static inline methods should be defined in the header file
satok18c28f42010-12-02 18:11:54 +090058 static int wideStrLen(unsigned short *str);
Jean Chalard581335c2011-06-17 12:45:17 +090059
Ken Wakasae12e9b52012-01-06 12:24:38 +090060 private:
satoke808e432010-12-02 14:53:24 +090061 bool hasBigram();
62
Ken Wakasae90b3332011-01-07 15:01:51 +090063 const unsigned char *mDict;
64
65 // Used only for the mmap version of dictionary loading, but we use these as dummy variables
66 // also for the malloc version.
67 const int mDictSize;
68 const int mMmapFd;
69 const int mDictBufAdjust;
70
satoke808e432010-12-02 14:53:24 +090071 const bool IS_LATEST_DICT_VERSION;
satok30088252010-12-01 21:22:15 +090072 UnigramDictionary *mUnigramDictionary;
Ken Wakasae90b3332011-01-07 15:01:51 +090073 BigramDictionary *mBigramDictionary;
satoka7e5a5a2011-12-15 16:49:12 +090074 WordsPriorityQueuePool *mWordsPriorityQueuePool;
satok1147c7b2011-12-14 15:04:58 +090075 Correction *mCorrection;
The Android Open Source Project923bf412009-03-13 15:11:42 -070076};
77
satoke808e432010-12-02 14:53:24 +090078// public static utility methods
79// static inline methods should be defined in the header file
satok18c28f42010-12-02 18:11:54 +090080inline int Dictionary::wideStrLen(unsigned short *str) {
81 if (!str) return 0;
82 unsigned short *end = str;
83 while (*end)
84 end++;
85 return end - str;
86}
Ken Wakasace9e52a2011-06-18 13:09:55 +090087} // namespace latinime
88
The Android Open Source Project923bf412009-03-13 15:11:42 -070089#endif // LATINIME_DICTIONARY_H