diff options
Diffstat (limited to 'native/src/dictionary.h')
-rw-r--r-- | native/src/dictionary.h | 73 |
1 files changed, 20 insertions, 53 deletions
diff --git a/native/src/dictionary.h b/native/src/dictionary.h index 2dac3b2c4..4c1f8837c 100644 --- a/native/src/dictionary.h +++ b/native/src/dictionary.h @@ -17,6 +17,9 @@ #ifndef LATINIME_DICTIONARY_H #define LATINIME_DICTIONARY_H +#include "bigram_dictionary.h" +#include "unigram_dictionary.h" + namespace latinime { // 22-bit address = ~4MB dictionary size limit, which on average would be about 200k-300k words @@ -35,68 +38,32 @@ namespace latinime { class Dictionary { public: - Dictionary(void *dict, int typedLetterMultipler, int fullWordMultiplier); + Dictionary(void *dict, int typedLetterMultipler, int fullWordMultiplier, int maxWordLength, + int maxWords, int maxAlternatives); int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies, - int maxWordLength, int maxWords, int maxAlternatives, int skipPos, - int *nextLetters, int nextLettersSize); + int *nextLetters, int nextLettersSize) { + return mUnigramDictionary->getSuggestions(codes, codesSize, outWords, frequencies, + nextLetters, nextLettersSize); + } + + // TODO: Call mBigramDictionary instead of mUnigramDictionary int getBigrams(unsigned short *word, int length, int *codes, int codesSize, unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams, - int maxAlternatives); - bool isValidWord(unsigned short *word, int length); + int maxAlternatives) { + return mUnigramDictionary->getBigrams(word, length, codes, codesSize, outWords, frequencies, + maxWordLength, maxBigrams, maxAlternatives); + } + bool isValidWord(unsigned short *word, int length) { + return mUnigramDictionary->isValidWord(word, length); + } void setAsset(void *asset) { mAsset = asset; } void *getAsset() { return mAsset; } ~Dictionary(); private: - void initSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies, - int maxWordLength, int maxWords, int maxAlternatives); - int getSuggestionCandidates(int inputLength, int maxWords, int skipPos, int *nextLetters, - int nextLettersSize); - void getVersionNumber(); - bool checkIfDictVersionIsLatest(); - int getAddress(int *pos); - 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; } - bool getTerminal(int *pos) { return (mDict[*pos] & FLAG_TERMINAL_MASK) > 0; } - int getCount(int *pos) { return mDict[(*pos)++] & 0xFF; } - unsigned short getChar(int *pos); - int wideStrLen(unsigned short *str); - - bool sameAsTyped(unsigned short *word, int length); - bool checkFirstCharacter(unsigned short *word); - bool addWord(unsigned short *word, int length, int frequency); - bool addWordBigram(unsigned short *word, int length, int frequency); - unsigned short toLowerCase(unsigned short c); - void getWordsRec(int pos, int depth, int maxDepth, bool completion, int frequency, - int inputIndex, int diffs, int skipPos, int *nextLetters, int nextLettersSize); - int isValidWordRec(int pos, unsigned short *word, int offset, int length); - void registerNextLetter(unsigned short c, int *nextLetters, int nextLettersSize); - - unsigned char *mDict; void *mAsset; - - int *mFrequencies; - int *mBigramFreq; - int mMaxWords; - int mMaxBigrams; - int mMaxWordLength; - unsigned short *mOutputChars; - unsigned short *mBigramChars; - int *mInputCodes; - int mInputLength; - int mMaxAlternatives; - unsigned short mWord[128]; - int mMaxEditDistance; - - int mFullWordMultiplier; - int mTypedLetterMultiplier; - int mVersion; - int mBigram; + BigramDictionary *mBigramDictionary; + UnigramDictionary *mUnigramDictionary; }; // ---------------------------------------------------------------------------- |