am 447c1936
: Merge "Enable Beginning-of-Sentence prediction for contextual dict."
* commit '447c19364ac0fa7b280b3ebd8f6e820eb925ebde': Enable Beginning-of-Sentence prediction for contextual dict.
This commit is contained in:
commit
1d183cec2e
5 changed files with 43 additions and 2 deletions
|
@ -122,6 +122,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
return mBinaryDictionary.isValidDictionary();
|
return mBinaryDictionary.isValidDictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove and always enable beginning of sentence prediction. Currently, this is enabled
|
||||||
|
// only for ContextualDictionary.
|
||||||
|
protected boolean enableBeginningOfSentencePrediction() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new expandable binary dictionary.
|
* Creates a new expandable binary dictionary.
|
||||||
*
|
*
|
||||||
|
@ -398,6 +404,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
if (mBinaryDictionary == null) {
|
if (mBinaryDictionary == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (composer.size() == 0 && prevWordsInfo.mIsBeginningOfSentence
|
||||||
|
&& !enableBeginningOfSentencePrediction()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
final ArrayList<SuggestedWordInfo> suggestions =
|
final ArrayList<SuggestedWordInfo> suggestions =
|
||||||
mBinaryDictionary.getSuggestions(composer, prevWordsInfo, proximityInfo,
|
mBinaryDictionary.getSuggestions(composer, prevWordsInfo, proximityInfo,
|
||||||
blockOffensiveWords, additionalFeaturesOptions, sessionId,
|
blockOffensiveWords, additionalFeaturesOptions, sessionId,
|
||||||
|
|
|
@ -35,12 +35,18 @@ public class ContextualDictionary extends ExpandableBinaryDictionary {
|
||||||
// Always reset the contents.
|
// Always reset the contents.
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
public static ContextualDictionary getDictionary(final Context context, final Locale locale,
|
public static ContextualDictionary getDictionary(final Context context, final Locale locale,
|
||||||
final File dictFile, final String dictNamePrefix) {
|
final File dictFile, final String dictNamePrefix) {
|
||||||
return new ContextualDictionary(context, locale, dictFile);
|
return new ContextualDictionary(context, locale, dictFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean enableBeginningOfSentencePrediction() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(final String word) {
|
public boolean isValidWord(final String word) {
|
||||||
// Strings out of this dictionary should not be considered existing words.
|
// Strings out of this dictionary should not be considered existing words.
|
||||||
|
|
|
@ -249,7 +249,7 @@ static void latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz,
|
||||||
env->GetFloatArrayRegion(inOutLanguageWeight, 0, 1 /* len */, &languageWeight);
|
env->GetFloatArrayRegion(inOutLanguageWeight, 0, 1 /* len */, &languageWeight);
|
||||||
SuggestionResults suggestionResults(MAX_RESULTS);
|
SuggestionResults suggestionResults(MAX_RESULTS);
|
||||||
const PrevWordsInfo prevWordsInfo(prevWordCodePoints, prevWordCodePointsLength,
|
const PrevWordsInfo prevWordsInfo(prevWordCodePoints, prevWordCodePointsLength,
|
||||||
false /* isStartOfSentence */);
|
isBeginningOfSentence);
|
||||||
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,
|
||||||
|
|
|
@ -85,6 +85,14 @@ class PrevWordsInfo {
|
||||||
return mPrevWordCodePointCount[n - 1];
|
return mPrevWordCodePointCount[n - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// n is 1-indexed.
|
||||||
|
bool isNthPrevWordBeginningOfSentence(const int n) const {
|
||||||
|
if (n <= 0 || n > MAX_PREV_WORD_COUNT_FOR_N_GRAM) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return mIsBeginningOfSentence[n - 1];
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DISALLOW_COPY_AND_ASSIGN(PrevWordsInfo);
|
DISALLOW_COPY_AND_ASSIGN(PrevWordsInfo);
|
||||||
|
|
||||||
|
|
|
@ -246,7 +246,24 @@ bool Ver4PatriciaTriePolicy::addNgramEntry(const PrevWordsInfo *const prevWordsI
|
||||||
false /* tryLowerCaseSearch */);
|
false /* tryLowerCaseSearch */);
|
||||||
// TODO: Support N-gram.
|
// TODO: Support N-gram.
|
||||||
if (prevWordsPtNodePos[0] == NOT_A_DICT_POS) {
|
if (prevWordsPtNodePos[0] == NOT_A_DICT_POS) {
|
||||||
return false;
|
if (prevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */)) {
|
||||||
|
const std::vector<UnigramProperty::ShortcutProperty> shortcuts;
|
||||||
|
const UnigramProperty beginningOfSentenceUnigramProperty(
|
||||||
|
true /* representsBeginningOfSentence */, true /* isNotAWord */,
|
||||||
|
false /* isBlacklisted */, MAX_PROBABILITY /* probability */,
|
||||||
|
NOT_A_TIMESTAMP /* timestamp */, 0 /* level */, 0 /* count */, &shortcuts);
|
||||||
|
if (!addUnigramEntry(prevWordsInfo->getNthPrevWordCodePoints(1 /* n */),
|
||||||
|
prevWordsInfo->getNthPrevWordCodePointCount(1 /* n */),
|
||||||
|
&beginningOfSentenceUnigramProperty)) {
|
||||||
|
AKLOGE("Cannot add unigram entry for the beginning-of-sentence.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Refresh Terminal PtNode positions.
|
||||||
|
prevWordsInfo->getPrevWordsTerminalPtNodePos(this, prevWordsPtNodePos,
|
||||||
|
false /* tryLowerCaseSearch */);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const int word1Pos = getTerminalPtNodePositionOfWord(
|
const int word1Pos = getTerminalPtNodePositionOfWord(
|
||||||
bigramProperty->getTargetCodePoints()->data(),
|
bigramProperty->getTargetCodePoints()->data(),
|
||||||
|
|
Loading…
Reference in a new issue