am 52076549: Merge "Make Beginning-of-Sentence prediction require two exposures."

* commit '520765491cbfcb8d2e66ee5c492a66eb8a726a74':
  Make Beginning-of-Sentence prediction require two exposures.
main
Keisuke Kuroyanagi 2014-06-26 05:02:15 +00:00 committed by Android Git Automerger
commit 8000869191
3 changed files with 21 additions and 5 deletions

View File

@ -75,7 +75,13 @@ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBas
return;
}
if (null != prevWord) {
userHistoryDictionary.addNgramEntry(prevWordsInfo, word, frequency, timestamp);
if (prevWordsInfo.mIsBeginningOfSentence) {
// Beginning-of-Sentence n-gram entry is treated as a n-gram entry of invalid word.
userHistoryDictionary.addNgramEntry(prevWordsInfo, word,
FREQUENCY_FOR_WORDS_NOT_IN_DICTS, timestamp);
} else {
userHistoryDictionary.addNgramEntry(prevWordsInfo, word, frequency, timestamp);
}
}
}
}

View File

@ -57,6 +57,10 @@ void BigramDictionary::getPredictions(const PrevWordsInfo *const prevWordsInfo,
if (bigramsIt.getBigramPos() == NOT_A_DICT_POS) {
continue;
}
if (prevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */)
&& bigramsIt.getProbability() == NOT_A_PROBABILITY) {
continue;
}
const int codePointCount = mDictionaryStructurePolicy->
getCodePointsAndProbabilityAndReturnCodePointCount(bigramsIt.getBigramPos(),
MAX_WORD_LENGTH, bigramCodePoints, &unigramProbability);

View File

@ -517,15 +517,21 @@ public class InputLogicTests extends InputTestsBase {
suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
}
public void testNoPredictionsAfterPeriod() {
public void testPredictionsAfterPeriod() {
mLatinIME.clearPersonalizedDictionariesForTest();
final String WORD_TO_TYPE = "Barack. ";
type(WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
runMessages();
// Test the first prediction is not displayed
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("no prediction after period", 0, suggestedWords.size());
SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("No prediction after period after inputting once.", 0, suggestedWords.size());
type(WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
runMessages();
suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("Beginning-of-Sentence prediction after inputting 2 times.", "Barack",
suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
}
public void testPredictionsAfterRecorrection() {