blob: 259276cea7fb8cc0067482a18792798c0b458392 [file] [log] [blame]
satok30088252010-12-01 21:22:15 +09001/*
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
satoke808e432010-12-02 14:53:24 +090020#include "defines.h"
21
satok30088252010-12-01 21:22:15 +090022namespace latinime {
23
satok30088252010-12-01 21:22:15 +090024class UnigramDictionary {
25public:
satoke808e432010-12-02 14:53:24 +090026 UnigramDictionary(const unsigned char *dict, int typedLetterMultipler, int fullWordMultiplier,
satok18c28f42010-12-02 18:11:54 +090027 int maxWordLength, int maxWords, int maxAlternatives, const bool isLatestDictVersion);
satok30088252010-12-01 21:22:15 +090028 int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
29 int *nextLetters, int nextLettersSize);
satok30088252010-12-01 21:22:15 +090030 ~UnigramDictionary();
31
32private:
33 void initSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies);
satok18c28f42010-12-02 18:11:54 +090034 int getSuggestionCandidates(int inputLength, int skipPos, int *nextLetters,
35 int nextLettersSize);
satok30088252010-12-01 21:22:15 +090036 void getVersionNumber();
37 bool checkIfDictVersionIsLatest();
38 int getAddress(int *pos);
satok30088252010-12-01 21:22:15 +090039 int getFreq(int *pos);
satok30088252010-12-01 21:22:15 +090040 int wideStrLen(unsigned short *str);
41
42 bool sameAsTyped(unsigned short *word, int length);
satok30088252010-12-01 21:22:15 +090043 bool addWord(unsigned short *word, int length, int frequency);
satok30088252010-12-01 21:22:15 +090044 unsigned short toLowerCase(unsigned short c);
satok715514d2010-12-02 20:19:59 +090045 void getWordsRec(int pos, int depth, int maxDepth, bool completion, int snr,
satok30088252010-12-01 21:22:15 +090046 int inputIndex, int diffs, int skipPos, int *nextLetters, int nextLettersSize);
47 void registerNextLetter(unsigned short c, int *nextLetters, int nextLettersSize);
satok30088252010-12-01 21:22:15 +090048
satok715514d2010-12-02 20:19:59 +090049 void onTerminalWhenUserTypedLengthIsGreaterThanInputLength(unsigned short *word,
50 const int mInputLength, const int depth, const int snr, int *nextLetters,
51 const int nextLettersSize, const int skipPos, const int freq);
52
53 void onTerminalWhenUserTypedLengthIsSameAsInputLength(unsigned short *word, const int depth,
54 const int snr, const int skipPos, const int freq, const int addedWeight);
55
satok28bd03b2010-12-03 16:39:16 +090056 bool needsToSkipCurrentNode(const unsigned short c,
57 const unsigned short userTypedChar, const int skipPos, const int depth);
58
59 int getMatchedProximityId(const int *currentChars, const unsigned short lowerC,
60 const unsigned short c, const int skipPos);
61
satoke808e432010-12-02 14:53:24 +090062 const unsigned char *DICT;
satok30088252010-12-01 21:22:15 +090063 const int MAX_WORDS;
64 const int MAX_WORD_LENGTH;
65 const int MAX_ALTERNATIVES;
satoke808e432010-12-02 14:53:24 +090066 const bool IS_LATEST_DICT_VERSION;
satok18c28f42010-12-02 18:11:54 +090067 const int TYPED_LETTER_MULTIPLIER;
68 const int FULL_WORD_MULTIPLIER;
satok30088252010-12-01 21:22:15 +090069
satok30088252010-12-01 21:22:15 +090070 int *mFrequencies;
satok30088252010-12-01 21:22:15 +090071 unsigned short *mOutputChars;
satok30088252010-12-01 21:22:15 +090072 int *mInputCodes;
73 int mInputLength;
satok715514d2010-12-02 20:19:59 +090074 // MAX_WORD_LENGTH_INTERNAL must be bigger than MAX_WORD_LENGTH
75 unsigned short mWord[MAX_WORD_LENGTH_INTERNAL];
satok30088252010-12-01 21:22:15 +090076 int mMaxEditDistance;
satok30088252010-12-01 21:22:15 +090077};
78
79// ----------------------------------------------------------------------------
80
81}; // namespace latinime
82
83#endif // LATINIME_UNIGRAM_DICTIONARY_H