2010-12-01 12:22:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LATINIME_UNIGRAM_DICTIONARY_H
|
|
|
|
#define LATINIME_UNIGRAM_DICTIONARY_H
|
|
|
|
|
2010-12-02 05:53:24 +00:00
|
|
|
#include "defines.h"
|
2010-12-01 12:22:15 +00:00
|
|
|
|
2010-12-02 05:53:24 +00:00
|
|
|
namespace latinime {
|
2010-12-01 12:22:15 +00:00
|
|
|
|
|
|
|
class UnigramDictionary {
|
|
|
|
public:
|
2010-12-02 05:53:24 +00:00
|
|
|
UnigramDictionary(const unsigned char *dict, int typedLetterMultipler, int fullWordMultiplier,
|
2010-12-02 09:11:54 +00:00
|
|
|
int maxWordLength, int maxWords, int maxAlternatives, const bool isLatestDictVersion);
|
2010-12-01 12:22:15 +00:00
|
|
|
int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
|
|
|
|
int *nextLetters, int nextLettersSize);
|
|
|
|
~UnigramDictionary();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void initSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies);
|
2010-12-02 09:11:54 +00:00
|
|
|
int getSuggestionCandidates(int inputLength, int skipPos, int *nextLetters,
|
|
|
|
int nextLettersSize);
|
2010-12-01 12:22:15 +00:00
|
|
|
void getVersionNumber();
|
|
|
|
bool checkIfDictVersionIsLatest();
|
|
|
|
int getAddress(int *pos);
|
|
|
|
int getFreq(int *pos);
|
|
|
|
int wideStrLen(unsigned short *str);
|
|
|
|
|
|
|
|
bool sameAsTyped(unsigned short *word, int length);
|
|
|
|
bool addWord(unsigned short *word, int length, int frequency);
|
|
|
|
unsigned short toLowerCase(unsigned short c);
|
2010-12-02 11:19:59 +00:00
|
|
|
void getWordsRec(int pos, int depth, int maxDepth, bool completion, int snr,
|
2010-12-01 12:22:15 +00:00
|
|
|
int inputIndex, int diffs, int skipPos, int *nextLetters, int nextLettersSize);
|
|
|
|
void registerNextLetter(unsigned short c, int *nextLetters, int nextLettersSize);
|
|
|
|
|
2010-12-02 11:19:59 +00:00
|
|
|
void onTerminalWhenUserTypedLengthIsGreaterThanInputLength(unsigned short *word,
|
|
|
|
const int mInputLength, const int depth, const int snr, int *nextLetters,
|
|
|
|
const int nextLettersSize, const int skipPos, const int freq);
|
|
|
|
|
|
|
|
void onTerminalWhenUserTypedLengthIsSameAsInputLength(unsigned short *word, const int depth,
|
|
|
|
const int snr, const int skipPos, const int freq, const int addedWeight);
|
|
|
|
|
2010-12-03 07:39:16 +00:00
|
|
|
bool needsToSkipCurrentNode(const unsigned short c,
|
|
|
|
const unsigned short userTypedChar, const int skipPos, const int depth);
|
|
|
|
|
|
|
|
int getMatchedProximityId(const int *currentChars, const unsigned short lowerC,
|
|
|
|
const unsigned short c, const int skipPos);
|
|
|
|
|
2010-12-02 05:53:24 +00:00
|
|
|
const unsigned char *DICT;
|
2010-12-01 12:22:15 +00:00
|
|
|
const int MAX_WORDS;
|
|
|
|
const int MAX_WORD_LENGTH;
|
|
|
|
const int MAX_ALTERNATIVES;
|
2010-12-02 05:53:24 +00:00
|
|
|
const bool IS_LATEST_DICT_VERSION;
|
2010-12-02 09:11:54 +00:00
|
|
|
const int TYPED_LETTER_MULTIPLIER;
|
|
|
|
const int FULL_WORD_MULTIPLIER;
|
2010-12-01 12:22:15 +00:00
|
|
|
|
|
|
|
int *mFrequencies;
|
|
|
|
unsigned short *mOutputChars;
|
|
|
|
int *mInputCodes;
|
|
|
|
int mInputLength;
|
2010-12-02 11:19:59 +00:00
|
|
|
// MAX_WORD_LENGTH_INTERNAL must be bigger than MAX_WORD_LENGTH
|
|
|
|
unsigned short mWord[MAX_WORD_LENGTH_INTERNAL];
|
2010-12-01 12:22:15 +00:00
|
|
|
int mMaxEditDistance;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
}; // namespace latinime
|
|
|
|
|
|
|
|
#endif // LATINIME_UNIGRAM_DICTIONARY_H
|