diff options
Diffstat (limited to 'java/src')
16 files changed, 128 insertions, 68 deletions
diff --git a/java/src/com/android/inputmethod/dictionarypack/DownloadManagerWrapper.java b/java/src/com/android/inputmethod/dictionarypack/DownloadManagerWrapper.java index 75cc7d4cb..3dbbc9b9b 100644 --- a/java/src/com/android/inputmethod/dictionarypack/DownloadManagerWrapper.java +++ b/java/src/com/android/inputmethod/dictionarypack/DownloadManagerWrapper.java @@ -54,15 +54,13 @@ public class DownloadManagerWrapper { if (null != mDownloadManager) { mDownloadManager.remove(ids); } + } catch (IllegalArgumentException e) { + // This is expected to happen on boot when the device is encrypted. } catch (SQLiteException e) { // We couldn't remove the file from DownloadManager. Apparently, the database can't // be opened. It may be a problem with file system corruption. In any case, there is // not much we can do apart from avoiding crashing. Log.e(TAG, "Can't remove files with ID " + ids + " from download manager", e); - } catch (IllegalArgumentException e) { - // Not sure how this can happen, but it could be another case where the provider - // is disabled. Or it could be a bug in older versions of the framework. - Log.e(TAG, "Can't find the content URL for DownloadManager?", e); } } @@ -71,10 +69,10 @@ public class DownloadManagerWrapper { if (null != mDownloadManager) { return mDownloadManager.openDownloadedFile(fileId); } + } catch (IllegalArgumentException e) { + // This is expected to happen on boot when the device is encrypted. } catch (SQLiteException e) { Log.e(TAG, "Can't open downloaded file with ID " + fileId, e); - } catch (IllegalArgumentException e) { - Log.e(TAG, "Can't find the content URL for DownloadManager?", e); } // We come here if mDownloadManager is null or if an exception was thrown. throw new FileNotFoundException(); @@ -85,10 +83,10 @@ public class DownloadManagerWrapper { if (null != mDownloadManager) { return mDownloadManager.query(query); } + } catch (IllegalArgumentException e) { + // This is expected to happen on boot when the device is encrypted. } catch (SQLiteException e) { Log.e(TAG, "Can't query the download manager", e); - } catch (IllegalArgumentException e) { - Log.e(TAG, "Can't find the content URL for DownloadManager?", e); } // We come here if mDownloadManager is null or if an exception was thrown. return null; @@ -99,10 +97,10 @@ public class DownloadManagerWrapper { if (null != mDownloadManager) { return mDownloadManager.enqueue(request); } + } catch (IllegalArgumentException e) { + // This is expected to happen on boot when the device is encrypted. } catch (SQLiteException e) { Log.e(TAG, "Can't enqueue a request with the download manager", e); - } catch (IllegalArgumentException e) { - Log.e(TAG, "Can't find the content URL for DownloadManager?", e); } return 0; } diff --git a/java/src/com/android/inputmethod/keyboard/TextDecorator.java b/java/src/com/android/inputmethod/keyboard/TextDecorator.java index 315d36313..6e4e3281e 100644 --- a/java/src/com/android/inputmethod/keyboard/TextDecorator.java +++ b/java/src/com/android/inputmethod/keyboard/TextDecorator.java @@ -49,7 +49,7 @@ public class TextDecorator { private int mMode = MODE_MONITOR; private String mLastComposingText = null; - private RectF mIndicatorBoundsForLastComposingText = new RectF(); + private boolean mHasRtlCharsInLastComposingText = false; private RectF mComposingTextBoundsForLastComposingText = new RectF(); private boolean mIsFullScreenMode = false; @@ -241,20 +241,8 @@ public class TextDecorator { right = Math.max(characterBounds.right, right); } mLastComposingText = composingTextString; + mHasRtlCharsInLastComposingText = useRtlLayout; mComposingTextBoundsForLastComposingText.set(left, top, right, bottom); - // The height and width of the indicator is the same as the height of the composing - // text. - final float indicatorSize = bottom - top; - mIndicatorBoundsForLastComposingText.set(0.0f, 0.0f, indicatorSize, indicatorSize); - // The horizontal position of the indicator depends on the text direction. - final float indicatorTop = top; - final float indicatorLeft; - if (useRtlLayout) { - indicatorLeft = left - indicatorSize; - } else { - indicatorLeft = right; - } - mIndicatorBoundsForLastComposingText.offset(indicatorLeft, indicatorTop); } final int selectionStart = info.getSelectionStart(); @@ -295,8 +283,8 @@ public class TextDecorator { return; } - mUiOperator.layoutUi(matrix, mIndicatorBoundsForLastComposingText, - mComposingTextBoundsForLastComposingText); + mUiOperator.layoutUi(matrix, mComposingTextBoundsForLastComposingText, + mHasRtlCharsInLastComposingText); } private void onClickIndicator() { @@ -374,7 +362,7 @@ public class TextDecorator { public void setOnClickListener(Runnable listener) { } @Override - public void layoutUi(Matrix matrix, RectF indicatorBounds, RectF composingTextBounds) { + public void layoutUi(Matrix matrix, RectF composingTextBounds, boolean useRtlLayout) { } }; } diff --git a/java/src/com/android/inputmethod/keyboard/TextDecoratorUi.java b/java/src/com/android/inputmethod/keyboard/TextDecoratorUi.java index b67d17789..d87dc1bfa 100644 --- a/java/src/com/android/inputmethod/keyboard/TextDecoratorUi.java +++ b/java/src/com/android/inputmethod/keyboard/TextDecoratorUi.java @@ -26,6 +26,7 @@ import android.graphics.Path; import android.graphics.RectF; import android.graphics.drawable.ColorDrawable; import android.inputmethodservice.InputMethodService; +import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.Gravity; import android.view.View; @@ -50,6 +51,7 @@ public final class TextDecoratorUi implements TextDecoratorUiOperator { private final PopupWindow mTouchEventWindow; private final View mTouchEventWindowClickListenerView; private final float mHitAreaMarginInPixels; + private final RectF mDisplayRect; /** * This constructor is designed to be called from {@link InputMethodService#setInputView(View)}. @@ -64,6 +66,9 @@ public final class TextDecoratorUi implements TextDecoratorUiOperator { R.integer.text_decorator_hit_area_margin_in_dp); mHitAreaMarginInPixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, hitAreaMarginInDP, resources.getDisplayMetrics()); + final DisplayMetrics displayMetrics = resources.getDisplayMetrics(); + mDisplayRect = new RectF(0.0f, 0.0f, displayMetrics.widthPixels, + displayMetrics.heightPixels); mLocalRootView = new RelativeLayout(context); mLocalRootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, @@ -111,17 +116,40 @@ public final class TextDecoratorUi implements TextDecoratorUiOperator { mTouchEventWindow.dismiss(); } + private static final RectF getIndicatorBoundsInScreenCoordinates(final Matrix matrix, + final RectF composingTextBounds, final boolean showAtLeftSide) { + final float indicatorSize = composingTextBounds.height(); + final RectF indicatorBounds; + if (showAtLeftSide) { + indicatorBounds = new RectF(composingTextBounds.left - indicatorSize, + composingTextBounds.top, composingTextBounds.left, + composingTextBounds.top + indicatorSize); + } else { + indicatorBounds = new RectF(composingTextBounds.right, composingTextBounds.top, + composingTextBounds.right + indicatorSize, + composingTextBounds.top + indicatorSize); + } + matrix.mapRect(indicatorBounds); + return indicatorBounds; + } + @Override - public void layoutUi(final Matrix matrix, final RectF indicatorBounds, - final RectF composingTextBounds) { - final RectF indicatorBoundsInScreenCoordinates = new RectF(); - matrix.mapRect(indicatorBoundsInScreenCoordinates, indicatorBounds); + public void layoutUi(final Matrix matrix, final RectF composingTextBounds, + final boolean useRtlLayout) { + RectF indicatorBoundsInScreenCoordinates = getIndicatorBoundsInScreenCoordinates(matrix, + composingTextBounds, useRtlLayout /* showAtLeftSide */); + if (indicatorBoundsInScreenCoordinates.left < mDisplayRect.left || + mDisplayRect.right < indicatorBoundsInScreenCoordinates.right) { + // The indicator is clipped by the screen. Show the indicator at the opposite side. + indicatorBoundsInScreenCoordinates = getIndicatorBoundsInScreenCoordinates(matrix, + composingTextBounds, !useRtlLayout /* showAtLeftSide */); + } + mAddToDictionaryIndicatorView.setBounds(indicatorBoundsInScreenCoordinates); - final RectF hitAreaBounds = new RectF(composingTextBounds); - hitAreaBounds.union(indicatorBounds); final RectF hitAreaBoundsInScreenCoordinates = new RectF(); - matrix.mapRect(hitAreaBoundsInScreenCoordinates, hitAreaBounds); + matrix.mapRect(hitAreaBoundsInScreenCoordinates, composingTextBounds); + hitAreaBoundsInScreenCoordinates.union(indicatorBoundsInScreenCoordinates); hitAreaBoundsInScreenCoordinates.inset(-mHitAreaMarginInPixels, -mHitAreaMarginInPixels); final int[] originScreen = new int[2]; diff --git a/java/src/com/android/inputmethod/keyboard/TextDecoratorUiOperator.java b/java/src/com/android/inputmethod/keyboard/TextDecoratorUiOperator.java index 9c0b64ad4..9e30e417e 100644 --- a/java/src/com/android/inputmethod/keyboard/TextDecoratorUiOperator.java +++ b/java/src/com/android/inputmethod/keyboard/TextDecoratorUiOperator.java @@ -17,7 +17,6 @@ package com.android.inputmethod.keyboard; import android.graphics.Matrix; -import android.graphics.PointF; import android.graphics.RectF; /** @@ -45,9 +44,8 @@ public interface TextDecoratorUiOperator { /** * Called when the layout should be updated. * @param matrix The matrix that transforms the local coordinates into the screen coordinates. - * @param indicatorBounds The bounding box of the indicator, in local coordinates. * @param composingTextBounds The bounding box of the composing text, in local coordinates. + * @param useRtlLayout {@code true} if the indicator should be optimized for RTL layout. */ - void layoutUi(final Matrix matrix, final RectF indicatorBounds, - final RectF composingTextBounds); + void layoutUi(final Matrix matrix, final RectF composingTextBounds, final boolean useRtlLayout); } diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 2ae54348a..9bca0bf35 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -188,7 +188,8 @@ public final class BinaryDictionary extends Dictionary { int[][] prevWordCodePointArrays, boolean[] isBeginningOfSentenceArray, int prevWordCount, int[] outputSuggestionCount, int[] outputCodePoints, int[] outputScores, int[] outputIndices, int[] outputTypes, - int[] outputAutoCommitFirstWordConfidence, float[] inOutLanguageWeight); + int[] outputAutoCommitFirstWordConfidence, + float[] inOutWeightOfLangModelVsSpatialModel); private static native boolean addUnigramEntryNative(long dict, int[] word, int probability, int[] shortcutTarget, int shortcutProbability, boolean isBeginningOfSentence, boolean isNotAWord, boolean isBlacklisted, int timestamp); @@ -256,7 +257,8 @@ public final class BinaryDictionary extends Dictionary { public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer, final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo, final SettingsValuesForSuggestion settingsValuesForSuggestion, - final int sessionId, final float[] inOutLanguageWeight) { + final int sessionId, final float weightForLocale, + final float[] inOutWeightOfLangModelVsSpatialModel) { if (!isValidDictionary()) { return null; } @@ -284,10 +286,12 @@ public final class BinaryDictionary extends Dictionary { settingsValuesForSuggestion.mSpaceAwareGestureEnabled); session.mNativeSuggestOptions.setAdditionalFeaturesOptions( settingsValuesForSuggestion.mAdditionalFeaturesSettingValues); - if (inOutLanguageWeight != null) { - session.mInputOutputLanguageWeight[0] = inOutLanguageWeight[0]; + if (inOutWeightOfLangModelVsSpatialModel != null) { + session.mInputOutputWeightOfLangModelVsSpatialModel[0] = + inOutWeightOfLangModelVsSpatialModel[0]; } else { - session.mInputOutputLanguageWeight[0] = Dictionary.NOT_A_LANGUAGE_WEIGHT; + session.mInputOutputWeightOfLangModelVsSpatialModel[0] = + Dictionary.NOT_A_WEIGHT_OF_LANG_MODEL_VS_SPATIAL_MODEL; } // TOOD: Pass multiple previous words information for n-gram. getSuggestionsNative(mNativeDict, proximityInfo.getNativeProximityInfo(), @@ -298,9 +302,11 @@ public final class BinaryDictionary extends Dictionary { session.mIsBeginningOfSentenceArray, prevWordsInfo.getPrevWordCount(), session.mOutputSuggestionCount, session.mOutputCodePoints, session.mOutputScores, session.mSpaceIndices, session.mOutputTypes, - session.mOutputAutoCommitFirstWordConfidence, session.mInputOutputLanguageWeight); - if (inOutLanguageWeight != null) { - inOutLanguageWeight[0] = session.mInputOutputLanguageWeight[0]; + session.mOutputAutoCommitFirstWordConfidence, + session.mInputOutputWeightOfLangModelVsSpatialModel); + if (inOutWeightOfLangModelVsSpatialModel != null) { + inOutWeightOfLangModelVsSpatialModel[0] = + session.mInputOutputWeightOfLangModelVsSpatialModel[0]; } final int count = session.mOutputSuggestionCount[0]; final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<>(); @@ -314,7 +320,8 @@ public final class BinaryDictionary extends Dictionary { if (len > 0) { suggestions.add(new SuggestedWordInfo( new String(session.mOutputCodePoints, start, len), - session.mOutputScores[j], session.mOutputTypes[j], this /* sourceDict */, + (int)(session.mOutputScores[j] * weightForLocale), session.mOutputTypes[j], + this /* sourceDict */, session.mSpaceIndices[j] /* indexOfTouchPointOfSecondWord */, session.mOutputAutoCommitFirstWordConfidence[0])); } @@ -483,6 +490,7 @@ public final class BinaryDictionary extends Dictionary { return true; } + @UsedForTesting public void addMultipleDictionaryEntries(final LanguageModelParam[] languageModelParams) { if (!isValidDictionary()) return; int processedParamCount = 0; diff --git a/java/src/com/android/inputmethod/latin/DicTraverseSession.java b/java/src/com/android/inputmethod/latin/DicTraverseSession.java index b341f623e..2751c1250 100644 --- a/java/src/com/android/inputmethod/latin/DicTraverseSession.java +++ b/java/src/com/android/inputmethod/latin/DicTraverseSession.java @@ -40,7 +40,7 @@ public final class DicTraverseSession { public final int[] mOutputTypes = new int[MAX_RESULTS]; // Only one result is ever used public final int[] mOutputAutoCommitFirstWordConfidence = new int[1]; - public final float[] mInputOutputLanguageWeight = new float[1]; + public final float[] mInputOutputWeightOfLangModelVsSpatialModel = new float[1]; public final NativeSuggestOptions mNativeSuggestOptions = new NativeSuggestOptions(); diff --git a/java/src/com/android/inputmethod/latin/Dictionary.java b/java/src/com/android/inputmethod/latin/Dictionary.java index cad9ee7d8..b58a52b41 100644 --- a/java/src/com/android/inputmethod/latin/Dictionary.java +++ b/java/src/com/android/inputmethod/latin/Dictionary.java @@ -31,7 +31,7 @@ import java.util.HashSet; */ public abstract class Dictionary { public static final int NOT_A_PROBABILITY = -1; - public static final float NOT_A_LANGUAGE_WEIGHT = -1.0f; + public static final float NOT_A_WEIGHT_OF_LANG_MODEL_VS_SPATIAL_MODEL = -1.0f; // The following types do not actually come from real dictionary instances, so we create // corresponding instances. @@ -88,15 +88,18 @@ public abstract class Dictionary { * @param proximityInfo the object for key proximity. May be ignored by some implementations. * @param settingsValuesForSuggestion the settings values used for the suggestion. * @param sessionId the session id. - * @param inOutLanguageWeight the language weight used for generating suggestions. - * inOutLanguageWeight is a float array that has only one element. This can be updated when the - * different language weight is used. + * @param weightForLocale the weight given to this locale, to multiply the output scores for + * multilingual input. + * @param inOutWeightOfLangModelVsSpatialModel the weight of the language model as a ratio of + * the spatial model, used for generating suggestions. inOutWeightOfLangModelVsSpatialModel is + * a float array that has only one element. This can be updated when a different value is used. * @return the list of suggestions (possibly null if none) */ abstract public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer, final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo, final SettingsValuesForSuggestion settingsValuesForSuggestion, - final int sessionId, final float[] inOutLanguageWeight); + final int sessionId, final float weightForLocale, + final float[] inOutWeightOfLangModelVsSpatialModel); /** * Checks if the given word has to be treated as a valid word. Please note that some @@ -190,7 +193,8 @@ public abstract class Dictionary { public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer, final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo, final SettingsValuesForSuggestion settingsValuesForSuggestion, - final int sessionId, final float[] inOutLanguageWeight) { + final int sessionId, final float weightForLocale, + final float[] inOutWeightOfLangModelVsSpatialModel) { return null; } diff --git a/java/src/com/android/inputmethod/latin/DictionaryCollection.java b/java/src/com/android/inputmethod/latin/DictionaryCollection.java index ca5e93714..b26b37817 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryCollection.java +++ b/java/src/com/android/inputmethod/latin/DictionaryCollection.java @@ -62,20 +62,21 @@ public final class DictionaryCollection extends Dictionary { public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer, final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo, final SettingsValuesForSuggestion settingsValuesForSuggestion, - final int sessionId, final float[] inOutLanguageWeight) { + final int sessionId, final float weightForLocale, + final float[] inOutWeightOfLangModelVsSpatialModel) { final CopyOnWriteArrayList<Dictionary> dictionaries = mDictionaries; if (dictionaries.isEmpty()) return null; // To avoid creating unnecessary objects, we get the list out of the first // dictionary and add the rest to it if not null, hence the get(0) ArrayList<SuggestedWordInfo> suggestions = dictionaries.get(0).getSuggestions(composer, prevWordsInfo, proximityInfo, settingsValuesForSuggestion, sessionId, - inOutLanguageWeight); + weightForLocale, inOutWeightOfLangModelVsSpatialModel); if (null == suggestions) suggestions = new ArrayList<>(); final int length = dictionaries.size(); for (int i = 1; i < length; ++ i) { final ArrayList<SuggestedWordInfo> sugg = dictionaries.get(i).getSuggestions(composer, prevWordsInfo, proximityInfo, settingsValuesForSuggestion, sessionId, - inOutLanguageWeight); + weightForLocale, inOutWeightOfLangModelVsSpatialModel); if (null != sugg) suggestions.addAll(sugg); } return suggestions; diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java index 0f09daf86..aa15bd6bf 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java @@ -104,6 +104,7 @@ public class DictionaryFacilitator { private static class DictionaryGroup { public final Locale mLocale; private Dictionary mMainDict; + public float mWeightForLocale = 1.0f; public final ConcurrentHashMap<String, ExpandableBinaryDictionary> mSubDictMap = new ConcurrentHashMap<>(); @@ -598,14 +599,16 @@ public class DictionaryFacilitator { final SuggestionResults suggestionResults = new SuggestionResults( SuggestedWords.MAX_SUGGESTIONS, prevWordsInfo.mPrevWordsInfo[0].mIsBeginningOfSentence); - final float[] languageWeight = new float[] { Dictionary.NOT_A_LANGUAGE_WEIGHT }; + final float[] weightOfLangModelVsSpatialModel = + new float[] { Dictionary.NOT_A_WEIGHT_OF_LANG_MODEL_VS_SPATIAL_MODEL }; for (final DictionaryGroup dictionaryGroup : dictionaryGroups) { for (final String dictType : DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS) { final Dictionary dictionary = dictionaryGroup.getDict(dictType); if (null == dictionary) continue; final ArrayList<SuggestedWordInfo> dictionarySuggestions = dictionary.getSuggestions(composer, prevWordsInfo, proximityInfo, - settingsValuesForSuggestion, sessionId, languageWeight); + settingsValuesForSuggestion, sessionId, + dictionaryGroup.mWeightForLocale, weightOfLangModelVsSpatialModel); if (null == dictionarySuggestions) continue; suggestionResults.addAll(dictionarySuggestions); if (null != suggestionResults.mRawSuggestions) { @@ -707,6 +710,7 @@ public class DictionaryFacilitator { getLocale(), personalizationDataChunk, spacingAndPunctuations, callback); } + @UsedForTesting public void addPhraseToContextualDictionary(final String[] phrase, final int probability, final int bigramProbabilityForWords, final int bigramProbabilityForPhrases) { // TODO: we're inserting the phrase into the dictionary for the active language. Rethink diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index 671ba6714..ad967c133 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -435,7 +435,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer, final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo, final SettingsValuesForSuggestion settingsValuesForSuggestion, final int sessionId, - final float[] inOutLanguageWeight) { + final float weightForLocale, final float[] inOutWeightOfLangModelVsSpatialModel) { reloadDictionaryIfRequired(); boolean lockAcquired = false; try { @@ -447,7 +447,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { } final ArrayList<SuggestedWordInfo> suggestions = mBinaryDictionary.getSuggestions(composer, prevWordsInfo, proximityInfo, - settingsValuesForSuggestion, sessionId, inOutLanguageWeight); + settingsValuesForSuggestion, sessionId, weightForLocale, + inOutWeightOfLangModelVsSpatialModel); if (mBinaryDictionary.isCorrupted()) { Log.i(TAG, "Dictionary (" + mDictName +") is corrupted. " + "Remove and regenerate it."); diff --git a/java/src/com/android/inputmethod/latin/PrevWordsInfo.java b/java/src/com/android/inputmethod/latin/PrevWordsInfo.java index d662051d9..76d4f57da 100644 --- a/java/src/com/android/inputmethod/latin/PrevWordsInfo.java +++ b/java/src/com/android/inputmethod/latin/PrevWordsInfo.java @@ -132,7 +132,8 @@ public class PrevWordsInfo { @Override public int hashCode() { - return Arrays.hashCode(mPrevWordsInfo); + // Just for having equals(). + return mPrevWordsInfo[0].hashCode(); } @Override @@ -140,7 +141,23 @@ public class PrevWordsInfo { if (this == o) return true; if (!(o instanceof PrevWordsInfo)) return false; final PrevWordsInfo prevWordsInfo = (PrevWordsInfo)o; - return Arrays.equals(mPrevWordsInfo, prevWordsInfo.mPrevWordsInfo); + + final int minLength = Math.min(mPrevWordsInfo.length, prevWordsInfo.mPrevWordsInfo.length); + for (int i = 0; i < minLength; i++) { + if (!mPrevWordsInfo[i].equals(prevWordsInfo.mPrevWordsInfo[i])) { + return false; + } + } + final WordInfo[] longerWordsInfo = + (mPrevWordsInfo.length > prevWordsInfo.mPrevWordsInfo.length) ? + mPrevWordsInfo : prevWordsInfo.mPrevWordsInfo; + for (int i = minLength; i < longerWordsInfo.length; i++) { + if (longerWordsInfo[i] != null + && !WordInfo.EMPTY_WORD_INFO.equals(longerWordsInfo[i])) { + return false; + } + } + return true; } @Override @@ -151,7 +168,11 @@ public class PrevWordsInfo { builder.append("PrevWord["); builder.append(i); builder.append("]: "); - if (wordInfo == null || !wordInfo.isValid()) { + if (wordInfo == null) { + builder.append("null. "); + continue; + } + if (!wordInfo.isValid()) { builder.append("Empty. "); continue; } diff --git a/java/src/com/android/inputmethod/latin/ReadOnlyBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ReadOnlyBinaryDictionary.java index ecf25c28b..827367bb4 100644 --- a/java/src/com/android/inputmethod/latin/ReadOnlyBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ReadOnlyBinaryDictionary.java @@ -53,11 +53,13 @@ public final class ReadOnlyBinaryDictionary extends Dictionary { public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer, final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo, final SettingsValuesForSuggestion settingsValuesForSuggestion, - final int sessionId, final float[] inOutLanguageWeight) { + final int sessionId, final float weightForLocale, + final float[] inOutWeightOfLangModelVsSpatialModel) { if (mLock.readLock().tryLock()) { try { return mBinaryDictionary.getSuggestions(composer, prevWordsInfo, proximityInfo, - settingsValuesForSuggestion, sessionId, inOutLanguageWeight); + settingsValuesForSuggestion, sessionId, weightForLocale, + inOutWeightOfLangModelVsSpatialModel); } finally { mLock.readLock().unlock(); } diff --git a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java index 197908032..249478785 100644 --- a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java @@ -23,6 +23,7 @@ import android.content.res.Resources; import android.text.TextUtils; import android.util.Log; +import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.AssetFileAddress; import com.android.inputmethod.latin.BinaryDictionaryGetter; import com.android.inputmethod.latin.Constants; @@ -382,6 +383,7 @@ public class DictionaryInfoUtils { return dictList; } + @UsedForTesting public static boolean looksValidForDictionaryInsertion(final CharSequence text, final SpacingAndPunctuations spacingAndPunctuations) { if (TextUtils.isEmpty(text)) return false; diff --git a/java/src/com/android/inputmethod/latin/utils/DistracterFilter.java b/java/src/com/android/inputmethod/latin/utils/DistracterFilter.java index 94c62429e..6fd241ee9 100644 --- a/java/src/com/android/inputmethod/latin/utils/DistracterFilter.java +++ b/java/src/com/android/inputmethod/latin/utils/DistracterFilter.java @@ -21,6 +21,7 @@ import java.util.Locale; import android.view.inputmethod.InputMethodSubtype; +import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.PrevWordsInfo; public interface DistracterFilter { @@ -36,6 +37,7 @@ public interface DistracterFilter { public boolean isDistracterToWordsInDictionaries(final PrevWordsInfo prevWordsInfo, final String testedWord, final Locale locale); + @UsedForTesting public int getWordHandlingType(final PrevWordsInfo prevWordsInfo, final String testedWord, final Locale locale); diff --git a/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java b/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java index 05d124764..7955541aa 100644 --- a/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java +++ b/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin.utils; import android.util.Log; +import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.DictionaryFacilitator; import com.android.inputmethod.latin.PrevWordsInfo; @@ -58,12 +59,14 @@ public final class LanguageModelParam { public final int mTimestamp; // Constructor for unigram. TODO: support shortcuts + @UsedForTesting public LanguageModelParam(final CharSequence word, final int unigramProbability, final int timestamp) { this(null /* word0 */, word, unigramProbability, Dictionary.NOT_A_PROBABILITY, timestamp); } // Constructor for unigram and bigram. + @UsedForTesting public LanguageModelParam(final CharSequence word0, final CharSequence word1, final int unigramProbability, final int bigramProbability, final int timestamp) { diff --git a/java/src/com/android/inputmethod/latin/utils/PrevWordsInfoUtils.java b/java/src/com/android/inputmethod/latin/utils/PrevWordsInfoUtils.java index 3cd63612c..5720d9388 100644 --- a/java/src/com/android/inputmethod/latin/utils/PrevWordsInfoUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/PrevWordsInfoUtils.java @@ -16,6 +16,7 @@ package com.android.inputmethod.latin.utils; +import java.util.Arrays; import java.util.regex.Pattern; import com.android.inputmethod.latin.Constants; @@ -56,6 +57,7 @@ public final class PrevWordsInfoUtils { if (prev == null) return PrevWordsInfo.EMPTY_PREV_WORDS_INFO; final String[] w = SPACE_REGEX.split(prev); final WordInfo[] prevWordsInfo = new WordInfo[Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM]; + Arrays.fill(prevWordsInfo, WordInfo.EMPTY_WORD_INFO); for (int i = 0; i < prevWordsInfo.length; i++) { final int focusedWordIndex = w.length - n - i; // Referring to the word after the focused word. @@ -66,7 +68,6 @@ public final class PrevWordsInfoUtils { if (spacingAndPunctuations.isWordConnector(firstChar)) { // The word following the focused word is starting with a word connector. // TODO: Return meaningful context for this case. - prevWordsInfo[i] = WordInfo.EMPTY_WORD_INFO; break; } } @@ -93,7 +94,6 @@ public final class PrevWordsInfoUtils { // TODO: Return meaningful context for this case. if (spacingAndPunctuations.isWordSeparator(lastChar) || spacingAndPunctuations.isWordConnector(lastChar)) { - prevWordsInfo[i] = WordInfo.EMPTY_WORD_INFO; break; } prevWordsInfo[i] = new WordInfo(focusedWord); |