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 | |
| 20 | namespace latinime { |
| 21 | |
Amith Yamasani | cc3e5c7 | 2009-03-31 10:51:17 -0700 | [diff] [blame] | 22 | // 22-bit address = ~4MB dictionary size limit, which on average would be about 200k-300k words |
| 23 | #define ADDRESS_MASK 0x3FFFFF |
| 24 | |
| 25 | // The bit that decides if an address follows in the next 22 bits |
| 26 | #define FLAG_ADDRESS_MASK 0x40 |
| 27 | // The bit that decides if this is a terminal node for a word. The node could still have children, |
| 28 | // if the word has other endings. |
| 29 | #define FLAG_TERMINAL_MASK 0x80 |
| 30 | |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 31 | class Dictionary { |
| 32 | public: |
| 33 | Dictionary(void *dict, int typedLetterMultipler, int fullWordMultiplier); |
Amith Yamasani | cc3e5c7 | 2009-03-31 10:51:17 -0700 | [diff] [blame] | 34 | int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies, |
Amith Yamasani | c3df2d6 | 2009-06-04 12:20:45 -0700 | [diff] [blame] | 35 | int maxWordLength, int maxWords, int maxAlternatives, int skipPos); |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 36 | bool isValidWord(unsigned short *word, int length); |
| 37 | void setAsset(void *asset) { mAsset = asset; } |
| 38 | void *getAsset() { return mAsset; } |
| 39 | ~Dictionary(); |
Amith Yamasani | cc3e5c7 | 2009-03-31 10:51:17 -0700 | [diff] [blame] | 40 | |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 41 | private: |
| 42 | |
| 43 | int getAddress(int *pos); |
Amith Yamasani | cc3e5c7 | 2009-03-31 10:51:17 -0700 | [diff] [blame] | 44 | bool getTerminal(int *pos) { return (mDict[*pos] & FLAG_TERMINAL_MASK) > 0; } |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 45 | int getFreq(int *pos) { return mDict[(*pos)++] & 0xFF; } |
| 46 | int getCount(int *pos) { return mDict[(*pos)++] & 0xFF; } |
| 47 | unsigned short getChar(int *pos); |
| 48 | int wideStrLen(unsigned short *str); |
Amith Yamasani | cc3e5c7 | 2009-03-31 10:51:17 -0700 | [diff] [blame] | 49 | |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 50 | bool sameAsTyped(unsigned short *word, int length); |
| 51 | bool addWord(unsigned short *word, int length, int frequency); |
| 52 | unsigned short toLowerCase(unsigned short c, int depth); |
Amith Yamasani | cc3e5c7 | 2009-03-31 10:51:17 -0700 | [diff] [blame] | 53 | void getWordsRec(int pos, int depth, int maxDepth, bool completion, int frequency, |
Amith Yamasani | 322dc3d | 2009-07-15 18:30:47 -0700 | [diff] [blame^] | 54 | int inputIndex, int diffs); |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 55 | bool isValidWordRec(int pos, unsigned short *word, int offset, int length); |
| 56 | |
| 57 | unsigned char *mDict; |
| 58 | void *mAsset; |
Amith Yamasani | cc3e5c7 | 2009-03-31 10:51:17 -0700 | [diff] [blame] | 59 | |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 60 | int *mFrequencies; |
| 61 | int mMaxWords; |
| 62 | int mMaxWordLength; |
| 63 | int mWords; |
| 64 | unsigned short *mOutputChars; |
| 65 | int *mInputCodes; |
| 66 | int mInputLength; |
| 67 | int mMaxAlternatives; |
| 68 | unsigned short mWord[128]; |
Amith Yamasani | c3df2d6 | 2009-06-04 12:20:45 -0700 | [diff] [blame] | 69 | int mSkipPos; |
Amith Yamasani | 322dc3d | 2009-07-15 18:30:47 -0700 | [diff] [blame^] | 70 | int mMaxEditDistance; |
Amith Yamasani | cc3e5c7 | 2009-03-31 10:51:17 -0700 | [diff] [blame] | 71 | |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 72 | int mFullWordMultiplier; |
| 73 | int mTypedLetterMultiplier; |
| 74 | }; |
| 75 | |
| 76 | // ---------------------------------------------------------------------------- |
| 77 | |
| 78 | }; // namespace latinime |
| 79 | |
| 80 | #endif // LATINIME_DICTIONARY_H |