The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 20 | #include "bigram_dictionary.h" |
| 21 | #include "unigram_dictionary.h" |
| 22 | |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 23 | namespace latinime { |
| 24 | |
Amith Yamasani | cc3e5c7 | 2009-03-31 10:51:17 -0700 | [diff] [blame] | 25 | // 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 Sung | 937d5ad | 2010-06-30 20:28:04 -0700 | [diff] [blame] | 34 | #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 Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 39 | class Dictionary { |
| 40 | public: |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 41 | Dictionary(void *dict, int typedLetterMultipler, int fullWordMultiplier, int maxWordLength, |
| 42 | int maxWords, int maxAlternatives); |
Amith Yamasani | cc3e5c7 | 2009-03-31 10:51:17 -0700 | [diff] [blame] | 43 | int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies, |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 44 | 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 Sung | 80aa14f | 2010-07-26 11:43:29 -0700 | [diff] [blame] | 50 | int getBigrams(unsigned short *word, int length, int *codes, int codesSize, |
| 51 | unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams, |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 52 | 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 Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 59 | void setAsset(void *asset) { mAsset = asset; } |
| 60 | void *getAsset() { return mAsset; } |
| 61 | ~Dictionary(); |
Amith Yamasani | cc3e5c7 | 2009-03-31 10:51:17 -0700 | [diff] [blame] | 62 | |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 63 | private: |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 64 | void *mAsset; |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 65 | BigramDictionary *mBigramDictionary; |
| 66 | UnigramDictionary *mUnigramDictionary; |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | // ---------------------------------------------------------------------------- |
| 70 | |
| 71 | }; // namespace latinime |
| 72 | |
| 73 | #endif // LATINIME_DICTIONARY_H |