blob: 4c1f8837c0c6c70e2f3b84ec68292d8309851b6e [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"
21#include "unigram_dictionary.h"
22
The Android Open Source Project923bf412009-03-13 15:11:42 -070023namespace latinime {
24
Amith Yamasanicc3e5c72009-03-31 10:51:17 -070025// 22-bit address = ~4MB dictionary size limit, which on average would be about 200k-300k words
26#define ADDRESS_MASK 0x3FFFFF
27
28// The bit that decides if an address follows in the next 22 bits
29#define FLAG_ADDRESS_MASK 0x40
30// The bit that decides if this is a terminal node for a word. The node could still have children,
31// if the word has other endings.
32#define FLAG_TERMINAL_MASK 0x80
33
Jae Yong Sung937d5ad2010-06-30 20:28:04 -070034#define FLAG_BIGRAM_READ 0x80
35#define FLAG_BIGRAM_CHILDEXIST 0x40
36#define FLAG_BIGRAM_CONTINUED 0x80
37#define FLAG_BIGRAM_FREQ 0x7F
38
The Android Open Source Project923bf412009-03-13 15:11:42 -070039class Dictionary {
40public:
satok30088252010-12-01 21:22:15 +090041 Dictionary(void *dict, int typedLetterMultipler, int fullWordMultiplier, int maxWordLength,
42 int maxWords, int maxAlternatives);
Amith Yamasanicc3e5c72009-03-31 10:51:17 -070043 int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
satok30088252010-12-01 21:22:15 +090044 int *nextLetters, int nextLettersSize) {
45 return mUnigramDictionary->getSuggestions(codes, codesSize, outWords, frequencies,
46 nextLetters, nextLettersSize);
47 }
48
49 // TODO: Call mBigramDictionary instead of mUnigramDictionary
Jae Yong Sung80aa14f2010-07-26 11:43:29 -070050 int getBigrams(unsigned short *word, int length, int *codes, int codesSize,
51 unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams,
satok30088252010-12-01 21:22:15 +090052 int maxAlternatives) {
53 return mUnigramDictionary->getBigrams(word, length, codes, codesSize, outWords, frequencies,
54 maxWordLength, maxBigrams, maxAlternatives);
55 }
56 bool isValidWord(unsigned short *word, int length) {
57 return mUnigramDictionary->isValidWord(word, length);
58 }
The Android Open Source Project923bf412009-03-13 15:11:42 -070059 void setAsset(void *asset) { mAsset = asset; }
60 void *getAsset() { return mAsset; }
61 ~Dictionary();
Amith Yamasanicc3e5c72009-03-31 10:51:17 -070062
The Android Open Source Project923bf412009-03-13 15:11:42 -070063private:
The Android Open Source Project923bf412009-03-13 15:11:42 -070064 void *mAsset;
satok30088252010-12-01 21:22:15 +090065 BigramDictionary *mBigramDictionary;
66 UnigramDictionary *mUnigramDictionary;
The Android Open Source Project923bf412009-03-13 15:11:42 -070067};
68
69// ----------------------------------------------------------------------------
70
71}; // namespace latinime
72
73#endif // LATINIME_DICTIONARY_H