aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src
diff options
context:
space:
mode:
Diffstat (limited to 'native/jni/src')
-rw-r--r--native/jni/src/bigram_dictionary.cpp6
-rw-r--r--native/jni/src/bigram_dictionary.h5
-rw-r--r--native/jni/src/binary_format.h61
-rw-r--r--native/jni/src/dictionary.cpp10
-rw-r--r--native/jni/src/dictionary.h7
-rw-r--r--native/jni/src/terminal_attributes.h20
-rw-r--r--native/jni/src/unigram_dictionary.cpp51
-rw-r--r--native/jni/src/unigram_dictionary.h27
8 files changed, 104 insertions, 83 deletions
diff --git a/native/jni/src/bigram_dictionary.cpp b/native/jni/src/bigram_dictionary.cpp
index f7a3d3e60..926a0d44e 100644
--- a/native/jni/src/bigram_dictionary.cpp
+++ b/native/jni/src/bigram_dictionary.cpp
@@ -26,11 +26,8 @@
namespace latinime {
BigramDictionary::BigramDictionary(const unsigned char *dict, int maxWordLength,
- const bool isLatestDictVersion, const bool hasBigram,
Dictionary *parentDictionary)
- : DICT(dict), MAX_WORD_LENGTH(maxWordLength),
- IS_LATEST_DICT_VERSION(isLatestDictVersion),
- HAS_BIGRAM(hasBigram), mParentDictionary(parentDictionary) {
+ : DICT(dict), MAX_WORD_LENGTH(maxWordLength), mParentDictionary(parentDictionary) {
if (DEBUG_DICT) {
AKLOGI("BigramDictionary - constructor");
AKLOGI("Has Bigram : %d", hasBigram);
@@ -123,6 +120,7 @@ int BigramDictionary::getBigrams(unsigned short *prevWord, int prevWordLength, i
}
pos = BinaryFormat::skipChildrenPosition(flags, pos);
pos = BinaryFormat::skipFrequency(flags, pos);
+ pos = BinaryFormat::skipShortcuts(root, flags, pos);
int bigramFlags;
int bigramCount = 0;
do {
diff --git a/native/jni/src/bigram_dictionary.h b/native/jni/src/bigram_dictionary.h
index 8132fbc59..af89e3255 100644
--- a/native/jni/src/bigram_dictionary.h
+++ b/native/jni/src/bigram_dictionary.h
@@ -22,8 +22,7 @@ namespace latinime {
class Dictionary;
class BigramDictionary {
public:
- BigramDictionary(const unsigned char *dict, int maxWordLength,
- const bool isLatestDictVersion, const bool hasBigram, Dictionary *parentDictionary);
+ BigramDictionary(const unsigned char *dict, int maxWordLength, Dictionary *parentDictionary);
int getBigrams(unsigned short *word, int length, int *codes, int codesSize,
unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams);
~BigramDictionary();
@@ -40,8 +39,6 @@ class BigramDictionary {
const int MAX_WORD_LENGTH;
// TODO: Re-implement proximity correction for bigram correction
static const int MAX_ALTERNATIVES = 1;
- const bool IS_LATEST_DICT_VERSION;
- const bool HAS_BIGRAM;
Dictionary *mParentDictionary;
int *mBigramFreq;
diff --git a/native/jni/src/binary_format.h b/native/jni/src/binary_format.h
index ab033ad90..f59302460 100644
--- a/native/jni/src/binary_format.h
+++ b/native/jni/src/binary_format.h
@@ -40,16 +40,21 @@ class BinaryFormat {
// implementations. On this occasion, we made the magic number 32 bits long.
const static uint32_t FORMAT_VERSION_2_MAGIC_NUMBER = 0x9BC13AFE;
+ const static int CHARACTER_ARRAY_TERMINATOR_SIZE = 1;
+ const static int SHORTCUT_LIST_SIZE_SIZE = 2;
+
static int detectFormat(const uint8_t* const dict);
static unsigned int getHeaderSize(const uint8_t* const dict);
+ static unsigned int getFlags(const uint8_t* const dict);
static int getGroupCountAndForwardPointer(const uint8_t* const dict, int* pos);
static uint8_t getFlagsAndForwardPointer(const uint8_t* const dict, int* pos);
static int32_t getCharCodeAndForwardPointer(const uint8_t* const dict, int* pos);
static int readFrequencyWithoutMovingPointer(const uint8_t* const dict, const int pos);
static int skipOtherCharacters(const uint8_t* const dict, const int pos);
- static int skipAttributes(const uint8_t* const dict, const int pos);
static int skipChildrenPosition(const uint8_t flags, const int pos);
static int skipFrequency(const uint8_t flags, const int pos);
+ static int skipShortcuts(const uint8_t* const dict, const uint8_t flags, const int pos);
+ static int skipBigrams(const uint8_t* const dict, const uint8_t flags, const int pos);
static int skipAllAttributes(const uint8_t* const dict, const uint8_t flags, const int pos);
static int skipChildrenPosAndAttributes(const uint8_t* const dict, const uint8_t flags,
const int pos);
@@ -61,6 +66,15 @@ class BinaryFormat {
const int length);
static int getWordAtAddress(const uint8_t* const root, const int address, const int maxDepth,
uint16_t* outWord);
+
+ // Flags for special processing
+ // Those *must* match the flags in makedict (BinaryDictInputOutput#*_PROCESSING_FLAG) or
+ // something very bad (like, the apocalypse) will happen. Please update both at the same time.
+ enum {
+ REQUIRES_GERMAN_UMLAUT_PROCESSING = 0x1,
+ REQUIRES_FRENCH_LIGATURES_PROCESSING = 0x4
+ };
+ const static unsigned int NO_FLAGS = 0;
};
inline int BinaryFormat::detectFormat(const uint8_t* const dict) {
@@ -77,7 +91,7 @@ inline int BinaryFormat::detectFormat(const uint8_t* const dict) {
// Format 2 header is as follows:
// Magic number (4 bytes) 0x9B 0xC1 0x3A 0xFE
// Version number (2 bytes) 0x00 0x02
- // Options (2 bytes) must be 0x00 0x00
+ // Options (2 bytes)
// Header size (4 bytes) : integer, big endian
return (dict[4] << 8) + dict[5];
default:
@@ -85,6 +99,15 @@ inline int BinaryFormat::detectFormat(const uint8_t* const dict) {
}
}
+inline unsigned int BinaryFormat::getFlags(const uint8_t* const dict) {
+ switch (detectFormat(dict)) {
+ case 1:
+ return NO_FLAGS;
+ default:
+ return (dict[6] << 8) + dict[7];
+ }
+}
+
inline unsigned int BinaryFormat::getHeaderSize(const uint8_t* const dict) {
switch (detectFormat(dict)) {
case 1:
@@ -157,12 +180,12 @@ static inline int attributeAddressSize(const uint8_t flags) {
*/
}
-inline int BinaryFormat::skipAttributes(const uint8_t* const dict, const int pos) {
+static inline int skipExistingBigrams(const uint8_t* const dict, const int pos) {
int currentPos = pos;
- uint8_t flags = getFlagsAndForwardPointer(dict, &currentPos);
+ uint8_t flags = BinaryFormat::getFlagsAndForwardPointer(dict, &currentPos);
while (flags & UnigramDictionary::FLAG_ATTRIBUTE_HAS_NEXT) {
currentPos += attributeAddressSize(flags);
- flags = getFlagsAndForwardPointer(dict, &currentPos);
+ flags = BinaryFormat::getFlagsAndForwardPointer(dict, &currentPos);
}
currentPos += attributeAddressSize(flags);
return currentPos;
@@ -174,6 +197,10 @@ static inline int childrenAddressSize(const uint8_t flags) {
/* See the note in attributeAddressSize. The same applies here */
}
+static inline int shortcutByteSize(const uint8_t* const dict, const int pos) {
+ return ((int)(dict[pos] << 8)) + (dict[pos + 1]);
+}
+
inline int BinaryFormat::skipChildrenPosition(const uint8_t flags, const int pos) {
return pos + childrenAddressSize(flags);
}
@@ -182,16 +209,30 @@ inline int BinaryFormat::skipFrequency(const uint8_t flags, const int pos) {
return UnigramDictionary::FLAG_IS_TERMINAL & flags ? pos + 1 : pos;
}
-inline int BinaryFormat::skipAllAttributes(const uint8_t* const dict, const uint8_t flags,
+inline int BinaryFormat::skipShortcuts(const uint8_t* const dict, const uint8_t flags,
const int pos) {
- // This function skips all attributes: shortcuts and bigrams.
- int newPos = pos;
if (UnigramDictionary::FLAG_HAS_SHORTCUT_TARGETS & flags) {
- newPos = skipAttributes(dict, newPos);
+ return pos + shortcutByteSize(dict, pos);
+ } else {
+ return pos;
}
+}
+
+inline int BinaryFormat::skipBigrams(const uint8_t* const dict, const uint8_t flags,
+ const int pos) {
if (UnigramDictionary::FLAG_HAS_BIGRAMS & flags) {
- newPos = skipAttributes(dict, newPos);
+ return skipExistingBigrams(dict, pos);
+ } else {
+ return pos;
}
+}
+
+inline int BinaryFormat::skipAllAttributes(const uint8_t* const dict, const uint8_t flags,
+ const int pos) {
+ // This function skips all attributes: shortcuts and bigrams.
+ int newPos = pos;
+ newPos = skipShortcuts(dict, flags, newPos);
+ newPos = skipBigrams(dict, flags, newPos);
return newPos;
}
diff --git a/native/jni/src/dictionary.cpp b/native/jni/src/dictionary.cpp
index 981a983ee..90ec207f0 100644
--- a/native/jni/src/dictionary.cpp
+++ b/native/jni/src/dictionary.cpp
@@ -29,9 +29,7 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
int typedLetterMultiplier, int fullWordMultiplier,
int maxWordLength, int maxWords)
: mDict((unsigned char*) dict), mDictSize(dictSize),
- mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust),
- // Checks whether it has the latest dictionary or the old dictionary
- IS_LATEST_DICT_VERSION((((unsigned char*) dict)[0] & 0xFF) >= DICTIONARY_VERSION_MIN) {
+ mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust) {
if (DEBUG_DICT) {
if (MAX_WORD_LENGTH_INTERNAL < maxWordLength) {
AKLOGI("Max word length (%d) is greater than %d",
@@ -43,10 +41,10 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
mWordsPriorityQueuePool = new WordsPriorityQueuePool(
maxWords, SUB_QUEUE_MAX_WORDS, maxWordLength);
const unsigned int headerSize = BinaryFormat::getHeaderSize(mDict);
+ const unsigned int options = BinaryFormat::getFlags(mDict);
mUnigramDictionary = new UnigramDictionary(mDict + headerSize, typedLetterMultiplier,
- fullWordMultiplier, maxWordLength, maxWords, IS_LATEST_DICT_VERSION);
- mBigramDictionary = new BigramDictionary(mDict + headerSize, maxWordLength,
- IS_LATEST_DICT_VERSION, true /* hasBigram */, this);
+ fullWordMultiplier, maxWordLength, maxWords, options);
+ mBigramDictionary = new BigramDictionary(mDict + headerSize, maxWordLength, this);
}
Dictionary::~Dictionary() {
diff --git a/native/jni/src/dictionary.h b/native/jni/src/dictionary.h
index 139d3f0d7..5638bbf8c 100644
--- a/native/jni/src/dictionary.h
+++ b/native/jni/src/dictionary.h
@@ -33,13 +33,13 @@ class Dictionary {
int fullWordMultiplier, int maxWordLength, int maxWords);
int getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates,
- int *codes, int codesSize, int flags, unsigned short *outWords, int *frequencies) {
+ int *codes, int codesSize, bool useFullEditDistance, unsigned short *outWords,
+ int *frequencies) {
return mUnigramDictionary->getSuggestions(proximityInfo, mWordsPriorityQueuePool,
mCorrection, xcoordinates, ycoordinates, codes,
- codesSize, flags, outWords, frequencies);
+ codesSize, useFullEditDistance, outWords, frequencies);
}
- // 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) {
return mBigramDictionary->getBigrams(word, length, codes, codesSize, outWords, frequencies,
@@ -68,7 +68,6 @@ class Dictionary {
const int mMmapFd;
const int mDictBufAdjust;
- const bool IS_LATEST_DICT_VERSION;
UnigramDictionary *mUnigramDictionary;
BigramDictionary *mBigramDictionary;
WordsPriorityQueuePool *mWordsPriorityQueuePool;
diff --git a/native/jni/src/terminal_attributes.h b/native/jni/src/terminal_attributes.h
index 1f9815936..9a803cca1 100644
--- a/native/jni/src/terminal_attributes.h
+++ b/native/jni/src/terminal_attributes.h
@@ -45,13 +45,19 @@ class TerminalAttributes {
// Gets the shortcut target itself as a uint16_t string. For parameters and return value
// see BinaryFormat::getWordAtAddress.
+ // TODO: make the output an uint32_t* to handle the whole unicode range.
inline int getNextShortcutTarget(const int maxDepth, uint16_t* outWord) {
const int shortcutFlags = BinaryFormat::getFlagsAndForwardPointer(mDict, &mPos);
mHasNextShortcutTarget =
0 != (shortcutFlags & UnigramDictionary::FLAG_ATTRIBUTE_HAS_NEXT);
- int shortcutAddress =
- BinaryFormat::getAttributeAddressAndForwardPointer(mDict, shortcutFlags, &mPos);
- return BinaryFormat::getWordAtAddress(mDict, shortcutAddress, maxDepth, outWord);
+ unsigned int i;
+ for (i = 0; i < MAX_WORD_LENGTH_INTERNAL; ++i) {
+ const int charCode = BinaryFormat::getCharCodeAndForwardPointer(mDict, &mPos);
+ if (NOT_A_CHARACTER == charCode) break;
+ outWord[i] = (uint16_t)charCode;
+ }
+ mPos += BinaryFormat::CHARACTER_ARRAY_TERMINATOR_SIZE;
+ return i;
}
};
@@ -65,12 +71,10 @@ class TerminalAttributes {
mDict(dict), mFlags(flags), mStartPos(pos) {
}
- inline bool isShortcutOnly() const {
- return 0 != (mFlags & UnigramDictionary::FLAG_IS_SHORTCUT_ONLY);
- }
-
inline ShortcutIterator getShortcutIterator() const {
- return ShortcutIterator(mDict, mStartPos, mFlags);
+ // The size of the shortcuts is stored here so that the whole shortcut chunk can be
+ // skipped quickly, so we ignore it.
+ return ShortcutIterator(mDict, mStartPos + BinaryFormat::SHORTCUT_LIST_SIZE_SIZE, mFlags);
}
};
} // namespace latinime
diff --git a/native/jni/src/unigram_dictionary.cpp b/native/jni/src/unigram_dictionary.cpp
index ed4c066f3..ab8570e6f 100644
--- a/native/jni/src/unigram_dictionary.cpp
+++ b/native/jni/src/unigram_dictionary.cpp
@@ -40,15 +40,13 @@ const UnigramDictionary::digraph_t UnigramDictionary::FRENCH_LIGATURES_DIGRAPHS[
// TODO: check the header
UnigramDictionary::UnigramDictionary(const uint8_t* const streamStart, int typedLetterMultiplier,
- int fullWordMultiplier, int maxWordLength, int maxWords,
- const bool isLatestDictVersion)
+ int fullWordMultiplier, int maxWordLength, int maxWords, const unsigned int flags)
: DICT_ROOT(streamStart), MAX_WORD_LENGTH(maxWordLength), MAX_WORDS(maxWords),
- IS_LATEST_DICT_VERSION(isLatestDictVersion),
TYPED_LETTER_MULTIPLIER(typedLetterMultiplier), FULL_WORD_MULTIPLIER(fullWordMultiplier),
// TODO : remove this variable.
ROOT_POS(0),
BYTES_IN_ONE_CHAR(sizeof(int)),
- MAX_DIGRAPH_SEARCH_DEPTH(DEFAULT_MAX_DIGRAPH_SEARCH_DEPTH) {
+ MAX_DIGRAPH_SEARCH_DEPTH(DEFAULT_MAX_DIGRAPH_SEARCH_DEPTH), FLAGS(flags) {
if (DEBUG_DICT) {
AKLOGI("UnigramDictionary - constructor");
}
@@ -100,7 +98,7 @@ int UnigramDictionary::getDigraphReplacement(const int *codes, const int i, cons
void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximityInfo,
const int *xcoordinates, const int *ycoordinates, const int *codesBuffer,
int *xCoordinatesBuffer, int *yCoordinatesBuffer,
- const int codesBufferSize, const int flags, const int *codesSrc,
+ const int codesBufferSize, const bool useFullEditDistance, const int *codesSrc,
const int codesRemain, const int currentDepth, int *codesDest, Correction *correction,
WordsPriorityQueuePool *queuePool,
const digraph_t* const digraphs, const unsigned int digraphsSize) {
@@ -128,8 +126,8 @@ void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximit
codesDest[(i - 1) * (BYTES_IN_ONE_CHAR / sizeof(codesDest[0]))] =
replacementCodePoint;
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates,
- codesBuffer, xCoordinatesBuffer, yCoordinatesBuffer, codesBufferSize, flags,
- codesSrc + i + 1, codesRemain - i - 1,
+ codesBuffer, xCoordinatesBuffer, yCoordinatesBuffer, codesBufferSize,
+ useFullEditDistance, codesSrc + i + 1, codesRemain - i - 1,
currentDepth + 1, codesDest + i, correction,
queuePool, digraphs, digraphsSize);
@@ -138,8 +136,8 @@ void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximit
// In our example, after "pru" in the buffer copy the "e", and continue on "fen"
memcpy(codesDest + i, codesSrc + i, BYTES_IN_ONE_CHAR);
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates,
- codesBuffer, xCoordinatesBuffer, yCoordinatesBuffer, codesBufferSize, flags,
- codesSrc + i, codesRemain - i, currentDepth + 1,
+ codesBuffer, xCoordinatesBuffer, yCoordinatesBuffer, codesBufferSize,
+ useFullEditDistance, codesSrc + i, codesRemain - i, currentDepth + 1,
codesDest + i, correction, queuePool,
digraphs, digraphsSize);
return;
@@ -162,39 +160,39 @@ void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximit
}
getWordSuggestions(proximityInfo, xCoordinatesBuffer, yCoordinatesBuffer, codesBuffer,
- startIndex + codesRemain, flags, correction,
+ startIndex + codesRemain, useFullEditDistance, correction,
queuePool);
}
int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo,
WordsPriorityQueuePool *queuePool, Correction *correction, const int *xcoordinates,
- const int *ycoordinates, const int *codes, const int codesSize, const int flags,
- unsigned short *outWords, int *frequencies) {
+ const int *ycoordinates, const int *codes, const int codesSize,
+ const bool useFullEditDistance, unsigned short *outWords, int *frequencies) {
queuePool->clearAll();
Correction* masterCorrection = correction;
- if (REQUIRES_GERMAN_UMLAUT_PROCESSING & flags)
+ if (BinaryFormat::REQUIRES_GERMAN_UMLAUT_PROCESSING & FLAGS)
{ // Incrementally tune the word and try all possibilities
int codesBuffer[getCodesBufferSize(codes, codesSize)];
int xCoordinatesBuffer[codesSize];
int yCoordinatesBuffer[codesSize];
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates, codesBuffer,
xCoordinatesBuffer, yCoordinatesBuffer,
- codesSize, flags, codes, codesSize, 0, codesBuffer, masterCorrection, queuePool,
- GERMAN_UMLAUT_DIGRAPHS,
+ codesSize, useFullEditDistance, codes, codesSize, 0, codesBuffer, masterCorrection,
+ queuePool, GERMAN_UMLAUT_DIGRAPHS,
sizeof(GERMAN_UMLAUT_DIGRAPHS) / sizeof(GERMAN_UMLAUT_DIGRAPHS[0]));
- } else if (REQUIRES_FRENCH_LIGATURES_PROCESSING & flags) {
+ } else if (BinaryFormat::REQUIRES_FRENCH_LIGATURES_PROCESSING & FLAGS) {
int codesBuffer[getCodesBufferSize(codes, codesSize)];
int xCoordinatesBuffer[codesSize];
int yCoordinatesBuffer[codesSize];
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates, codesBuffer,
xCoordinatesBuffer, yCoordinatesBuffer,
- codesSize, flags, codes, codesSize, 0, codesBuffer, masterCorrection, queuePool,
- FRENCH_LIGATURES_DIGRAPHS,
+ codesSize, useFullEditDistance, codes, codesSize, 0, codesBuffer, masterCorrection,
+ queuePool, FRENCH_LIGATURES_DIGRAPHS,
sizeof(FRENCH_LIGATURES_DIGRAPHS) / sizeof(FRENCH_LIGATURES_DIGRAPHS[0]));
} else { // Normal processing
- getWordSuggestions(proximityInfo, xcoordinates, ycoordinates, codes, codesSize, flags,
- masterCorrection, queuePool);
+ getWordSuggestions(proximityInfo, xcoordinates, ycoordinates, codes, codesSize,
+ useFullEditDistance, masterCorrection, queuePool);
}
PROF_START(20);
@@ -227,7 +225,7 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo,
void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
const int *xcoordinates, const int *ycoordinates, const int *codes,
- const int inputLength, const int flags, Correction *correction,
+ const int inputLength, const bool useFullEditDistance, Correction *correction,
WordsPriorityQueuePool *queuePool) {
PROF_OPEN;
@@ -235,7 +233,6 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
PROF_END(0);
PROF_START(1);
- const bool useFullEditDistance = USE_FULL_EDIT_DISTANCE & flags;
getOneWordSuggestions(proximityInfo, xcoordinates, ycoordinates, codes, useFullEditDistance,
inputLength, correction, queuePool);
PROF_END(1);
@@ -366,10 +363,9 @@ inline void UnigramDictionary::onTerminal(const int freq,
WordsPriorityQueue *masterQueue = queuePool->getMasterQueue();
const int finalFreq = correction->getFinalFreq(freq, &wordPointer, &wordLength);
if (finalFreq != NOT_A_FREQUENCY) {
- if (!terminalAttributes.isShortcutOnly()) {
- addWord(wordPointer, wordLength, finalFreq, masterQueue);
- }
+ addWord(wordPointer, wordLength, finalFreq, masterQueue);
+ const int shortcutFreq = finalFreq > 0 ? finalFreq - 1 : 0;
// Please note that the shortcut candidates will be added to the master queue only.
TerminalAttributes::ShortcutIterator iterator =
terminalAttributes.getShortcutIterator();
@@ -379,11 +375,12 @@ inline void UnigramDictionary::onTerminal(const int freq,
// We need to either modulate the frequency of each shortcut according
// to its own shortcut frequency or to make the queue
// so that the insert order is protected inside the queue for words
- // with the same score.
+ // with the same score. For the moment we use -1 to make sure the shortcut will
+ // never be in front of the word.
uint16_t shortcutTarget[MAX_WORD_LENGTH_INTERNAL];
const int shortcutTargetStringLength = iterator.getNextShortcutTarget(
MAX_WORD_LENGTH_INTERNAL, shortcutTarget);
- addWord(shortcutTarget, shortcutTargetStringLength, finalFreq, masterQueue);
+ addWord(shortcutTarget, shortcutTargetStringLength, shortcutFreq, masterQueue);
}
}
}
diff --git a/native/jni/src/unigram_dictionary.h b/native/jni/src/unigram_dictionary.h
index c8f15566c..4479cd94e 100644
--- a/native/jni/src/unigram_dictionary.h
+++ b/native/jni/src/unigram_dictionary.h
@@ -49,10 +49,6 @@ class UnigramDictionary {
static const int FLAG_HAS_SHORTCUT_TARGETS = 0x08;
// Flag for bigram presence
static const int FLAG_HAS_BIGRAMS = 0x04;
- // Flag for shortcut-only words. Some words are shortcut-only, which means they match when
- // the user types them but they don't pop in the suggestion strip, only the words they are
- // shortcuts for do.
- static const int FLAG_IS_SHORTCUT_ONLY = 0x02;
// Attribute (bigram/shortcut) related flags:
// Flag for presence of more attributes
@@ -74,26 +70,26 @@ class UnigramDictionary {
static const int MAX_ERRORS_FOR_TWO_WORDS = 1;
UnigramDictionary(const uint8_t* const streamStart, int typedLetterMultipler,
- int fullWordMultiplier, int maxWordLength, int maxWords,
- const bool isLatestDictVersion);
+ int fullWordMultiplier, int maxWordLength, int maxWords, const unsigned int flags);
bool isValidWord(const uint16_t* const inWord, const int length) const;
int getBigramPosition(int pos, unsigned short *word, int offset, int length) const;
int getSuggestions(ProximityInfo *proximityInfo, WordsPriorityQueuePool *queuePool,
Correction *correction, const int *xcoordinates,
- const int *ycoordinates, const int *codes, const int codesSize, const int flags,
- unsigned short *outWords, int *frequencies);
+ const int *ycoordinates, const int *codes, const int codesSize,
+ const bool useFullEditDistance, unsigned short *outWords, int *frequencies);
virtual ~UnigramDictionary();
private:
void getWordSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates,
const int *ycoordinates, const int *codes, const int inputLength,
- const int flags, Correction *correction, WordsPriorityQueuePool *queuePool);
+ const bool useFullEditDistance, Correction *correction,
+ WordsPriorityQueuePool *queuePool);
int getDigraphReplacement(const int *codes, const int i, const int codesSize,
const digraph_t* const digraphs, const unsigned int digraphsSize) const;
void getWordWithDigraphSuggestionsRec(ProximityInfo *proximityInfo,
const int *xcoordinates, const int* ycoordinates, const int *codesBuffer,
int *xCoordinatesBuffer, int *yCoordinatesBuffer,
- const int codesBufferSize, const int flags, const int* codesSrc,
+ const int codesBufferSize, const bool useFullEditDistance, const int* codesSrc,
const int codesRemain, const int currentDepth, int* codesDest, Correction *correction,
WordsPriorityQueuePool* queuePool, const digraph_t* const digraphs,
const unsigned int digraphsSize);
@@ -143,22 +139,13 @@ class UnigramDictionary {
const uint8_t* const DICT_ROOT;
const int MAX_WORD_LENGTH;
const int MAX_WORDS;
- const bool IS_LATEST_DICT_VERSION;
const int TYPED_LETTER_MULTIPLIER;
const int FULL_WORD_MULTIPLIER;
const int ROOT_POS;
const unsigned int BYTES_IN_ONE_CHAR;
const int MAX_DIGRAPH_SEARCH_DEPTH;
+ const int FLAGS;
- // Flags for special processing
- // Those *must* match the flags in BinaryDictionary.Flags.ALL_FLAGS in BinaryDictionary.java
- // or something very bad (like, the apocalypse) will happen.
- // Please update both at the same time.
- enum {
- REQUIRES_GERMAN_UMLAUT_PROCESSING = 0x1,
- USE_FULL_EDIT_DISTANCE = 0x2,
- REQUIRES_FRENCH_LIGATURES_PROCESSING = 0x4
- };
static const digraph_t GERMAN_UMLAUT_DIGRAPHS[];
static const digraph_t FRENCH_LIGATURES_DIGRAPHS[];