Merge "Make DicTraverseSession having suggest options."
commit
2ebe2009b3
|
@ -162,7 +162,7 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz, j
|
||||||
const jsize numberOfOptions = env->GetArrayLength(suggestOptions);
|
const jsize numberOfOptions = env->GetArrayLength(suggestOptions);
|
||||||
int options[numberOfOptions];
|
int options[numberOfOptions];
|
||||||
env->GetIntArrayRegion(suggestOptions, 0, numberOfOptions, options);
|
env->GetIntArrayRegion(suggestOptions, 0, numberOfOptions, options);
|
||||||
SuggestOptions givenOptions(options, numberOfOptions);
|
SuggestOptions givenSuggestOptions(options, numberOfOptions);
|
||||||
|
|
||||||
// Output values
|
// Output values
|
||||||
/* By the way, let's check the output array length here to make sure */
|
/* By the way, let's check the output array length here to make sure */
|
||||||
|
@ -190,12 +190,11 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz, j
|
||||||
memset(outputTypes, 0, sizeof(outputTypes));
|
memset(outputTypes, 0, sizeof(outputTypes));
|
||||||
|
|
||||||
int count;
|
int count;
|
||||||
if (givenOptions.isGesture() || inputSize > 0) {
|
if (givenSuggestOptions.isGesture() || inputSize > 0) {
|
||||||
count = dictionary->getSuggestions(pInfo, traverseSession, xCoordinates, yCoordinates,
|
count = dictionary->getSuggestions(pInfo, traverseSession, xCoordinates, yCoordinates,
|
||||||
times, pointerIds, inputCodePoints, inputSize, prevWordCodePoints,
|
times, pointerIds, inputCodePoints, inputSize, prevWordCodePoints,
|
||||||
prevWordCodePointsLength, commitPoint, givenOptions.isGesture(),
|
prevWordCodePointsLength, commitPoint, &givenSuggestOptions, outputCodePoints,
|
||||||
givenOptions.useFullEditDistance(), outputCodePoints, scores,
|
scores, spaceIndices, outputTypes);
|
||||||
spaceIndices, outputTypes);
|
|
||||||
} else {
|
} else {
|
||||||
count = dictionary->getBigrams(prevWordCodePoints, prevWordCodePointsLength,
|
count = dictionary->getBigrams(prevWordCodePoints, prevWordCodePointsLength,
|
||||||
inputCodePoints, inputSize, outputCodePoints, scores, outputTypes);
|
inputCodePoints, inputSize, outputCodePoints, scores, outputTypes);
|
||||||
|
|
|
@ -34,12 +34,14 @@ static void latinime_initDicTraverseSession(JNIEnv *env, jclass clazz, jlong tra
|
||||||
void *ts = reinterpret_cast<void *>(traverseSession);
|
void *ts = reinterpret_cast<void *>(traverseSession);
|
||||||
Dictionary *dict = reinterpret_cast<Dictionary *>(dictionary);
|
Dictionary *dict = reinterpret_cast<Dictionary *>(dictionary);
|
||||||
if (!previousWord) {
|
if (!previousWord) {
|
||||||
DicTraverseWrapper::initDicTraverseSession(ts, dict, 0, 0);
|
DicTraverseWrapper::initDicTraverseSession(
|
||||||
|
ts, dict, 0 /* prevWord */, 0 /* prevWordLength*/, 0 /* suggestOptions */);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int prevWord[previousWordLength];
|
int prevWord[previousWordLength];
|
||||||
env->GetIntArrayRegion(previousWord, 0, previousWordLength, prevWord);
|
env->GetIntArrayRegion(previousWord, 0, previousWordLength, prevWord);
|
||||||
DicTraverseWrapper::initDicTraverseSession(ts, dict, prevWord, previousWordLength);
|
DicTraverseWrapper::initDicTraverseSession(
|
||||||
|
ts, dict, prevWord, previousWordLength, 0 /* suggestOptions */);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void latinime_releaseDicTraverseSession(JNIEnv *env, jclass clazz, jlong traverseSession) {
|
static void latinime_releaseDicTraverseSession(JNIEnv *env, jclass clazz, jlong traverseSession) {
|
||||||
|
|
|
@ -22,5 +22,5 @@ namespace latinime {
|
||||||
void *(*DicTraverseWrapper::sDicTraverseSessionFactoryMethod)(JNIEnv *, jstring) = 0;
|
void *(*DicTraverseWrapper::sDicTraverseSessionFactoryMethod)(JNIEnv *, jstring) = 0;
|
||||||
void (*DicTraverseWrapper::sDicTraverseSessionReleaseMethod)(void *) = 0;
|
void (*DicTraverseWrapper::sDicTraverseSessionReleaseMethod)(void *) = 0;
|
||||||
void (*DicTraverseWrapper::sDicTraverseSessionInitMethod)(
|
void (*DicTraverseWrapper::sDicTraverseSessionInitMethod)(
|
||||||
void *, const Dictionary *const, const int *, const int) = 0;
|
void *, const Dictionary *const, const int *, const int, const SuggestOptions *const) = 0;
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
class Dictionary;
|
class Dictionary;
|
||||||
|
class SuggestOptions;
|
||||||
// TODO: Remove
|
// TODO: Remove
|
||||||
class DicTraverseWrapper {
|
class DicTraverseWrapper {
|
||||||
public:
|
public:
|
||||||
|
@ -32,9 +33,11 @@ class DicTraverseWrapper {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static void initDicTraverseSession(void *traverseSession, const Dictionary *const dictionary,
|
static void initDicTraverseSession(void *traverseSession, const Dictionary *const dictionary,
|
||||||
const int *prevWord, const int prevWordLength) {
|
const int *prevWord, const int prevWordLength,
|
||||||
|
const SuggestOptions *const suggestOptions) {
|
||||||
if (sDicTraverseSessionInitMethod) {
|
if (sDicTraverseSessionInitMethod) {
|
||||||
sDicTraverseSessionInitMethod(traverseSession, dictionary, prevWord, prevWordLength);
|
sDicTraverseSessionInitMethod(
|
||||||
|
traverseSession, dictionary, prevWord, prevWordLength, suggestOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void releaseDicTraverseSession(void *traverseSession) {
|
static void releaseDicTraverseSession(void *traverseSession) {
|
||||||
|
@ -46,7 +49,8 @@ class DicTraverseWrapper {
|
||||||
sDicTraverseSessionFactoryMethod = factoryMethod;
|
sDicTraverseSessionFactoryMethod = factoryMethod;
|
||||||
}
|
}
|
||||||
static void setTraverseSessionInitMethod(
|
static void setTraverseSessionInitMethod(
|
||||||
void (*initMethod)(void *, const Dictionary *const, const int *, const int)) {
|
void (*initMethod)(void *, const Dictionary *const, const int *, const int,
|
||||||
|
const SuggestOptions *const)) {
|
||||||
sDicTraverseSessionInitMethod = initMethod;
|
sDicTraverseSessionInitMethod = initMethod;
|
||||||
}
|
}
|
||||||
static void setTraverseSessionReleaseMethod(void (*releaseMethod)(void *)) {
|
static void setTraverseSessionReleaseMethod(void (*releaseMethod)(void *)) {
|
||||||
|
@ -57,7 +61,7 @@ class DicTraverseWrapper {
|
||||||
DISALLOW_IMPLICIT_CONSTRUCTORS(DicTraverseWrapper);
|
DISALLOW_IMPLICIT_CONSTRUCTORS(DicTraverseWrapper);
|
||||||
static void *(*sDicTraverseSessionFactoryMethod)(JNIEnv *, jstring);
|
static void *(*sDicTraverseSessionFactoryMethod)(JNIEnv *, jstring);
|
||||||
static void (*sDicTraverseSessionInitMethod)(
|
static void (*sDicTraverseSessionInitMethod)(
|
||||||
void *, const Dictionary *const, const int *, const int);
|
void *, const Dictionary *const, const int *, const int, const SuggestOptions *const);
|
||||||
static void (*sDicTraverseSessionReleaseMethod)(void *);
|
static void (*sDicTraverseSessionReleaseMethod)(void *);
|
||||||
};
|
};
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "binary_format.h"
|
#include "binary_format.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "dic_traverse_wrapper.h"
|
#include "dic_traverse_wrapper.h"
|
||||||
|
#include "suggest_options.h"
|
||||||
#include "suggest/core/suggest.h"
|
#include "suggest/core/suggest.h"
|
||||||
#include "suggest/policyimpl/gesture/gesture_suggest_policy_factory.h"
|
#include "suggest/policyimpl/gesture/gesture_suggest_policy_factory.h"
|
||||||
#include "suggest/policyimpl/typing/typing_suggest_policy_factory.h"
|
#include "suggest/policyimpl/typing/typing_suggest_policy_factory.h"
|
||||||
|
@ -53,13 +54,13 @@ Dictionary::~Dictionary() {
|
||||||
|
|
||||||
int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *traverseSession,
|
int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *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, bool isGesture,
|
int inputSize, int *prevWordCodePoints, int prevWordLength, int commitPoint,
|
||||||
bool useFullEditDistance, int *outWords, int *frequencies, int *spaceIndices,
|
const SuggestOptions *const suggestOptions, int *outWords, int *frequencies,
|
||||||
int *outputTypes) const {
|
int *spaceIndices, int *outputTypes) const {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if (isGesture) {
|
if (suggestOptions->isGesture()) {
|
||||||
DicTraverseWrapper::initDicTraverseSession(
|
DicTraverseWrapper::initDicTraverseSession(
|
||||||
traverseSession, this, prevWordCodePoints, prevWordLength);
|
traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions);
|
||||||
result = mGestureSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
|
result = mGestureSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
|
||||||
ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint, outWords,
|
ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint, outWords,
|
||||||
frequencies, spaceIndices, outputTypes);
|
frequencies, spaceIndices, outputTypes);
|
||||||
|
@ -70,7 +71,7 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *traverseSessi
|
||||||
} else {
|
} else {
|
||||||
if (USE_SUGGEST_INTERFACE_FOR_TYPING) {
|
if (USE_SUGGEST_INTERFACE_FOR_TYPING) {
|
||||||
DicTraverseWrapper::initDicTraverseSession(
|
DicTraverseWrapper::initDicTraverseSession(
|
||||||
traverseSession, this, prevWordCodePoints, prevWordLength);
|
traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions);
|
||||||
result = mTypingSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
|
result = mTypingSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
|
||||||
ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint,
|
ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint,
|
||||||
outWords, frequencies, spaceIndices, outputTypes);
|
outWords, frequencies, spaceIndices, outputTypes);
|
||||||
|
@ -84,8 +85,8 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *traverseSessi
|
||||||
mBigramDictionary->fillBigramAddressToProbabilityMapAndFilter(prevWordCodePoints,
|
mBigramDictionary->fillBigramAddressToProbabilityMapAndFilter(prevWordCodePoints,
|
||||||
prevWordLength, &bigramMap, bigramFilter);
|
prevWordLength, &bigramMap, bigramFilter);
|
||||||
result = mUnigramDictionary->getSuggestions(proximityInfo, xcoordinates, ycoordinates,
|
result = mUnigramDictionary->getSuggestions(proximityInfo, xcoordinates, ycoordinates,
|
||||||
inputCodePoints, inputSize, &bigramMap, bigramFilter, useFullEditDistance,
|
inputCodePoints, inputSize, &bigramMap, bigramFilter,
|
||||||
outWords, frequencies, outputTypes);
|
suggestOptions->useFullEditDistance(), outWords, frequencies, outputTypes);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace latinime {
|
||||||
class BigramDictionary;
|
class BigramDictionary;
|
||||||
class ProximityInfo;
|
class ProximityInfo;
|
||||||
class SuggestInterface;
|
class SuggestInterface;
|
||||||
|
class SuggestOptions;
|
||||||
class UnigramDictionary;
|
class UnigramDictionary;
|
||||||
|
|
||||||
class Dictionary {
|
class Dictionary {
|
||||||
|
@ -54,9 +55,9 @@ class Dictionary {
|
||||||
|
|
||||||
int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates,
|
int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates,
|
||||||
int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints, int inputSize,
|
int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints, int inputSize,
|
||||||
int *prevWordCodePoints, int prevWordLength, int commitPoint, bool isGesture,
|
int *prevWordCodePoints, int prevWordLength, int commitPoint,
|
||||||
bool useFullEditDistance, int *outWords, int *frequencies, int *spaceIndices,
|
const SuggestOptions *const suggestOptions, int *outWords, int *frequencies,
|
||||||
int *outputTypes) const;
|
int *spaceIndices, int *outputTypes) const;
|
||||||
|
|
||||||
int getBigrams(const int *word, int length, int *inputCodePoints, int inputSize, int *outWords,
|
int getBigrams(const int *word, int length, int *inputCodePoints, int inputSize, int *outWords,
|
||||||
int *frequencies, int *outputTypes) const;
|
int *frequencies, int *outputTypes) const;
|
||||||
|
|
|
@ -34,10 +34,11 @@ static void *getSessionInstance(JNIEnv *env, jstring localeStr) {
|
||||||
|
|
||||||
// TODO: Pass "DicTraverseSession *traverseSession" when the source code structure settles down.
|
// TODO: Pass "DicTraverseSession *traverseSession" when the source code structure settles down.
|
||||||
static void initSessionInstance(void *traverseSession, const Dictionary *const dictionary,
|
static void initSessionInstance(void *traverseSession, const Dictionary *const dictionary,
|
||||||
const int *prevWord, const int prevWordLength) {
|
const int *prevWord, const int prevWordLength,
|
||||||
|
const SuggestOptions *const suggestOptions) {
|
||||||
if (traverseSession) {
|
if (traverseSession) {
|
||||||
DicTraverseSession *tSession = static_cast<DicTraverseSession *>(traverseSession);
|
DicTraverseSession *tSession = static_cast<DicTraverseSession *>(traverseSession);
|
||||||
tSession->init(dictionary, prevWord, prevWordLength);
|
tSession->init(dictionary, prevWord, prevWordLength, suggestOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,10 +63,11 @@ class TraverseSessionFactoryRegisterer {
|
||||||
static TraverseSessionFactoryRegisterer traverseSessionFactoryRegisterer;
|
static TraverseSessionFactoryRegisterer traverseSessionFactoryRegisterer;
|
||||||
|
|
||||||
void DicTraverseSession::init(const Dictionary *const dictionary, const int *prevWord,
|
void DicTraverseSession::init(const Dictionary *const dictionary, const int *prevWord,
|
||||||
int prevWordLength) {
|
int prevWordLength, const SuggestOptions *const suggestOptions) {
|
||||||
mDictionary = dictionary;
|
mDictionary = dictionary;
|
||||||
mMultiWordCostMultiplier = BinaryFormat::getMultiWordCostMultiplier(mDictionary->getDict(),
|
mMultiWordCostMultiplier = BinaryFormat::getMultiWordCostMultiplier(mDictionary->getDict(),
|
||||||
mDictionary->getDictSize());
|
mDictionary->getDictSize());
|
||||||
|
mSuggestOptions = suggestOptions;
|
||||||
if (!prevWord) {
|
if (!prevWord) {
|
||||||
mPrevWordPos = NOT_VALID_WORD;
|
mPrevWordPos = NOT_VALID_WORD;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -30,12 +30,13 @@ namespace latinime {
|
||||||
|
|
||||||
class Dictionary;
|
class Dictionary;
|
||||||
class ProximityInfo;
|
class ProximityInfo;
|
||||||
|
class SuggestOptions;
|
||||||
|
|
||||||
class DicTraverseSession {
|
class DicTraverseSession {
|
||||||
public:
|
public:
|
||||||
AK_FORCE_INLINE DicTraverseSession(JNIEnv *env, jstring localeStr)
|
AK_FORCE_INLINE DicTraverseSession(JNIEnv *env, jstring localeStr)
|
||||||
: mPrevWordPos(NOT_VALID_WORD), mProximityInfo(0),
|
: mPrevWordPos(NOT_VALID_WORD), mProximityInfo(0),
|
||||||
mDictionary(0), mDicNodesCache(), mMultiBigramMap(),
|
mDictionary(0), mSuggestOptions(0), mDicNodesCache(), mMultiBigramMap(),
|
||||||
mInputSize(0), mPartiallyCommited(false), mMaxPointerCount(1),
|
mInputSize(0), mPartiallyCommited(false), mMaxPointerCount(1),
|
||||||
mMultiWordCostMultiplier(1.0f) {
|
mMultiWordCostMultiplier(1.0f) {
|
||||||
// NOTE: mProximityInfoStates is an array of instances.
|
// NOTE: mProximityInfoStates is an array of instances.
|
||||||
|
@ -45,7 +46,8 @@ class DicTraverseSession {
|
||||||
// Non virtual inline destructor -- never inherit this class
|
// Non virtual inline destructor -- never inherit this class
|
||||||
AK_FORCE_INLINE ~DicTraverseSession() {}
|
AK_FORCE_INLINE ~DicTraverseSession() {}
|
||||||
|
|
||||||
void init(const Dictionary *dictionary, const int *prevWord, int prevWordLength);
|
void init(const Dictionary *dictionary, const int *prevWord, int prevWordLength,
|
||||||
|
const SuggestOptions *const suggestOptions);
|
||||||
// TODO: Remove and merge into init
|
// TODO: Remove and merge into init
|
||||||
void setupForGetSuggestions(const ProximityInfo *pInfo, const int *inputCodePoints,
|
void setupForGetSuggestions(const ProximityInfo *pInfo, const int *inputCodePoints,
|
||||||
const int inputSize, const int *const inputXs, const int *const inputYs,
|
const int inputSize, const int *const inputXs, const int *const inputYs,
|
||||||
|
@ -61,6 +63,7 @@ class DicTraverseSession {
|
||||||
// getters and setters
|
// getters and setters
|
||||||
//--------------------
|
//--------------------
|
||||||
const ProximityInfo *getProximityInfo() const { return mProximityInfo; }
|
const ProximityInfo *getProximityInfo() const { return mProximityInfo; }
|
||||||
|
const SuggestOptions *getSuggestOptions() const { return mSuggestOptions; }
|
||||||
int getPrevWordPos() const { return mPrevWordPos; }
|
int getPrevWordPos() const { return mPrevWordPos; }
|
||||||
// TODO: REMOVE
|
// TODO: REMOVE
|
||||||
void setPrevWordPos(int pos) { mPrevWordPos = pos; }
|
void setPrevWordPos(int pos) { mPrevWordPos = pos; }
|
||||||
|
@ -167,6 +170,7 @@ class DicTraverseSession {
|
||||||
int mPrevWordPos;
|
int mPrevWordPos;
|
||||||
const ProximityInfo *mProximityInfo;
|
const ProximityInfo *mProximityInfo;
|
||||||
const Dictionary *mDictionary;
|
const Dictionary *mDictionary;
|
||||||
|
const SuggestOptions *mSuggestOptions;
|
||||||
|
|
||||||
DicNodesCache mDicNodesCache;
|
DicNodesCache mDicNodesCache;
|
||||||
// Temporary cache for bigram frequencies
|
// Temporary cache for bigram frequencies
|
||||||
|
|
|
@ -23,6 +23,9 @@ namespace latinime {
|
||||||
|
|
||||||
class SuggestOptions{
|
class SuggestOptions{
|
||||||
public:
|
public:
|
||||||
|
SuggestOptions(const int *const options, const int length)
|
||||||
|
: mOptions(options), mLength(length) {}
|
||||||
|
|
||||||
AK_FORCE_INLINE bool isGesture() const {
|
AK_FORCE_INLINE bool isGesture() const {
|
||||||
return getBoolOption(IS_GESTURE);
|
return getBoolOption(IS_GESTURE);
|
||||||
}
|
}
|
||||||
|
@ -31,14 +34,18 @@ class SuggestOptions{
|
||||||
return getBoolOption(USE_FULL_EDIT_DISTANCE);
|
return getBoolOption(USE_FULL_EDIT_DISTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
SuggestOptions(const int *const options, const int length)
|
AK_FORCE_INLINE bool getAdditionalFeaturesBoolOption(const int key) const {
|
||||||
: mOptions(options), mLength(length) {}
|
return getBoolOption(key + ADDITIONAL_FEATURES_OPTIONS);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Need to update com.android.inputmethod.latin.NativeSuggestOptions when you add, remove or
|
// Need to update com.android.inputmethod.latin.NativeSuggestOptions when you add, remove or
|
||||||
// reorder options.
|
// reorder options.
|
||||||
static const int IS_GESTURE = 0;
|
static const int IS_GESTURE = 0;
|
||||||
static const int USE_FULL_EDIT_DISTANCE = 1;
|
static const int USE_FULL_EDIT_DISTANCE = 1;
|
||||||
|
// Additional features options are stored after the other options and used as setting values of
|
||||||
|
// experimental features.
|
||||||
|
static const int ADDITIONAL_FEATURES_OPTIONS = 2;
|
||||||
|
|
||||||
const int *const mOptions;
|
const int *const mOptions;
|
||||||
const int mLength;
|
const int mLength;
|
||||||
|
|
Loading…
Reference in New Issue