satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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_UNIGRAM_DICTIONARY_H |
| 18 | #define LATINIME_UNIGRAM_DICTIONARY_H |
| 19 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 20 | #include "defines.h" |
| 21 | |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 22 | namespace latinime { |
| 23 | |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 24 | class UnigramDictionary { |
| 25 | public: |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 26 | UnigramDictionary(const unsigned char *dict, int typedLetterMultipler, int fullWordMultiplier, |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame^] | 27 | int maxWordLength, int maxWords, int maxAlternatives, const bool isLatestDictVersion); |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 28 | int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies, |
| 29 | int *nextLetters, int nextLettersSize); |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 30 | ~UnigramDictionary(); |
| 31 | |
| 32 | private: |
| 33 | void initSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies); |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame^] | 34 | int getSuggestionCandidates(int inputLength, int skipPos, int *nextLetters, |
| 35 | int nextLettersSize); |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 36 | void getVersionNumber(); |
| 37 | bool checkIfDictVersionIsLatest(); |
| 38 | int getAddress(int *pos); |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 39 | int getFreq(int *pos); |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 40 | int wideStrLen(unsigned short *str); |
| 41 | |
| 42 | bool sameAsTyped(unsigned short *word, int length); |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 43 | bool addWord(unsigned short *word, int length, int frequency); |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 44 | unsigned short toLowerCase(unsigned short c); |
| 45 | void getWordsRec(int pos, int depth, int maxDepth, bool completion, int frequency, |
| 46 | int inputIndex, int diffs, int skipPos, int *nextLetters, int nextLettersSize); |
| 47 | void registerNextLetter(unsigned short c, int *nextLetters, int nextLettersSize); |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 48 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 49 | const unsigned char *DICT; |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 50 | const int MAX_WORDS; |
| 51 | const int MAX_WORD_LENGTH; |
| 52 | const int MAX_ALTERNATIVES; |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 53 | const bool IS_LATEST_DICT_VERSION; |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame^] | 54 | const int TYPED_LETTER_MULTIPLIER; |
| 55 | const int FULL_WORD_MULTIPLIER; |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 56 | |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 57 | int *mFrequencies; |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 58 | unsigned short *mOutputChars; |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 59 | int *mInputCodes; |
| 60 | int mInputLength; |
| 61 | unsigned short mWord[128]; |
| 62 | int mMaxEditDistance; |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | // ---------------------------------------------------------------------------- |
| 66 | |
| 67 | }; // namespace latinime |
| 68 | |
| 69 | #endif // LATINIME_UNIGRAM_DICTIONARY_H |