From ca17ed7d9dcafd15d79da04f8c0ba6cdf6f0dde4 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Mon, 6 Oct 2014 19:28:39 +0900 Subject: [PATCH] Fix: BoS prediction is shown after inputting just once. Change-Id: Ibba209f47cb5b1a4b08281689d607711b8dcfad4 --- .../structure/backward/v402/ver4_patricia_trie_policy.cpp | 5 ++++- .../inputmethod/latin/BinaryDictionaryDecayingTests.java | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp index 11f7b305f..cb07cbdad 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp @@ -428,7 +428,10 @@ bool Ver4PatriciaTriePolicy::updateCounter(const PrevWordsInfo *const prevWordsI AKLOGE("Cannot update unigarm entry in updateCounter()."); return false; } - const NgramProperty ngramProperty(wordCodePoints.toVector(), probability, historicalInfo); + const int probabilityForNgram = prevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */) + ? NOT_A_PROBABILITY : probability; + const NgramProperty ngramProperty(wordCodePoints.toVector(), probabilityForNgram, + historicalInfo); if (!addNgramEntry(prevWordsInfo, &ngramProperty)) { AKLOGE("Cannot update unigarm entry in updateCounter()."); return false; diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java index c3c2bb2fd..cbfbab926 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java @@ -611,6 +611,7 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { mCurrentTime); final NgramContext beginningOfSentenceContext = NgramContext.BEGINNING_OF_SENTENCE; onInputWordWithBeginningOfSentenceContext(binaryDictionary, "aaa", true /* isValidWord */); + onInputWordWithBeginningOfSentenceContext(binaryDictionary, "aaa", true /* isValidWord */); assertTrue(binaryDictionary.isValidNgram(beginningOfSentenceContext, "aaa")); onInputWordWithBeginningOfSentenceContext(binaryDictionary, "aaa", true /* isValidWord */); onInputWordWithBeginningOfSentenceContext(binaryDictionary, "bbb", true /* isValidWord */); @@ -622,6 +623,8 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { assertFalse(binaryDictionary.isValidNgram(beginningOfSentenceContext, "bbb")); onInputWordWithBeginningOfSentenceContext(binaryDictionary, "aaa", true /* isValidWord */); + onInputWordWithBeginningOfSentenceContext(binaryDictionary, "aaa", true /* isValidWord */); + onInputWordWithBeginningOfSentenceContext(binaryDictionary, "bbb", true /* isValidWord */); onInputWordWithBeginningOfSentenceContext(binaryDictionary, "bbb", true /* isValidWord */); assertTrue(binaryDictionary.isValidNgram(beginningOfSentenceContext, "aaa")); assertTrue(binaryDictionary.isValidNgram(beginningOfSentenceContext, "bbb"));