blob: 8574e07365942a29c7d2d01191a10d8a7977d1e9 [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
20namespace latinime {
21
22class Dictionary {
23public:
24 Dictionary(void *dict, int typedLetterMultipler, int fullWordMultiplier);
25 int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
26 int maxWordLength, int maxWords, int maxAlternatives);
27 bool isValidWord(unsigned short *word, int length);
28 void setAsset(void *asset) { mAsset = asset; }
29 void *getAsset() { return mAsset; }
30 ~Dictionary();
31
32private:
33
34 int getAddress(int *pos);
35 bool getTerminal(int *pos) { return (mDict[*pos] & 0x80) > 0; }
36 int getFreq(int *pos) { return mDict[(*pos)++] & 0xFF; }
37 int getCount(int *pos) { return mDict[(*pos)++] & 0xFF; }
38 unsigned short getChar(int *pos);
39 int wideStrLen(unsigned short *str);
40
41 bool sameAsTyped(unsigned short *word, int length);
42 bool addWord(unsigned short *word, int length, int frequency);
43 unsigned short toLowerCase(unsigned short c, int depth);
44 void getWordsRec(int pos, int depth, int maxDepth, bool completion, int frequency,
45 int inputIndex);
46 bool isValidWordRec(int pos, unsigned short *word, int offset, int length);
47
48 unsigned char *mDict;
49 void *mAsset;
50
51 int *mFrequencies;
52 int mMaxWords;
53 int mMaxWordLength;
54 int mWords;
55 unsigned short *mOutputChars;
56 int *mInputCodes;
57 int mInputLength;
58 int mMaxAlternatives;
59 unsigned short mWord[128];
60
61 int mFullWordMultiplier;
62 int mTypedLetterMultiplier;
63};
64
65// ----------------------------------------------------------------------------
66
67}; // namespace latinime
68
69#endif // LATINIME_DICTIONARY_H