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; return;
} }
if (null != prevWord) { if (null != prevWord) {
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); 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) { if (bigramsIt.getBigramPos() == NOT_A_DICT_POS) {
continue; continue;
} }
if (prevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */)
&& bigramsIt.getProbability() == NOT_A_PROBABILITY) {
continue;
}
const int codePointCount = mDictionaryStructurePolicy-> const int codePointCount = mDictionaryStructurePolicy->
getCodePointsAndProbabilityAndReturnCodePointCount(bigramsIt.getBigramPos(), getCodePointsAndProbabilityAndReturnCodePointCount(bigramsIt.getBigramPos(),
MAX_WORD_LENGTH, bigramCodePoints, &unigramProbability); MAX_WORD_LENGTH, bigramCodePoints, &unigramProbability);

View File

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