From 1bfd7be2080f97d15b57ec1cac0dba1f1f2ca23d Mon Sep 17 00:00:00 2001 From: Jatin Matani Date: Mon, 13 Apr 2015 15:26:48 -0700 Subject: Store raw strings for personal dictionary The raw strings would be sent to personal LM for decoding. Earlier lowercased strings were being used with the purpose of isValid checks (spelling does not consider casing for spell checking calls). But for showing these in suggestion, we need the raw strings. Note: PersonalDictionaryLookup#getWordsForLocale is used to feed the personal LM in PersonalLanguageModelHelper. Bug:20152986 Change-Id: I9d796fa57bf2073036bf11d86b143ff205a6199c --- .../latin/PersonalDictionaryLookupTest.java | 40 +++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'tests/src') diff --git a/tests/src/com/android/inputmethod/latin/PersonalDictionaryLookupTest.java b/tests/src/com/android/inputmethod/latin/PersonalDictionaryLookupTest.java index 983957fd4..c06adedfd 100644 --- a/tests/src/com/android/inputmethod/latin/PersonalDictionaryLookupTest.java +++ b/tests/src/com/android/inputmethod/latin/PersonalDictionaryLookupTest.java @@ -289,7 +289,8 @@ public class PersonalDictionaryLookupTest extends AndroidTestCase { addWord("fOo", Locale.FRENCH, 17, null); // Create the PersonalDictionaryLookup and wait until it's loaded. - PersonalDictionaryLookup lookup = new PersonalDictionaryLookup(mContext, ExecutorUtils.SPELLING); + PersonalDictionaryLookup lookup = new PersonalDictionaryLookup(mContext, + ExecutorUtils.SPELLING); lookup.open(); // Both en_CA and en_US match. @@ -304,6 +305,43 @@ public class PersonalDictionaryLookupTest extends AndroidTestCase { lookup.close(); } + + public void testCaseMatchingForWordsAndShortcuts() { + Log.d(TAG, "testCaseMatchingForWordsAndShortcuts"); + addWord("Foo", Locale.US, 17, "f"); + addWord("bokabu", Locale.US, 17, "Bu"); + + // Create the PersonalDictionaryLookup and wait until it's loaded. + PersonalDictionaryLookup lookup = new PersonalDictionaryLookup(mContext, + ExecutorUtils.SPELLING); + lookup.open(); + + // Valid, inspite of capitalization in US but not in other + // locales. + assertTrue(lookup.isValidWord("Foo", Locale.US)); + assertTrue(lookup.isValidWord("foo", Locale.US)); + assertFalse(lookup.isValidWord("Foo", Locale.UK)); + assertFalse(lookup.isValidWord("foo", Locale.UK)); + + // Valid in all forms in US. + assertTrue(lookup.isValidWord("bokabu", Locale.US)); + assertTrue(lookup.isValidWord("BOKABU", Locale.US)); + assertTrue(lookup.isValidWord("BokaBU", Locale.US)); + + // Correct capitalization; sensitive to shortcut casing & locale. + assertEquals("Foo", lookup.expandShortcut("f", Locale.US)); + assertNull(lookup.expandShortcut("f", Locale.UK)); + + // Correct capitalization; sensitive to shortcut casing & locale. + assertEquals("bokabu", lookup.expandShortcut("Bu", Locale.US)); + assertNull(lookup.expandShortcut("Bu", Locale.UK)); + assertNull(lookup.expandShortcut("bu", Locale.US)); + + // Verify that raw strings are retained for #getWordsForLocale. + verifyWordExists(lookup.getWordsForLocale(Locale.US), "Foo"); + verifyWordDoesNotExist(lookup.getWordsForLocale(Locale.US), "foo"); + } + public void testManageListeners() { Log.d(TAG, "testManageListeners"); -- cgit v1.2.3-83-g751a