aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Paraskevov <paraskevov@google.com>2015-04-15 16:41:51 -0700
committerMartin Paraskevov <paraskevov@google.com>2015-04-15 19:00:45 -0700
commit8ff42d158193001b3abdd13c768f693c532be8aa (patch)
treea9059ba9517a16d33c37ff0b08c796f76947fde0
parent40f0f61bb365b5073f1d9fdb56a393c5df5ef4b0 (diff)
downloadlatinime-8ff42d158193001b3abdd13c768f693c532be8aa.tar.gz
latinime-8ff42d158193001b3abdd13c768f693c532be8aa.tar.xz
latinime-8ff42d158193001b3abdd13c768f693c532be8aa.zip
Strip quotes from begining/end of a word before checking its validity.
Bug: 20142633 Change-Id: Ia0f3661ac3028473c00f83df72dcb9e1fd134247
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java21
1 files changed, 13 insertions, 8 deletions
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java
index fd5c54c09..d6de94532 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java
@@ -58,6 +58,9 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
protected final SuggestionsCache mSuggestionsCache = new SuggestionsCache();
private final ContentObserver mObserver;
+ private static final String quotesRegexp =
+ "\\u0022|\\u0027|\\u0060|\\u00B4|\\u2018|\\u2018|\\u201C|\\u201D";
+
private static final class SuggestionsParams {
public final String[] mSuggestions;
public final int mFlags;
@@ -224,12 +227,16 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
protected SuggestionsInfo onGetSuggestionsInternal(
final TextInfo textInfo, final NgramContext ngramContext, final int suggestionsLimit) {
try {
- final String inText = textInfo.getText();
+ final String text = textInfo.getText().
+ replaceAll(AndroidSpellCheckerService.APOSTROPHE,
+ AndroidSpellCheckerService.SINGLE_QUOTE).
+ replaceAll("^" + quotesRegexp, "").
+ replaceAll(quotesRegexp + "$", "");
final SuggestionsParams cachedSuggestionsParams =
- mSuggestionsCache.getSuggestionsFromCache(inText, ngramContext);
+ mSuggestionsCache.getSuggestionsFromCache(text, ngramContext);
if (cachedSuggestionsParams != null) {
- Log.d(TAG, "onGetSuggestionsInternal() : Cache hit for [" + inText + "]");
+ Log.d(TAG, "onGetSuggestionsInternal() : Cache hit for [" + text + "]");
return new SuggestionsInfo(
cachedSuggestionsParams.mFlags, cachedSuggestionsParams.mSuggestions);
}
@@ -241,10 +248,10 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
}
// Handle special patterns like email, URI, telephone number.
- final int checkability = getCheckabilityInScript(inText, mScript);
+ final int checkability = getCheckabilityInScript(text, mScript);
if (CHECKABILITY_CHECKABLE != checkability) {
if (CHECKABILITY_CONTAINS_PERIOD == checkability) {
- final String[] splitText = inText.split(Constants.REGEXP_PERIOD);
+ final String[] splitText = text.split(Constants.REGEXP_PERIOD);
boolean allWordsAreValid = true;
for (final String word : splitText) {
if (!mService.isValidWord(mLocale, word)) {
@@ -259,15 +266,13 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
TextUtils.join(Constants.STRING_SPACE, splitText) });
}
}
- return mService.isValidWord(mLocale, inText) ?
+ return mService.isValidWord(mLocale, text) ?
AndroidSpellCheckerService.getInDictEmptySuggestions() :
AndroidSpellCheckerService.getNotInDictEmptySuggestions(
CHECKABILITY_CONTAINS_PERIOD == checkability /* reportAsTypo */);
}
// Handle normal words.
- final String text = inText.replaceAll(
- AndroidSpellCheckerService.APOSTROPHE, AndroidSpellCheckerService.SINGLE_QUOTE);
final int capitalizeType = StringUtils.getCapitalizationType(text);
if (isInDictForAnyCapitalization(text, capitalizeType)) {