2009-03-13 22:11:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 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_DICTIONARY_H
|
|
|
|
#define LATINIME_DICTIONARY_H
|
|
|
|
|
|
|
|
namespace latinime {
|
|
|
|
|
2009-03-31 17:51:17 +00:00
|
|
|
// 22-bit address = ~4MB dictionary size limit, which on average would be about 200k-300k words
|
|
|
|
#define ADDRESS_MASK 0x3FFFFF
|
|
|
|
|
|
|
|
// The bit that decides if an address follows in the next 22 bits
|
|
|
|
#define FLAG_ADDRESS_MASK 0x40
|
|
|
|
// The bit that decides if this is a terminal node for a word. The node could still have children,
|
|
|
|
// if the word has other endings.
|
|
|
|
#define FLAG_TERMINAL_MASK 0x80
|
|
|
|
|
2010-07-01 03:28:04 +00:00
|
|
|
#define FLAG_BIGRAM_READ 0x80
|
|
|
|
#define FLAG_BIGRAM_CHILDEXIST 0x40
|
|
|
|
#define FLAG_BIGRAM_CONTINUED 0x80
|
|
|
|
#define FLAG_BIGRAM_FREQ 0x7F
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
class Dictionary {
|
|
|
|
public:
|
|
|
|
Dictionary(void *dict, int typedLetterMultipler, int fullWordMultiplier);
|
2009-03-31 17:51:17 +00:00
|
|
|
int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
|
2010-02-05 22:07:04 +00:00
|
|
|
int maxWordLength, int maxWords, int maxAlternatives, int skipPos,
|
|
|
|
int *nextLetters, int nextLettersSize);
|
2010-07-01 03:28:04 +00:00
|
|
|
int getBigrams(unsigned short *word, int length, unsigned short *outWords, int *frequencies,
|
|
|
|
int maxWordLength, int maxBigrams);
|
2009-03-13 22:11:42 +00:00
|
|
|
bool isValidWord(unsigned short *word, int length);
|
|
|
|
void setAsset(void *asset) { mAsset = asset; }
|
|
|
|
void *getAsset() { return mAsset; }
|
|
|
|
~Dictionary();
|
2009-03-31 17:51:17 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private:
|
|
|
|
|
2010-07-01 03:28:04 +00:00
|
|
|
void getVersionNumber();
|
|
|
|
bool checkIfDictVersionIsLatest();
|
2009-03-13 22:11:42 +00:00
|
|
|
int getAddress(int *pos);
|
2010-07-01 03:28:04 +00:00
|
|
|
int getBigramAddress(int *pos, bool advance);
|
|
|
|
int getFreq(int *pos);
|
|
|
|
int getBigramFreq(int *pos);
|
|
|
|
void searchForTerminalNode(int address, int frequency);
|
|
|
|
|
|
|
|
bool getFirstBitOfByte(int *pos) { return (mDict[*pos] & 0x80) > 0; }
|
|
|
|
bool getSecondBitOfByte(int *pos) { return (mDict[*pos] & 0x40) > 0; }
|
2009-03-31 17:51:17 +00:00
|
|
|
bool getTerminal(int *pos) { return (mDict[*pos] & FLAG_TERMINAL_MASK) > 0; }
|
2009-03-13 22:11:42 +00:00
|
|
|
int getCount(int *pos) { return mDict[(*pos)++] & 0xFF; }
|
|
|
|
unsigned short getChar(int *pos);
|
|
|
|
int wideStrLen(unsigned short *str);
|
2009-03-31 17:51:17 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
bool sameAsTyped(unsigned short *word, int length);
|
|
|
|
bool addWord(unsigned short *word, int length, int frequency);
|
2010-07-01 03:28:04 +00:00
|
|
|
bool addWordBigram(unsigned short *word, int length, int frequency);
|
2009-08-07 21:04:24 +00:00
|
|
|
unsigned short toLowerCase(unsigned short c);
|
2009-03-31 17:51:17 +00:00
|
|
|
void getWordsRec(int pos, int depth, int maxDepth, bool completion, int frequency,
|
2009-07-16 01:30:47 +00:00
|
|
|
int inputIndex, int diffs);
|
2010-07-01 03:28:04 +00:00
|
|
|
int isValidWordRec(int pos, unsigned short *word, int offset, int length);
|
2010-02-05 22:07:04 +00:00
|
|
|
void registerNextLetter(unsigned short c);
|
2009-03-13 22:11:42 +00:00
|
|
|
|
|
|
|
unsigned char *mDict;
|
|
|
|
void *mAsset;
|
2009-03-31 17:51:17 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
int *mFrequencies;
|
2010-07-01 03:28:04 +00:00
|
|
|
int *mBigramFreq;
|
2009-03-13 22:11:42 +00:00
|
|
|
int mMaxWords;
|
2010-07-01 03:28:04 +00:00
|
|
|
int mMaxBigrams;
|
2009-03-13 22:11:42 +00:00
|
|
|
int mMaxWordLength;
|
|
|
|
unsigned short *mOutputChars;
|
2010-07-01 03:28:04 +00:00
|
|
|
unsigned short *mBigramChars;
|
2009-03-13 22:11:42 +00:00
|
|
|
int *mInputCodes;
|
|
|
|
int mInputLength;
|
|
|
|
int mMaxAlternatives;
|
|
|
|
unsigned short mWord[128];
|
2009-06-04 19:20:45 +00:00
|
|
|
int mSkipPos;
|
2009-07-16 01:30:47 +00:00
|
|
|
int mMaxEditDistance;
|
2009-03-31 17:51:17 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
int mFullWordMultiplier;
|
|
|
|
int mTypedLetterMultiplier;
|
2010-02-05 22:07:04 +00:00
|
|
|
int *mNextLettersFrequencies;
|
|
|
|
int mNextLettersSize;
|
2010-07-01 03:28:04 +00:00
|
|
|
int mVersion;
|
|
|
|
int mBigram;
|
2009-03-13 22:11:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
}; // namespace latinime
|
|
|
|
|
|
|
|
#endif // LATINIME_DICTIONARY_H
|