am de2b312c: Use same language weight for all dictionaries.
* commit 'de2b312c6d00509a313c076d0be37eea5c2d41f3': Use same language weight for all dictionaries.main
commit
aa105c1097
|
@ -210,20 +210,22 @@ static void latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz,
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
float languageWeight;
|
||||||
|
env->GetFloatArrayRegion(inOutLanguageWeight, 0, 1 /* len */, &languageWeight);
|
||||||
SuggestionResults suggestionResults(MAX_RESULTS);
|
SuggestionResults suggestionResults(MAX_RESULTS);
|
||||||
if (givenSuggestOptions.isGesture() || inputSize > 0) {
|
if (givenSuggestOptions.isGesture() || inputSize > 0) {
|
||||||
// TODO: Use SuggestionResults to return suggestions.
|
// TODO: Use SuggestionResults to return suggestions.
|
||||||
dictionary->getSuggestions(pInfo, traverseSession, xCoordinates, yCoordinates,
|
dictionary->getSuggestions(pInfo, traverseSession, xCoordinates, yCoordinates,
|
||||||
times, pointerIds, inputCodePoints, inputSize, prevWordCodePoints,
|
times, pointerIds, inputCodePoints, inputSize, prevWordCodePoints,
|
||||||
prevWordCodePointsLength, &givenSuggestOptions, &suggestionResults);
|
prevWordCodePointsLength, &givenSuggestOptions, languageWeight,
|
||||||
|
&suggestionResults);
|
||||||
} else {
|
} else {
|
||||||
dictionary->getPredictions(prevWordCodePoints, prevWordCodePointsLength,
|
dictionary->getPredictions(prevWordCodePoints, prevWordCodePointsLength,
|
||||||
&suggestionResults);
|
&suggestionResults);
|
||||||
}
|
}
|
||||||
suggestionResults.outputSuggestions(env, outSuggestionCount, outCodePointsArray,
|
suggestionResults.outputSuggestions(env, outSuggestionCount, outCodePointsArray,
|
||||||
outScoresArray, outSpaceIndicesArray, outTypesArray,
|
outScoresArray, outSpaceIndicesArray, outTypesArray,
|
||||||
outAutoCommitFirstWordConfidenceArray);
|
outAutoCommitFirstWordConfidenceArray, inOutLanguageWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
static jint latinime_BinaryDictionary_getProbability(JNIEnv *env, jclass clazz, jlong dict,
|
static jint latinime_BinaryDictionary_getProbability(JNIEnv *env, jclass clazz, jlong dict,
|
||||||
|
|
|
@ -309,6 +309,7 @@ static inline void prof_out(void) {
|
||||||
#define NOT_A_PROBABILITY (-1)
|
#define NOT_A_PROBABILITY (-1)
|
||||||
#define NOT_A_DICT_POS (S_INT_MIN)
|
#define NOT_A_DICT_POS (S_INT_MIN)
|
||||||
#define NOT_A_TIMESTAMP (-1)
|
#define NOT_A_TIMESTAMP (-1)
|
||||||
|
#define NOT_A_LANGUAGE_WEIGHT (-1.0f)
|
||||||
|
|
||||||
// A special value to mean the first word confidence makes no sense in this case,
|
// A special value to mean the first word confidence makes no sense in this case,
|
||||||
// e.g. this is not a multi-word suggestion.
|
// e.g. this is not a multi-word suggestion.
|
||||||
|
|
|
@ -47,7 +47,7 @@ Dictionary::Dictionary(JNIEnv *env, DictionaryStructureWithBufferPolicy::Structu
|
||||||
void Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
|
void 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 inputSize, int *prevWordCodePoints, int prevWordLength,
|
||||||
const SuggestOptions *const suggestOptions,
|
const SuggestOptions *const suggestOptions, const float languageWeight,
|
||||||
SuggestionResults *const outSuggestionResults) const {
|
SuggestionResults *const outSuggestionResults) const {
|
||||||
TimeKeeper::setCurrentTime();
|
TimeKeeper::setCurrentTime();
|
||||||
DicTraverseSession::initSessionInstance(
|
DicTraverseSession::initSessionInstance(
|
||||||
|
@ -55,11 +55,11 @@ void Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession
|
||||||
if (suggestOptions->isGesture()) {
|
if (suggestOptions->isGesture()) {
|
||||||
mGestureSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
|
mGestureSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
|
||||||
ycoordinates, times, pointerIds, inputCodePoints, inputSize,
|
ycoordinates, times, pointerIds, inputCodePoints, inputSize,
|
||||||
outSuggestionResults);
|
languageWeight, outSuggestionResults);
|
||||||
} else {
|
} else {
|
||||||
mTypingSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
|
mTypingSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
|
||||||
ycoordinates, times, pointerIds, inputCodePoints, inputSize,
|
ycoordinates, times, pointerIds, inputCodePoints, inputSize,
|
||||||
outSuggestionResults);
|
languageWeight, outSuggestionResults);
|
||||||
}
|
}
|
||||||
if (DEBUG_DICT) {
|
if (DEBUG_DICT) {
|
||||||
outSuggestionResults->dumpSuggestions();
|
outSuggestionResults->dumpSuggestions();
|
||||||
|
|
|
@ -65,7 +65,7 @@ class Dictionary {
|
||||||
void getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
|
void 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 inputSize, int *prevWordCodePoints, int prevWordLength,
|
||||||
const SuggestOptions *const suggestOptions,
|
const SuggestOptions *const suggestOptions, const float languageWeight,
|
||||||
SuggestionResults *const outSuggestionResults) const;
|
SuggestionResults *const outSuggestionResults) const;
|
||||||
|
|
||||||
void getPredictions(const int *word, int length,
|
void getPredictions(const int *word, int length,
|
||||||
|
|
|
@ -20,7 +20,8 @@ namespace latinime {
|
||||||
|
|
||||||
void SuggestionResults::outputSuggestions(JNIEnv *env, jintArray outSuggestionCount,
|
void SuggestionResults::outputSuggestions(JNIEnv *env, jintArray outSuggestionCount,
|
||||||
jintArray outputCodePointsArray, jintArray outScoresArray, jintArray outSpaceIndicesArray,
|
jintArray outputCodePointsArray, jintArray outScoresArray, jintArray outSpaceIndicesArray,
|
||||||
jintArray outTypesArray, jintArray outAutoCommitFirstWordConfidenceArray) {
|
jintArray outTypesArray, jintArray outAutoCommitFirstWordConfidenceArray,
|
||||||
|
jfloatArray outLanguageWeight) {
|
||||||
int outputIndex = 0;
|
int outputIndex = 0;
|
||||||
while (!mSuggestedWords.empty()) {
|
while (!mSuggestedWords.empty()) {
|
||||||
const SuggestedWord &suggestedWord = mSuggestedWords.top();
|
const SuggestedWord &suggestedWord = mSuggestedWords.top();
|
||||||
|
@ -50,6 +51,7 @@ void SuggestionResults::outputSuggestions(JNIEnv *env, jintArray outSuggestionCo
|
||||||
mSuggestedWords.pop();
|
mSuggestedWords.pop();
|
||||||
}
|
}
|
||||||
env->SetIntArrayRegion(outSuggestionCount, 0 /* start */, 1 /* len */, &outputIndex);
|
env->SetIntArrayRegion(outSuggestionCount, 0 /* start */, 1 /* len */, &outputIndex);
|
||||||
|
env->SetFloatArrayRegion(outLanguageWeight, 0 /* start */, 1 /* len */, &mLanguageWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SuggestionResults::addPrediction(const int *const codePoints, const int codePointCount,
|
void SuggestionResults::addPrediction(const int *const codePoints, const int codePointCount,
|
||||||
|
@ -94,6 +96,7 @@ void SuggestionResults::getSortedScores(int *const outScores) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SuggestionResults::dumpSuggestions() const {
|
void SuggestionResults::dumpSuggestions() const {
|
||||||
|
AKLOGE("language weight: %f", mLanguageWeight);
|
||||||
std::vector<SuggestedWord> suggestedWords;
|
std::vector<SuggestedWord> suggestedWords;
|
||||||
auto copyOfSuggestedWords = mSuggestedWords;
|
auto copyOfSuggestedWords = mSuggestedWords;
|
||||||
while (!copyOfSuggestedWords.empty()) {
|
while (!copyOfSuggestedWords.empty()) {
|
||||||
|
|
|
@ -29,12 +29,13 @@ namespace latinime {
|
||||||
class SuggestionResults {
|
class SuggestionResults {
|
||||||
public:
|
public:
|
||||||
explicit SuggestionResults(const int maxSuggestionCount)
|
explicit SuggestionResults(const int maxSuggestionCount)
|
||||||
: mMaxSuggestionCount(maxSuggestionCount), mSuggestedWords() {}
|
: mMaxSuggestionCount(maxSuggestionCount), mLanguageWeight(NOT_A_LANGUAGE_WEIGHT),
|
||||||
|
mSuggestedWords() {}
|
||||||
|
|
||||||
// Returns suggestion count.
|
// Returns suggestion count.
|
||||||
void outputSuggestions(JNIEnv *env, jintArray outSuggestionCount, jintArray outCodePointsArray,
|
void outputSuggestions(JNIEnv *env, jintArray outSuggestionCount, jintArray outCodePointsArray,
|
||||||
jintArray outScoresArray, jintArray outSpaceIndicesArray, jintArray outTypesArray,
|
jintArray outScoresArray, jintArray outSpaceIndicesArray, jintArray outTypesArray,
|
||||||
jintArray outAutoCommitFirstWordConfidenceArray);
|
jintArray outAutoCommitFirstWordConfidenceArray, jfloatArray outLanguageWeight);
|
||||||
void addPrediction(const int *const codePoints, const int codePointCount, const int score);
|
void addPrediction(const int *const codePoints, const int codePointCount, const int score);
|
||||||
void addSuggestion(const int *const codePoints, const int codePointCount,
|
void addSuggestion(const int *const codePoints, const int codePointCount,
|
||||||
const int score, const int type, const int indexToPartialCommit,
|
const int score, const int type, const int indexToPartialCommit,
|
||||||
|
@ -42,6 +43,10 @@ class SuggestionResults {
|
||||||
void getSortedScores(int *const outScores) const;
|
void getSortedScores(int *const outScores) const;
|
||||||
void dumpSuggestions() const;
|
void dumpSuggestions() const;
|
||||||
|
|
||||||
|
void setLanguageWeight(const float languageWeight) {
|
||||||
|
mLanguageWeight = languageWeight;
|
||||||
|
}
|
||||||
|
|
||||||
int getSuggestionCount() const {
|
int getSuggestionCount() const {
|
||||||
return mSuggestedWords.size();
|
return mSuggestedWords.size();
|
||||||
}
|
}
|
||||||
|
@ -50,6 +55,7 @@ class SuggestionResults {
|
||||||
DISALLOW_IMPLICIT_CONSTRUCTORS(SuggestionResults);
|
DISALLOW_IMPLICIT_CONSTRUCTORS(SuggestionResults);
|
||||||
|
|
||||||
const int mMaxSuggestionCount;
|
const int mMaxSuggestionCount;
|
||||||
|
float mLanguageWeight;
|
||||||
std::priority_queue<
|
std::priority_queue<
|
||||||
SuggestedWord, std::vector<SuggestedWord>, SuggestedWord::Comparator> mSuggestedWords;
|
SuggestedWord, std::vector<SuggestedWord>, SuggestedWord::Comparator> mSuggestedWords;
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,7 +33,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
|
||||||
|
|
||||||
/* static */ void SuggestionsOutputUtils::outputSuggestions(
|
/* static */ void SuggestionsOutputUtils::outputSuggestions(
|
||||||
const Scoring *const scoringPolicy, DicTraverseSession *traverseSession,
|
const Scoring *const scoringPolicy, DicTraverseSession *traverseSession,
|
||||||
SuggestionResults *const outSuggestionResults) {
|
const float languageWeight, SuggestionResults *const outSuggestionResults) {
|
||||||
#if DEBUG_EVALUATE_MOST_PROBABLE_STRING
|
#if DEBUG_EVALUATE_MOST_PROBABLE_STRING
|
||||||
const int terminalSize = 0;
|
const int terminalSize = 0;
|
||||||
#else
|
#else
|
||||||
|
@ -43,9 +43,12 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
|
||||||
for (int index = terminalSize - 1; index >= 0; --index) {
|
for (int index = terminalSize - 1; index >= 0; --index) {
|
||||||
traverseSession->getDicTraverseCache()->popTerminal(&terminals[index]);
|
traverseSession->getDicTraverseCache()->popTerminal(&terminals[index]);
|
||||||
}
|
}
|
||||||
|
// Compute a language weight when an invalid language weight is passed.
|
||||||
const float languageWeight = scoringPolicy->getAdjustedLanguageWeight(
|
// NOT_A_LANGUAGE_WEIGHT (-1) is assumed as an invalid language weight.
|
||||||
traverseSession, terminals.data(), terminalSize);
|
const float languageWeightToOutputSuggestions = (languageWeight < 0.0f) ?
|
||||||
|
scoringPolicy->getAdjustedLanguageWeight(
|
||||||
|
traverseSession, terminals.data(), terminalSize) : languageWeight;
|
||||||
|
outSuggestionResults->setLanguageWeight(languageWeightToOutputSuggestions);
|
||||||
// Force autocorrection for obvious long multi-word suggestions when the top suggestion is
|
// Force autocorrection for obvious long multi-word suggestions when the top suggestion is
|
||||||
// a long multiple words suggestion.
|
// a long multiple words suggestion.
|
||||||
// TODO: Implement a smarter auto-commit method for handling multi-word suggestions.
|
// TODO: Implement a smarter auto-commit method for handling multi-word suggestions.
|
||||||
|
@ -61,10 +64,11 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
|
||||||
// Output suggestion results here
|
// Output suggestion results here
|
||||||
for (auto &terminalDicNode : terminals) {
|
for (auto &terminalDicNode : terminals) {
|
||||||
outputSuggestionsOfDicNode(scoringPolicy, traverseSession, &terminalDicNode,
|
outputSuggestionsOfDicNode(scoringPolicy, traverseSession, &terminalDicNode,
|
||||||
languageWeight, boostExactMatches, forceCommitMultiWords,
|
languageWeightToOutputSuggestions, boostExactMatches, forceCommitMultiWords,
|
||||||
outputSecondWordFirstLetterInputIndex, outSuggestionResults);
|
outputSecondWordFirstLetterInputIndex, outSuggestionResults);
|
||||||
}
|
}
|
||||||
scoringPolicy->getMostProbableString(traverseSession, languageWeight, outSuggestionResults);
|
scoringPolicy->getMostProbableString(traverseSession, languageWeightToOutputSuggestions,
|
||||||
|
outSuggestionResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ void SuggestionsOutputUtils::outputSuggestionsOfDicNode(
|
/* static */ void SuggestionsOutputUtils::outputSuggestionsOfDicNode(
|
||||||
|
|
|
@ -33,7 +33,8 @@ class SuggestionsOutputUtils {
|
||||||
* Outputs the final list of suggestions (i.e., terminal nodes).
|
* Outputs the final list of suggestions (i.e., terminal nodes).
|
||||||
*/
|
*/
|
||||||
static void outputSuggestions(const Scoring *const scoringPolicy,
|
static void outputSuggestions(const Scoring *const scoringPolicy,
|
||||||
DicTraverseSession *traverseSession, SuggestionResults *const outSuggestionResults);
|
DicTraverseSession *traverseSession, const float languageWeight,
|
||||||
|
SuggestionResults *const outSuggestionResults);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DISALLOW_IMPLICIT_CONSTRUCTORS(SuggestionsOutputUtils);
|
DISALLOW_IMPLICIT_CONSTRUCTORS(SuggestionsOutputUtils);
|
||||||
|
|
|
@ -44,7 +44,8 @@ const int Suggest::MIN_CONTINUOUS_SUGGESTION_INPUT_SIZE = 2;
|
||||||
*/
|
*/
|
||||||
void Suggest::getSuggestions(ProximityInfo *pInfo, void *traverseSession,
|
void 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, SuggestionResults *const outSuggestionResults) const {
|
int inputSize, const float languageWeight,
|
||||||
|
SuggestionResults *const outSuggestionResults) const {
|
||||||
PROF_OPEN;
|
PROF_OPEN;
|
||||||
PROF_START(0);
|
PROF_START(0);
|
||||||
const float maxSpatialDistance = TRAVERSAL->getMaxSpatialDistance();
|
const float maxSpatialDistance = TRAVERSAL->getMaxSpatialDistance();
|
||||||
|
@ -65,7 +66,8 @@ void Suggest::getSuggestions(ProximityInfo *pInfo, void *traverseSession,
|
||||||
}
|
}
|
||||||
PROF_END(1);
|
PROF_END(1);
|
||||||
PROF_START(2);
|
PROF_START(2);
|
||||||
SuggestionsOutputUtils::outputSuggestions(SCORING, tSession, outSuggestionResults);
|
SuggestionsOutputUtils::outputSuggestions(
|
||||||
|
SCORING, tSession, languageWeight, outSuggestionResults);
|
||||||
PROF_END(2);
|
PROF_END(2);
|
||||||
PROF_CLOSE;
|
PROF_CLOSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Suggest : public SuggestInterface {
|
||||||
AK_FORCE_INLINE virtual ~Suggest() {}
|
AK_FORCE_INLINE virtual ~Suggest() {}
|
||||||
void getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
|
void getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
|
||||||
int *times, int *pointerIds, int *inputCodePoints, int inputSize,
|
int *times, int *pointerIds, int *inputCodePoints, int inputSize,
|
||||||
SuggestionResults *const outSuggestionResults) const;
|
const float languageWeight, SuggestionResults *const outSuggestionResults) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DISALLOW_IMPLICIT_CONSTRUCTORS(Suggest);
|
DISALLOW_IMPLICIT_CONSTRUCTORS(Suggest);
|
||||||
|
|
|
@ -28,7 +28,7 @@ class SuggestInterface {
|
||||||
public:
|
public:
|
||||||
virtual void getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs,
|
virtual void 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,
|
||||||
SuggestionResults *const suggestionResults) const = 0;
|
const float languageWeight, SuggestionResults *const suggestionResults) const = 0;
|
||||||
SuggestInterface() {}
|
SuggestInterface() {}
|
||||||
virtual ~SuggestInterface() {}
|
virtual ~SuggestInterface() {}
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue