Merge "Fix reading uninitialized memory."
commit
3c648ab4da
|
@ -46,7 +46,7 @@ Dictionary::Dictionary(JNIEnv *env, const DictionaryStructureWithBufferPolicy::S
|
||||||
int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
|
int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
|
||||||
int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints,
|
int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints,
|
||||||
int inputSize, int *prevWordCodePoints, int prevWordLength, int commitPoint,
|
int inputSize, int *prevWordCodePoints, int prevWordLength, int commitPoint,
|
||||||
const SuggestOptions *const suggestOptions, int *outWords, int *frequencies,
|
const SuggestOptions *const suggestOptions, int *outWords, int *outputScores,
|
||||||
int *spaceIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const {
|
int *spaceIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const {
|
||||||
TimeKeeper::setCurrentTime();
|
TimeKeeper::setCurrentTime();
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -55,9 +55,9 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession
|
||||||
traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions);
|
traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions);
|
||||||
result = mGestureSuggest.get()->getSuggestions(proximityInfo, traverseSession, xcoordinates,
|
result = mGestureSuggest.get()->getSuggestions(proximityInfo, traverseSession, xcoordinates,
|
||||||
ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint, outWords,
|
ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint, outWords,
|
||||||
frequencies, spaceIndices, outputTypes, outputAutoCommitFirstWordConfidence);
|
outputScores, spaceIndices, outputTypes, outputAutoCommitFirstWordConfidence);
|
||||||
if (DEBUG_DICT) {
|
if (DEBUG_DICT) {
|
||||||
DUMP_RESULT(outWords, frequencies);
|
DUMP_RESULT(outWords, outputScores);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
|
@ -65,20 +65,20 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession
|
||||||
traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions);
|
traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions);
|
||||||
result = mTypingSuggest.get()->getSuggestions(proximityInfo, traverseSession, xcoordinates,
|
result = mTypingSuggest.get()->getSuggestions(proximityInfo, traverseSession, xcoordinates,
|
||||||
ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint,
|
ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint,
|
||||||
outWords, frequencies, spaceIndices, outputTypes,
|
outWords, outputScores, spaceIndices, outputTypes,
|
||||||
outputAutoCommitFirstWordConfidence);
|
outputAutoCommitFirstWordConfidence);
|
||||||
if (DEBUG_DICT) {
|
if (DEBUG_DICT) {
|
||||||
DUMP_RESULT(outWords, frequencies);
|
DUMP_RESULT(outWords, outputScores);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Dictionary::getBigrams(const int *word, int length, int *outWords, int *frequencies,
|
int Dictionary::getBigrams(const int *word, int length, int *outWords, int *outputScores,
|
||||||
int *outputTypes) const {
|
int *outputTypes) const {
|
||||||
TimeKeeper::setCurrentTime();
|
TimeKeeper::setCurrentTime();
|
||||||
if (length <= 0) return 0;
|
if (length <= 0) return 0;
|
||||||
return mBigramDictionary.get()->getPredictions(word, length, outWords, frequencies,
|
return mBigramDictionary.get()->getPredictions(word, length, outWords, outputScores,
|
||||||
outputTypes);
|
outputTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,10 +64,10 @@ class Dictionary {
|
||||||
int getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
|
int getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
|
||||||
int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints,
|
int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints,
|
||||||
int inputSize, int *prevWordCodePoints, int prevWordLength, int commitPoint,
|
int inputSize, int *prevWordCodePoints, int prevWordLength, int commitPoint,
|
||||||
const SuggestOptions *const suggestOptions, int *outWords, int *frequencies,
|
const SuggestOptions *const suggestOptions, int *outWords, int *outputScores,
|
||||||
int *spaceIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const;
|
int *spaceIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const;
|
||||||
|
|
||||||
int getBigrams(const int *word, int length, int *outWords, int *frequencies,
|
int getBigrams(const int *word, int length, int *outWords, int *outputScores,
|
||||||
int *outputTypes) const;
|
int *outputTypes) const;
|
||||||
|
|
||||||
int getProbability(const int *word, int length) const;
|
int getProbability(const int *word, int length) const;
|
||||||
|
|
|
@ -31,7 +31,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
|
||||||
// TODO: Split this method.
|
// TODO: Split this method.
|
||||||
/* static */ int SuggestionsOutputUtils::outputSuggestions(
|
/* static */ int SuggestionsOutputUtils::outputSuggestions(
|
||||||
const Scoring *const scoringPolicy, DicTraverseSession *traverseSession,
|
const Scoring *const scoringPolicy, DicTraverseSession *traverseSession,
|
||||||
int *frequencies, int *outputCodePoints, int *outputIndicesToPartialCommit,
|
int *outputScores, int *outputCodePoints, int *outputIndicesToPartialCommit,
|
||||||
int *outputTypes, int *outputAutoCommitFirstWordConfidence) {
|
int *outputTypes, int *outputAutoCommitFirstWordConfidence) {
|
||||||
#if DEBUG_EVALUATE_MOST_PROBABLE_STRING
|
#if DEBUG_EVALUATE_MOST_PROBABLE_STRING
|
||||||
const int terminalSize = 0;
|
const int terminalSize = 0;
|
||||||
|
@ -52,7 +52,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
|
||||||
// Insert most probable word at index == 0 as long as there is one terminal at least
|
// Insert most probable word at index == 0 as long as there is one terminal at least
|
||||||
const bool hasMostProbableString =
|
const bool hasMostProbableString =
|
||||||
scoringPolicy->getMostProbableString(traverseSession, terminalSize, languageWeight,
|
scoringPolicy->getMostProbableString(traverseSession, terminalSize, languageWeight,
|
||||||
&outputCodePoints[0], &outputTypes[0], &frequencies[0]);
|
&outputCodePoints[0], &outputTypes[0], &outputScores[0]);
|
||||||
if (hasMostProbableString) {
|
if (hasMostProbableString) {
|
||||||
outputIndicesToPartialCommit[outputWordIndex] = NOT_AN_INDEX;
|
outputIndicesToPartialCommit[outputWordIndex] = NOT_AN_INDEX;
|
||||||
++outputWordIndex;
|
++outputWordIndex;
|
||||||
|
@ -97,7 +97,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
|
||||||
const bool isExactMatch =
|
const bool isExactMatch =
|
||||||
ErrorTypeUtils::isExactMatch(terminalDicNode->getContainedErrorTypes());
|
ErrorTypeUtils::isExactMatch(terminalDicNode->getContainedErrorTypes());
|
||||||
const bool isFirstCharUppercase = terminalDicNode->isFirstCharUppercase();
|
const bool isFirstCharUppercase = terminalDicNode->isFirstCharUppercase();
|
||||||
// Heuristic: We exclude freq=0 first-char-uppercase words from exact match.
|
// Heuristic: We exclude probability=0 first-char-uppercase words from exact match.
|
||||||
// (e.g. "AMD" and "and")
|
// (e.g. "AMD" and "and")
|
||||||
const bool isSafeExactMatch = isExactMatch
|
const bool isSafeExactMatch = isExactMatch
|
||||||
&& !(isPossiblyOffensiveWord && isFirstCharUppercase);
|
&& !(isPossiblyOffensiveWord && isFirstCharUppercase);
|
||||||
|
@ -123,7 +123,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
|
||||||
// Don't output invalid words. However, we still need to submit their shortcuts if any.
|
// Don't output invalid words. However, we still need to submit their shortcuts if any.
|
||||||
if (isValidWord) {
|
if (isValidWord) {
|
||||||
outputTypes[outputWordIndex] = Dictionary::KIND_CORRECTION | outputTypeFlags;
|
outputTypes[outputWordIndex] = Dictionary::KIND_CORRECTION | outputTypeFlags;
|
||||||
frequencies[outputWordIndex] = finalScore;
|
outputScores[outputWordIndex] = finalScore;
|
||||||
if (outputSecondWordFirstLetterInputIndex) {
|
if (outputSecondWordFirstLetterInputIndex) {
|
||||||
outputIndicesToPartialCommit[outputWordIndex] =
|
outputIndicesToPartialCommit[outputWordIndex] =
|
||||||
terminalDicNode->getSecondWordFirstInputIndex(
|
terminalDicNode->getSecondWordFirstInputIndex(
|
||||||
|
@ -151,7 +151,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
|
||||||
terminalDicNode->getContainedErrorTypes(),
|
terminalDicNode->getContainedErrorTypes(),
|
||||||
true /* forceCommit */, boostExactMatches) : finalScore;
|
true /* forceCommit */, boostExactMatches) : finalScore;
|
||||||
const int updatedOutputWordIndex = outputShortcuts(&shortcutIt,
|
const int updatedOutputWordIndex = outputShortcuts(&shortcutIt,
|
||||||
outputWordIndex, shortcutBaseScore, outputCodePoints, frequencies, outputTypes,
|
outputWordIndex, shortcutBaseScore, outputCodePoints, outputScores, outputTypes,
|
||||||
sameAsTyped);
|
sameAsTyped);
|
||||||
const int secondWordFirstInputIndex = terminalDicNode->getSecondWordFirstInputIndex(
|
const int secondWordFirstInputIndex = terminalDicNode->getSecondWordFirstInputIndex(
|
||||||
traverseSession->getProximityInfoState(0));
|
traverseSession->getProximityInfoState(0));
|
||||||
|
@ -168,8 +168,8 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasMostProbableString) {
|
if (hasMostProbableString) {
|
||||||
scoringPolicy->safetyNetForMostProbableString(terminalSize, maxScore,
|
scoringPolicy->safetyNetForMostProbableString(outputWordIndex, maxScore,
|
||||||
&outputCodePoints[0], &frequencies[0]);
|
&outputCodePoints[0], outputScores);
|
||||||
}
|
}
|
||||||
return outputWordIndex;
|
return outputWordIndex;
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
|
||||||
/* static */ int SuggestionsOutputUtils::outputShortcuts(
|
/* static */ int SuggestionsOutputUtils::outputShortcuts(
|
||||||
BinaryDictionaryShortcutIterator *const shortcutIt,
|
BinaryDictionaryShortcutIterator *const shortcutIt,
|
||||||
int outputWordIndex, const int finalScore, int *const outputCodePoints,
|
int outputWordIndex, const int finalScore, int *const outputCodePoints,
|
||||||
int *const frequencies, int *const outputTypes, const bool sameAsTyped) {
|
int *const outputScores, int *const outputTypes, const bool sameAsTyped) {
|
||||||
int shortcutTarget[MAX_WORD_LENGTH];
|
int shortcutTarget[MAX_WORD_LENGTH];
|
||||||
while (shortcutIt->hasNextShortcutTarget() && outputWordIndex < MAX_RESULTS) {
|
while (shortcutIt->hasNextShortcutTarget() && outputWordIndex < MAX_RESULTS) {
|
||||||
bool isWhilelist;
|
bool isWhilelist;
|
||||||
|
@ -249,8 +249,8 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
|
||||||
kind = Dictionary::KIND_SHORTCUT;
|
kind = Dictionary::KIND_SHORTCUT;
|
||||||
}
|
}
|
||||||
outputTypes[outputWordIndex] = kind;
|
outputTypes[outputWordIndex] = kind;
|
||||||
frequencies[outputWordIndex] = shortcutScore;
|
outputScores[outputWordIndex] = shortcutScore;
|
||||||
frequencies[outputWordIndex] = max(S_INT_MIN + 1, shortcutScore) - 1;
|
outputScores[outputWordIndex] = max(S_INT_MIN + 1, shortcutScore) - 1;
|
||||||
const int startIndex2 = outputWordIndex * MAX_WORD_LENGTH;
|
const int startIndex2 = outputWordIndex * MAX_WORD_LENGTH;
|
||||||
DicNodeUtils::appendTwoWords(0, 0, shortcutTarget, shortcutTargetStringLength,
|
DicNodeUtils::appendTwoWords(0, 0, shortcutTarget, shortcutTargetStringLength,
|
||||||
&outputCodePoints[startIndex2]);
|
&outputCodePoints[startIndex2]);
|
||||||
|
|
|
@ -32,7 +32,7 @@ class SuggestionsOutputUtils {
|
||||||
* Outputs the final list of suggestions (i.e., terminal nodes).
|
* Outputs the final list of suggestions (i.e., terminal nodes).
|
||||||
*/
|
*/
|
||||||
static int outputSuggestions(const Scoring *const scoringPolicy,
|
static int outputSuggestions(const Scoring *const scoringPolicy,
|
||||||
DicTraverseSession *traverseSession, int *frequencies, int *outputCodePoints,
|
DicTraverseSession *traverseSession, int *outputScores, int *outputCodePoints,
|
||||||
int *outputIndicesToPartialCommit, int *outputTypes,
|
int *outputIndicesToPartialCommit, int *outputTypes,
|
||||||
int *outputAutoCommitFirstWordConfidence);
|
int *outputAutoCommitFirstWordConfidence);
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class SuggestionsOutputUtils {
|
||||||
|
|
||||||
static int outputShortcuts(BinaryDictionaryShortcutIterator *const shortcutIt,
|
static int outputShortcuts(BinaryDictionaryShortcutIterator *const shortcutIt,
|
||||||
int outputWordIndex, const int finalScore, int *const outputCodePoints,
|
int outputWordIndex, const int finalScore, int *const outputCodePoints,
|
||||||
int *const frequencies, int *const outputTypes, const bool sameAsTyped);
|
int *const outputScores, int *const outputTypes, const bool sameAsTyped);
|
||||||
};
|
};
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
#endif // LATINIME_SUGGESTIONS_OUTPUT_UTILS
|
#endif // LATINIME_SUGGESTIONS_OUTPUT_UTILS
|
||||||
|
|
|
@ -33,8 +33,8 @@ class Scoring {
|
||||||
virtual bool getMostProbableString(const DicTraverseSession *const traverseSession,
|
virtual bool getMostProbableString(const DicTraverseSession *const traverseSession,
|
||||||
const int terminalSize, const float languageWeight, int *const outputCodePoints,
|
const int terminalSize, const float languageWeight, int *const outputCodePoints,
|
||||||
int *const type, int *const freq) const = 0;
|
int *const type, int *const freq) const = 0;
|
||||||
virtual void safetyNetForMostProbableString(const int terminalSize,
|
virtual void safetyNetForMostProbableString(const int scoreCount,
|
||||||
const int maxScore, int *const outputCodePoints, int *const frequencies) const = 0;
|
const int maxScore, int *const outputCodePoints, int *const scores) const = 0;
|
||||||
virtual float getAdjustedLanguageWeight(DicTraverseSession *const traverseSession,
|
virtual float getAdjustedLanguageWeight(DicTraverseSession *const traverseSession,
|
||||||
DicNode *const terminals, const int size) const = 0;
|
DicNode *const terminals, const int size) const = 0;
|
||||||
virtual float getDoubleLetterDemotionDistanceCost(
|
virtual float getDoubleLetterDemotionDistanceCost(
|
||||||
|
|
|
@ -44,7 +44,7 @@ const int Suggest::MIN_CONTINUOUS_SUGGESTION_INPUT_SIZE = 2;
|
||||||
*/
|
*/
|
||||||
int Suggest::getSuggestions(ProximityInfo *pInfo, void *traverseSession,
|
int Suggest::getSuggestions(ProximityInfo *pInfo, void *traverseSession,
|
||||||
int *inputXs, int *inputYs, int *times, int *pointerIds, int *inputCodePoints,
|
int *inputXs, int *inputYs, int *times, int *pointerIds, int *inputCodePoints,
|
||||||
int inputSize, int commitPoint, int *outWords, int *frequencies, int *outputIndices,
|
int inputSize, int commitPoint, int *outWords, int *outputScores, int *outputIndices,
|
||||||
int *outputTypes, int *outputAutoCommitFirstWordConfidence) const {
|
int *outputTypes, int *outputAutoCommitFirstWordConfidence) const {
|
||||||
PROF_OPEN;
|
PROF_OPEN;
|
||||||
PROF_START(0);
|
PROF_START(0);
|
||||||
|
@ -66,7 +66,7 @@ int Suggest::getSuggestions(ProximityInfo *pInfo, void *traverseSession,
|
||||||
}
|
}
|
||||||
PROF_END(1);
|
PROF_END(1);
|
||||||
PROF_START(2);
|
PROF_START(2);
|
||||||
const int size = SuggestionsOutputUtils::outputSuggestions(SCORING, tSession, frequencies,
|
const int size = SuggestionsOutputUtils::outputSuggestions(SCORING, tSession, outputScores,
|
||||||
outWords, outputIndices, outputTypes, outputAutoCommitFirstWordConfidence);
|
outWords, outputIndices, outputTypes, outputAutoCommitFirstWordConfidence);
|
||||||
PROF_END(2);
|
PROF_END(2);
|
||||||
PROF_CLOSE;
|
PROF_CLOSE;
|
||||||
|
|
|
@ -48,7 +48,7 @@ class Suggest : public SuggestInterface {
|
||||||
AK_FORCE_INLINE virtual ~Suggest() {}
|
AK_FORCE_INLINE virtual ~Suggest() {}
|
||||||
int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
|
int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
|
||||||
int *times, int *pointerIds, int *inputCodePoints, int inputSize, int commitPoint,
|
int *times, int *pointerIds, int *inputCodePoints, int inputSize, int commitPoint,
|
||||||
int *outWords, int *frequencies, int *outputIndices, int *outputTypes,
|
int *outWords, int *outputScores, int *outputIndices, int *outputTypes,
|
||||||
int *outputAutoCommitFirstWordConfidence) const;
|
int *outputAutoCommitFirstWordConfidence) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -27,7 +27,7 @@ class SuggestInterface {
|
||||||
public:
|
public:
|
||||||
virtual int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs,
|
virtual int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs,
|
||||||
int *inputYs, int *times, int *pointerIds, int *inputCodePoints, int inputSize,
|
int *inputYs, int *times, int *pointerIds, int *inputCodePoints, int inputSize,
|
||||||
int commitPoint, int *outWords, int *frequencies, int *outputIndices,
|
int commitPoint, int *outWords, int *outputScores, int *outputIndices,
|
||||||
int *outputTypes, int *outputAutoCommitFirstWordConfidence) const = 0;
|
int *outputTypes, int *outputAutoCommitFirstWordConfidence) const = 0;
|
||||||
SuggestInterface() {}
|
SuggestInterface() {}
|
||||||
virtual ~SuggestInterface() {}
|
virtual ~SuggestInterface() {}
|
||||||
|
|
|
@ -39,8 +39,8 @@ class TypingScoring : public Scoring {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
AK_FORCE_INLINE void safetyNetForMostProbableString(const int terminalSize,
|
AK_FORCE_INLINE void safetyNetForMostProbableString(const int scoreCount,
|
||||||
const int maxScore, int *const outputCodePoints, int *const frequencies) const {
|
const int maxScore, int *const outputCodePoints, int *const scores) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
AK_FORCE_INLINE float getAdjustedLanguageWeight(DicTraverseSession *const traverseSession,
|
AK_FORCE_INLINE float getAdjustedLanguageWeight(DicTraverseSession *const traverseSession,
|
||||||
|
|
Loading…
Reference in New Issue