Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c6d5041 authored by Satoshi Kataoka's avatar Satoshi Kataoka Committed by Android Git Automerger
Browse files

am c05b3b56: Merge "Add a session for the personalization dictionary"

* commit 'c05b3b56':
  Add a session for the personalization dictionary
parents 145ac75c c05b3b56
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -2530,7 +2530,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
        final int maxFreq = AutoCorrectionUtils.getMaxFrequency(
                suggest.getUnigramDictionaries(), suggestion);
        if (maxFreq == 0) return null;
        userHistoryPredictionDictionary.addToUserHistory(prevWord, secondWord, maxFreq > 0);
        userHistoryPredictionDictionary
                .addToPersonalizationPredictionDictionary(prevWord, secondWord, maxFreq > 0);
        return prevWord;
    }

+13 −6
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.inputmethod.latin.WordComposer;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.utils.ByteArrayWrapper;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils;
import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils.BigramDictionaryInterface;
import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils.OnAddWordListener;
@@ -49,9 +50,6 @@ import java.util.concurrent.locks.ReentrantLock;
 * This class is a base class of a dictionary for the personalized prediction language model.
 */
public abstract class DynamicPredictionDictionaryBase extends ExpandableDictionary {
    public static void registerUpdateListener(PersonalizationDictionaryUpdateListener listener) {
        // TODO: Implement
    }

    private static final String TAG = DynamicPredictionDictionaryBase.class.getSimpleName();
    public static final boolean DBG_SAVE_RESTORE = false;
@@ -75,6 +73,9 @@ public abstract class DynamicPredictionDictionaryBase extends ExpandableDictiona
    private final ReentrantLock mBigramListLock = new ReentrantLock();
    private final SharedPreferences mPrefs;

    private final ArrayList<PersonalizationDictionaryUpdateSession> mSessions =
            CollectionUtils.newArrayList();

    // Should always be false except when we use this class for test
    @UsedForTesting boolean isTest = false;

@@ -118,14 +119,15 @@ public abstract class DynamicPredictionDictionaryBase extends ExpandableDictiona
    }

    /**
     * Pair will be added to the user history dictionary.
     * Pair will be added to the personalization prediction dictionary.
     *
     * The first word may be null. That means we don't know the context, in other words,
     * it's only a unigram. The first word may also be an empty string : this means start
     * context, as in beginning of a sentence for example.
     * The second word may not be null (a NullPointerException would be thrown).
     */
    public int addToUserHistory(final String word1, final String word2, final boolean isValid) {
    public int addToPersonalizationPredictionDictionary(
            final String word1, final String word2, final boolean isValid) {
        if (word2.length() >= Constants.DICTIONARY_MAX_WORD_LENGTH ||
                (word1 != null && word1.length() >= Constants.DICTIONARY_MAX_WORD_LENGTH)) {
            return -1;
@@ -393,9 +395,14 @@ public abstract class DynamicPredictionDictionaryBase extends ExpandableDictiona
            final String word1, final String word2, final boolean isValid) {
        mBigramListLock.lock();
        try {
            addToUserHistory(word1, word2, isValid);
            addToPersonalizationPredictionDictionary(word1, word2, isValid);
        } finally {
            mBigramListLock.unlock();
        }
    }

    public void registerUpdateSession(PersonalizationDictionaryUpdateSession session) {
        session.setDictionary(this);
        mSessions.add(session);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ import android.content.Context;
public class PersonalizationDictionary extends ExpandableBinaryDictionary {
    private static final String NAME = "personalization";

    public static void registerUpdateListener(PersonalizationDictionaryUpdateListener listener) {
    public static void registerUpdateListener(PersonalizationDictionaryUpdateSession listener) {
        // TODO: Implement
    }

+11 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import com.android.inputmethod.latin.utils.CollectionUtils;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

import java.lang.ref.SoftReference;
@@ -58,6 +59,16 @@ public class PersonalizationDictionaryHelper {
        }
    }

    public static void
            registerPersonalizationDictionaryUpdateSession(final Context context,
                    final PersonalizationDictionaryUpdateSession session) {
        final PersonalizationPredictionDictionary dictionary =
                getPersonalizationPredictionDictionary(context,
                        context.getResources().getConfiguration().locale.toString(),
                        PreferenceManager.getDefaultSharedPreferences(context));
        dictionary.registerUpdateSession(session);
    }

    public static PersonalizationPredictionDictionary getPersonalizationPredictionDictionary(
            final Context context, final String locale, final SharedPreferences sp) {
        synchronized (sLangPersonalizationDictCache) {
+0 −21
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.inputmethod.latin.personalization;

public interface PersonalizationDictionaryUpdateListener {
    // TODO: Implement
}
Loading