aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java-overridable/src/com/android/inputmethod/latin/utils/StatsUtils.java6
-rw-r--r--java/res/xml/method.xml4
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java3
-rw-r--r--java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java3
-rw-r--r--java/src/com/android/inputmethod/latin/NgramContext.java16
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java6
-rw-r--r--java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java3
-rw-r--r--java/src/com/android/inputmethod/latin/utils/NgramContextUtils.java14
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/tests/TestsTamilLK.java4
-rw-r--r--tests/src/com/android/inputmethod/latin/InputLogicTests.java59
-rw-r--r--tests/src/com/android/inputmethod/latin/InputTestsBase.java5
-rw-r--r--tests/src/com/android/inputmethod/latin/NgramContextTests.java22
-rw-r--r--tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java8
-rw-r--r--tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java4
14 files changed, 113 insertions, 44 deletions
diff --git a/java-overridable/src/com/android/inputmethod/latin/utils/StatsUtils.java b/java-overridable/src/com/android/inputmethod/latin/utils/StatsUtils.java
index 21a806878..b8f835ee3 100644
--- a/java-overridable/src/com/android/inputmethod/latin/utils/StatsUtils.java
+++ b/java-overridable/src/com/android/inputmethod/latin/utils/StatsUtils.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.latin.utils;
import android.view.inputmethod.InputMethodSubtype;
+import com.android.inputmethod.latin.DictionaryFacilitator;
import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.settings.SettingsValues;
@@ -36,7 +37,8 @@ public final class StatsUtils {
}
public static void onPickSuggestionManually(final SuggestedWords suggestedWords,
- final SuggestedWords.SuggestedWordInfo suggestionInfo) {
+ final SuggestedWords.SuggestedWordInfo suggestionInfo,
+ final DictionaryFacilitator dictionaryFacilitator) {
}
public static void onBackspaceWordDelete(int wordLength) {
@@ -70,7 +72,7 @@ public final class StatsUtils {
}
public static void onAutoCorrection(final String typedWord, final String autoCorrectionWord,
- final boolean isBatchInput, @Nullable final String dictionaryType) {
+ final boolean isBatchInput, final DictionaryFacilitator dictionaryType) {
}
public static void onWordCommitUserTyped(final String commitWord, final boolean isBatchMode) {
diff --git a/java/res/xml/method.xml b/java/res/xml/method.xml
index 33a10fa8f..64929adf1 100644
--- a/java/res/xml/method.xml
+++ b/java/res/xml/method.xml
@@ -626,6 +626,7 @@
/>
<!-- TODO: This Sinhala keyboard is a preliminary layout.
This isn't based on the final specification. -->
+ <!-- si_LK is currently disabled due to lack of combination rules.
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x5c6b3bde"
@@ -634,6 +635,7 @@
android:imeSubtypeExtraValue="KeyboardLayoutSet=sinhala,EmojiCapable"
android:isAsciiCapable="false"
/>
+ -->
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x8e94d413"
@@ -693,6 +695,7 @@
android:isAsciiCapable="false"
/>
<!-- TODO: Enabling/Disabling ta_LK subtype must be aligned with si_LK subtype. -->
+ <!-- ta_LK disabled alongside si_LK subtype due to lack of combination rules.
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x6ca12d84"
@@ -701,6 +704,7 @@
android:imeSubtypeExtraValue="KeyboardLayoutSet=tamil,EmojiCapable"
android:isAsciiCapable="false"
/>
+ !-->
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x785abbd9"
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index daac5b521..7f4631b2d 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -58,7 +58,8 @@ public final class BinaryDictionary extends Dictionary {
// Must be equal to CONFIDENCE_TO_AUTO_COMMIT in native/jni/src/defines.h
private static final int CONFIDENCE_TO_AUTO_COMMIT = 1000000;
- static final int DICTIONARY_MAX_WORD_LENGTH = 48;
+ public static final int DICTIONARY_MAX_WORD_LENGTH = 48;
+ public static final int MAX_PREV_WORD_COUNT_FOR_N_GRAM = 3;
@UsedForTesting
public static final String UNIGRAM_COUNT_QUERY = "UNIGRAM_COUNT";
diff --git a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
index ba0f9b807..15a14e5af 100644
--- a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
@@ -125,7 +125,8 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary
*/
private void addNameLocked(final String name) {
int len = StringUtils.codePointCount(name);
- NgramContext ngramContext = NgramContext.EMPTY_PREV_WORDS_INFO;
+ NgramContext ngramContext = NgramContext.getEmptyPrevWordsContext(
+ BinaryDictionary.MAX_PREV_WORD_COUNT_FOR_N_GRAM);
// TODO: Better tokenization for non-Latin writing systems
for (int i = 0; i < len; i++) {
if (Character.isLetter(name.codePointAt(i))) {
diff --git a/java/src/com/android/inputmethod/latin/NgramContext.java b/java/src/com/android/inputmethod/latin/NgramContext.java
index aeeff6126..9682fb8a4 100644
--- a/java/src/com/android/inputmethod/latin/NgramContext.java
+++ b/java/src/com/android/inputmethod/latin/NgramContext.java
@@ -43,6 +43,10 @@ public class NgramContext {
public static final String CONTEXT_SEPARATOR = " ";
+ public static NgramContext getEmptyPrevWordsContext(int maxPrevWordCount) {
+ return new NgramContext(maxPrevWordCount, WordInfo.EMPTY_WORD_INFO);
+ }
+
/**
* Word information used to represent previous words information.
*/
@@ -102,10 +106,17 @@ public class NgramContext {
private final WordInfo[] mPrevWordsInfo;
private final int mPrevWordsCount;
+ private final int mMaxPrevWordCount;
+
// Construct from the previous word information.
public NgramContext(final WordInfo... prevWordsInfo) {
+ this(DecoderSpecificConstants.MAX_PREV_WORD_COUNT_FOR_N_GRAM, prevWordsInfo);
+ }
+
+ public NgramContext(final int maxPrevWordCount, final WordInfo... prevWordsInfo) {
mPrevWordsInfo = prevWordsInfo;
mPrevWordsCount = prevWordsInfo.length;
+ mMaxPrevWordCount = maxPrevWordCount;
}
/**
@@ -113,12 +124,11 @@ public class NgramContext {
*/
@Nonnull
public NgramContext getNextNgramContext(final WordInfo wordInfo) {
- final int nextPrevWordCount = Math.min(
- DecoderSpecificConstants.MAX_PREV_WORD_COUNT_FOR_N_GRAM, mPrevWordsCount + 1);
+ final int nextPrevWordCount = Math.min(mMaxPrevWordCount, mPrevWordsCount + 1);
final WordInfo[] prevWordsInfo = new WordInfo[nextPrevWordCount];
prevWordsInfo[0] = wordInfo;
System.arraycopy(mPrevWordsInfo, 0, prevWordsInfo, 1, nextPrevWordCount - 1);
- return new NgramContext(prevWordsInfo);
+ return new NgramContext(mMaxPrevWordCount, prevWordsInfo);
}
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index f02a63e57..00175f024 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -324,7 +324,8 @@ public final class InputLogic {
// That's going to be predictions (or punctuation suggestions), so INPUT_STYLE_NONE.
handler.postUpdateSuggestionStrip(SuggestedWords.INPUT_STYLE_NONE);
- StatsUtils.onPickSuggestionManually(mSuggestedWords, suggestionInfo);
+ StatsUtils.onPickSuggestionManually(
+ mSuggestedWords, suggestionInfo, mDictionaryFacilitator);
StatsUtils.onWordCommitSuggestionPickedManually(
suggestionInfo.mWord, mWordComposer.isBatchMode());
return inputTransaction;
@@ -2053,8 +2054,7 @@ public final class InputLogic {
mConnection.getExpectedSelectionEnd() - stringToCommit.length(),
typedWord, stringToCommit));
StatsUtils.onAutoCorrection(typedWord, stringToCommit, isBatchMode,
- null == autoCorrectionOrNull
- ? null : autoCorrectionOrNull.mSourceDict.mDictType);
+ mDictionaryFacilitator);
StatsUtils.onWordCommitAutoCorrect(stringToCommit, isBatchMode);
} else {
StatsUtils.onWordCommitUserTyped(stringToCommit, isBatchMode);
diff --git a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
index 54ee68d65..cbf0829b5 100644
--- a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
@@ -20,6 +20,7 @@ import android.content.Context;
import com.android.inputmethod.annotations.ExternallyReferenced;
import com.android.inputmethod.annotations.UsedForTesting;
+import com.android.inputmethod.latin.BinaryDictionary;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
import com.android.inputmethod.latin.NgramContext;
@@ -98,7 +99,7 @@ public class UserHistoryDictionary extends ExpandableBinaryDictionary {
public static void addToDictionary(final ExpandableBinaryDictionary userHistoryDictionary,
@Nonnull final NgramContext ngramContext, final String word, final boolean isValid,
final int timestamp) {
- if (word.length() > DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH) {
+ if (word.length() > BinaryDictionary.DICTIONARY_MAX_WORD_LENGTH) {
return;
}
userHistoryDictionary.updateEntriesForWord(ngramContext, word,
diff --git a/java/src/com/android/inputmethod/latin/utils/NgramContextUtils.java b/java/src/com/android/inputmethod/latin/utils/NgramContextUtils.java
index 727df1a93..c05ffd693 100644
--- a/java/src/com/android/inputmethod/latin/utils/NgramContextUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/NgramContextUtils.java
@@ -31,6 +31,7 @@ public final class NgramContextUtils {
// Intentional empty constructor for utility class.
}
+ private static final Pattern NEWLINE_REGEX = Pattern.compile("[\\r\\n]+");
private static final Pattern SPACE_REGEX = Pattern.compile("\\s+");
// Get context information from nth word before the cursor. n = 1 retrieves the words
// immediately before the cursor, n = 2 retrieves the words before that, and so on. This splits
@@ -58,7 +59,11 @@ public final class NgramContextUtils {
public static NgramContext getNgramContextFromNthPreviousWord(final CharSequence prev,
final SpacingAndPunctuations spacingAndPunctuations, final int n) {
if (prev == null) return NgramContext.EMPTY_PREV_WORDS_INFO;
- final String[] w = SPACE_REGEX.split(prev);
+ final String[] lines = NEWLINE_REGEX.split(prev);
+ if (lines.length == 0) {
+ return new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO);
+ }
+ final String[] w = SPACE_REGEX.split(lines[lines.length - 1]);
final WordInfo[] prevWordsInfo =
new WordInfo[DecoderSpecificConstants.MAX_PREV_WORD_COUNT_FOR_N_GRAM];
Arrays.fill(prevWordsInfo, WordInfo.EMPTY_WORD_INFO);
@@ -81,16 +86,17 @@ public final class NgramContextUtils {
prevWordsInfo[i] = WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO;
break;
}
+
final String focusedWord = w[focusedWordIndex];
- // If the word is, the context is beginning-of-sentence.
+ // If the word is empty, the context is beginning-of-sentence.
final int length = focusedWord.length();
if (length <= 0) {
prevWordsInfo[i] = WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO;
break;
}
- // If ends in a sentence separator, the context is beginning-of-sentence.
+ // If the word ends in a sentence terminator, the context is beginning-of-sentence.
final char lastChar = focusedWord.charAt(length - 1);
- if (spacingAndPunctuations.isSentenceSeparator(lastChar)) {
+ if (spacingAndPunctuations.isSentenceTerminator(lastChar)) {
prevWordsInfo[i] = WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO;
break;
}
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsTamilLK.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsTamilLK.java
index 6e49c5953..72872ba66 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsTamilLK.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsTamilLK.java
@@ -16,7 +16,7 @@
package com.android.inputmethod.keyboard.layout.tests;
-import android.test.suitebuilder.annotation.SmallTest;
+import android.test.suitebuilder.annotation.Suppress;
import com.android.inputmethod.keyboard.layout.LayoutBase;
import com.android.inputmethod.keyboard.layout.Symbols;
@@ -30,7 +30,7 @@ import java.util.Locale;
/**
* ta_LK: Tamil (Sri Lanka)/tamil
*/
-@SmallTest
+@Suppress
public final class TestsTamilLK extends LayoutTestsBase {
private static final Locale LOCALE = new Locale("ta", "LK");
private static final LayoutBase LAYOUT = new Tamil(new TamilLKCustomizer(LOCALE));
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
index b1b48135f..eb94e2266 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
@@ -16,17 +16,33 @@
package com.android.inputmethod.latin;
-import android.test.MoreAsserts;
+import static android.test.MoreAsserts.assertNotEqual;
+
import android.test.suitebuilder.annotation.LargeTest;
import android.text.TextUtils;
import android.view.inputmethod.BaseInputConnection;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.define.DecoderSpecificConstants;
import com.android.inputmethod.latin.settings.Settings;
@LargeTest
public class InputLogicTests extends InputTestsBase {
+ private boolean mNextWordPrediction;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ mNextWordPrediction = getBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, true);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, mNextWordPrediction, true);
+ super.tearDown();
+ }
+
public void testTypeWord() {
final String WORD_TO_TYPE = "abcd";
type(WORD_TO_TYPE);
@@ -494,24 +510,19 @@ public class InputLogicTests extends InputTestsBase {
public void testPredictionsWithDoubleSpaceToPeriod() {
mLatinIME.clearPersonalizedDictionariesForTest();
- final String WORD_TO_TYPE = "Barack ";
+ final String WORD_TO_TYPE = "Barack ";
type(WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
- // No need to test here, testPredictionsAfterSpace is testing it already
- type(" ");
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
- runMessages();
- // Test the predictions have been cleared
- SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
- assertEquals("predictions cleared after double-space-to-period", suggestedWords.size(), 0);
+
type(Constants.CODE_DELETE);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
- // Test the first prediction is displayed
+
+ SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("predictions after cancel double-space-to-period", "Obama",
- suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
+ mLatinIME.getSuggestedWordsForTest().getWord(0));
}
public void testPredictionsAfterManualPick() {
@@ -533,15 +544,9 @@ public class InputLogicTests extends InputTestsBase {
type(WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
- 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_MILLIS);
- runMessages();
- suggestedWords = mLatinIME.getSuggestedWordsForTest();
- assertEquals("Beginning-of-Sentence prediction after inputting 2 times.", "Barack",
- suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
+ SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
+ assertFalse(mLatinIME.getSuggestedWordsForTest().isEmpty());
}
public void testPredictionsAfterRecorrection() {
@@ -668,8 +673,11 @@ public class InputLogicTests extends InputTestsBase {
type(Constants.CODE_DELETE);
assertEquals("gesture then backspace", "", mEditText.getText().toString());
gesture("this");
- MoreAsserts.assertNotEqual("gesture twice the same thing", "this",
- mEditText.getText().toString());
+ if (DecoderSpecificConstants.SHOULD_REMOVE_PREVIOUSLY_REJECTED_SUGGESTION) {
+ assertNotEqual("this", mEditText.getText().toString());
+ } else {
+ assertEquals("this", mEditText.getText().toString());
+ }
}
private void typeOrGestureWordAndPutCursorInside(final boolean gesture, final String word,
@@ -736,12 +744,13 @@ public class InputLogicTests extends InputTestsBase {
ensureComposingSpanPos("space while in the middle of a word cancels composition", -1, -1);
}
+ // TODO: Verify this works when we return FIGS language models to the APK.
public void testAutoCorrectForFrench() {
final String STRING_TO_TYPE = "irq ";
- final String EXPECTED_RESULT = "ira ";
- changeLanguage("fr");
+ final String EXPECTED_RESULT = "ir a ";
+ changeLanguage("es");
type(STRING_TO_TYPE);
- assertEquals("simple auto-correct for French", EXPECTED_RESULT,
+ assertEquals("simple auto-correct for Spanish", EXPECTED_RESULT,
mEditText.getText().toString());
}
@@ -771,6 +780,8 @@ public class InputLogicTests extends InputTestsBase {
}
public void testWordThenSpaceThenPunctuationFromStripTwiceForFrench() {
+ setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, false, true);
+
final String WORD_TO_TYPE = "test ";
final String PUNCTUATION_FROM_STRIP = "!";
final String EXPECTED_RESULT = "test !!";
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
index 6ae38c615..ab4060a86 100644
--- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
@@ -164,6 +164,11 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
return previousSetting;
}
+ protected boolean getBooleanPreference(final String key, final boolean defaultValue) {
+ return PreferenceManager.getDefaultSharedPreferences(mLatinIME)
+ .getBoolean(key, defaultValue);
+ }
+
protected String setStringPreference(final String key, final String value,
final String defaultValue) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mLatinIME);
diff --git a/tests/src/com/android/inputmethod/latin/NgramContextTests.java b/tests/src/com/android/inputmethod/latin/NgramContextTests.java
index 7749bff63..0a662db82 100644
--- a/tests/src/com/android/inputmethod/latin/NgramContextTests.java
+++ b/tests/src/com/android/inputmethod/latin/NgramContextTests.java
@@ -17,6 +17,8 @@
package com.android.inputmethod.latin;
import com.android.inputmethod.latin.NgramContext.WordInfo;
+import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
+import com.android.inputmethod.latin.utils.NgramContextUtils;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
@@ -120,4 +122,24 @@ public class NgramContextTests extends AndroidTestCase {
assertEquals(1, ngramContext_a_empty.extractPrevWordsContextArray().length);
assertEquals("a", ngramContext_a_empty.extractPrevWordsContextArray()[0]);
}
+
+ public void testGetNgramContextFromNthPreviousWord() {
+ SpacingAndPunctuations spacingAndPunctuations = new SpacingAndPunctuations(
+ mContext.getResources());
+ assertEquals("<S>", NgramContextUtils.getNgramContextFromNthPreviousWord("",
+ spacingAndPunctuations, 1).extractPrevWordsContext());
+ assertEquals("<S> b", NgramContextUtils.getNgramContextFromNthPreviousWord("a. b ",
+ spacingAndPunctuations, 1).extractPrevWordsContext());
+ assertEquals("<S> b", NgramContextUtils.getNgramContextFromNthPreviousWord("a? b ",
+ spacingAndPunctuations, 1).extractPrevWordsContext());
+ assertEquals("<S> b", NgramContextUtils.getNgramContextFromNthPreviousWord("a! b ",
+ spacingAndPunctuations, 1).extractPrevWordsContext());
+ assertEquals("<S> b", NgramContextUtils.getNgramContextFromNthPreviousWord("a\nb ",
+ spacingAndPunctuations, 1).extractPrevWordsContext());
+ assertEquals("<S> a b", NgramContextUtils.getNgramContextFromNthPreviousWord("a b ",
+ spacingAndPunctuations, 1).extractPrevWordsContext());
+ assertFalse(NgramContextUtils
+ .getNgramContextFromNthPreviousWord("a b c d e", spacingAndPunctuations, 1)
+ .extractPrevWordsContext().startsWith("<S>"));
+ }
}
diff --git a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java
index 8614ccc0e..08779b9d3 100644
--- a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java
+++ b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java
@@ -206,10 +206,14 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
"abc def .", mSpacingAndPunctuations, 1), NgramContext.BEGINNING_OF_SENTENCE);
assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord(
"abc, def", mSpacingAndPunctuations, 2), NgramContext.EMPTY_PREV_WORDS_INFO);
+ // question mark is treated as the end of the sentence. Hence, beginning of the
+ // sentence is expected.
assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord(
- "abc? def", mSpacingAndPunctuations, 2), NgramContext.EMPTY_PREV_WORDS_INFO);
+ "abc? def", mSpacingAndPunctuations, 2), NgramContext.BEGINNING_OF_SENTENCE);
+ // Exclamation mark is treated as the end of the sentence. Hence, beginning of the
+ // sentence is expected.
assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord(
- "abc! def", mSpacingAndPunctuations, 2), NgramContext.EMPTY_PREV_WORDS_INFO);
+ "abc! def", mSpacingAndPunctuations, 2), NgramContext.BEGINNING_OF_SENTENCE);
assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord(
"abc 'def", mSpacingAndPunctuations, 2), NgramContext.EMPTY_PREV_WORDS_INFO);
}
diff --git a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java
index 94105aa12..4b7b9bc36 100644
--- a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java
+++ b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.latin.personalization;
import android.content.Context;
+import com.android.inputmethod.latin.BinaryDictionary;
import com.android.inputmethod.latin.NgramContext;
import com.android.inputmethod.latin.NgramContext.WordInfo;
import com.android.inputmethod.latin.common.FileUtils;
@@ -98,7 +99,8 @@ public class UserHistoryDictionaryTestsHelper {
private static void addWordsToDictionary(final UserHistoryDictionary dict,
final List<String> words, final int timestamp) {
- NgramContext ngramContext = NgramContext.EMPTY_PREV_WORDS_INFO;
+ NgramContext ngramContext = NgramContext.getEmptyPrevWordsContext(
+ BinaryDictionary.MAX_PREV_WORD_COUNT_FOR_N_GRAM);
for (final String word : words) {
UserHistoryDictionary.addToDictionary(dict, ngramContext, word, true, timestamp);
ngramContext = ngramContext.getNextNgramContext(new WordInfo(word));