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

Commit 221e756f authored by Kurt Partridge's avatar Kurt Partridge
Browse files

ResearchLogging capture full n-gram data

DO NOT MERGE

- Captures complete motion data for all words in an n-gram.
- Also filters n-grams properly; if any word in the n-gram is not
  in the dictionary, it is not included.
- Simplify ResearchLog to not require explicit state
- Added LogBuffer class MainLogBuffer class to allow n-gram-level decisions
  about privacy.
- Moved LogUnit out from ResearchLogger

multi-project change with Ie2bc79fd7fe6b951b24771e94b8d4ca21989af65

Bug: 6188932
Change-Id: I568c90d4af07e7c759c1e7fc64b716bd8c7b4ae5
parent 7cec911f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -261,7 +261,8 @@
    <string name="research_feedback_dialog_title" translatable="false">Send feedback</string>
    <!-- Text for checkbox option to include user data in feedback for research purposes [CHAR LIMIT=50] -->
    <!-- TODO: remove translatable=false attribute once text is stable -->
    <string name="research_feedback_include_history_label" translatable="false">Include last 5 words entered</string>
    <!-- TODO: handle multilingual plurals -->
    <string name="research_feedback_include_history_label" translatable="false">Include last <xliff:g id="word">%d</xliff:g> words entered</string>
    <!-- Hint to user about the text entry field where they should enter research feedback [CHAR LIMIT=40] -->
    <!-- TODO: remove translatable=false attribute once text is stable -->
    <string name="research_feedback_hint" translatable="false">Enter your feedback here.</string>
+3 −5
Original line number Diff line number Diff line
@@ -1247,11 +1247,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
        }
        mLastKeyTime = when;
        mConnection.beginBatchEdit();

        if (ProductionFlag.IS_EXPERIMENTAL) {
            ResearchLogger.latinIME_onCodeInput(primaryCode, x, y);
        }

        final KeyboardSwitcher switcher = mKeyboardSwitcher;
        // The space state depends only on the last character pressed and its own previous
        // state. Here, we revert the space state to neutral if the key is actually modifying
@@ -1333,6 +1328,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
            mLastComposedWord.deactivate();
        mEnteredText = null;
        mConnection.endBatchEdit();
        if (ProductionFlag.IS_EXPERIMENTAL) {
            ResearchLogger.latinIME_onCodeInput(primaryCode, x, y);
        }
    }

    // Called from PointerTracker through the KeyboardActionListener interface
+5 −3
Original line number Diff line number Diff line
@@ -18,10 +18,7 @@ package com.android.inputmethod.research;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;

import com.android.inputmethod.latin.R;

@@ -31,6 +28,11 @@ public class FeedbackActivity extends Activity {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.research_feedback_activity);
        final FeedbackLayout layout = (FeedbackLayout) findViewById(R.id.research_feedback_layout);
        final CheckBox checkbox = (CheckBox) findViewById(R.id.research_feedback_include_history);
        final CharSequence cs = checkbox.getText();
        final String actualString = String.format(cs.toString(),
                ResearchLogger.FEEDBACK_WORD_BUFFER_SIZE);
        checkbox.setText(actualString);
        layout.setActivity(this);
    }

+111 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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.research;

import java.util.LinkedList;

/**
 * A buffer that holds a fixed number of LogUnits.
 *
 * LogUnits are added in and shifted out in temporal order.  Only a subset of the LogUnits are
 * actual words; the other LogUnits do not count toward the word limit.  Once the buffer reaches
 * capacity, adding another LogUnit that is a word evicts the oldest LogUnits out one at a time to
 * stay under the capacity limit.
 */
public class LogBuffer {
    protected final LinkedList<LogUnit> mLogUnits;
    /* package for test */ int mWordCapacity;
    // The number of members of mLogUnits that are actual words.
    protected int mNumActualWords;

    /**
     * Create a new LogBuffer that can hold a fixed number of LogUnits that are words (and
     * unlimited number of non-word LogUnits), and that outputs its result to a researchLog.
     *
     * @param wordCapacity maximum number of words
     */
    LogBuffer(final int wordCapacity) {
        if (wordCapacity <= 0) {
            throw new IllegalArgumentException("wordCapacity must be 1 or greater.");
        }
        mLogUnits = new LinkedList<LogUnit>();
        mWordCapacity = wordCapacity;
        mNumActualWords = 0;
    }

    /**
     * Adds a new LogUnit to the front of the LIFO queue, evicting existing LogUnit's
     * (oldest first) if word capacity is reached.
     */
    public void shiftIn(LogUnit newLogUnit) {
        if (newLogUnit.getWord() == null) {
            // This LogUnit isn't a word, so it doesn't count toward the word-limit.
            mLogUnits.add(newLogUnit);
            return;
        }
        if (mNumActualWords == mWordCapacity) {
            shiftOutThroughFirstWord();
        }
        mLogUnits.add(newLogUnit);
        mNumActualWords++; // Must be a word, or we wouldn't be here.
    }

    private void shiftOutThroughFirstWord() {
        while (!mLogUnits.isEmpty()) {
            final LogUnit logUnit = mLogUnits.removeFirst();
            onShiftOut(logUnit);
            if (logUnit.hasWord()) {
                // Successfully shifted out a word-containing LogUnit and made space for the new
                // LogUnit.
                mNumActualWords--;
                break;
            }
        }
    }

    /**
     * Removes all LogUnits from the buffer without calling onShiftOut().
     */
    public void clear() {
        mLogUnits.clear();
        mNumActualWords = 0;
    }

    /**
     * Called when a LogUnit is removed from the LogBuffer as a result of a shiftIn.  LogUnits are
     * removed in the order entered.  This method is not called when shiftOut is called directly.
     *
     * Base class does nothing; subclasses may override.
     */
    protected void onShiftOut(LogUnit logUnit) {
    }

    /**
     * Called to deliberately remove the oldest LogUnit.  Usually called when draining the
     * LogBuffer.
     */
    public LogUnit shiftOut() {
        if (mLogUnits.isEmpty()) {
            return null;
        }
        final LogUnit logUnit = mLogUnits.removeFirst();
        if (logUnit.hasWord()) {
            mNumActualWords--;
        }
        return logUnit;
    }
}
+81 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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.research;

import java.util.ArrayList;

/**
 * A group of log statements related to each other.
 *
 * A LogUnit is collection of LogStatements, each of which is generated by at a particular point
 * in the code.  (There is no LogStatement class; the data is stored across the instance variables
 * here.)  A single LogUnit's statements can correspond to all the calls made while in the same
 * composing region, or all the calls between committing the last composing region, and the first
 * character of the next composing region.
 *
 * Individual statements in a log may be marked as potentially private.  If so, then they are only
 * published to a ResearchLog if the ResearchLogger determines that publishing the entire LogUnit
 * will not violate the user's privacy.  Checks for this may include whether other LogUnits have
 * been published recently, or whether the LogUnit contains numbers, etc.
 */
/* package */ class LogUnit {
    private final ArrayList<String[]> mKeysList = new ArrayList<String[]>();
    private final ArrayList<Object[]> mValuesList = new ArrayList<Object[]>();
    private final ArrayList<Boolean> mIsPotentiallyPrivate = new ArrayList<Boolean>();
    private String mWord;
    private boolean mContainsDigit;

    public void addLogStatement(final String[] keys, final Object[] values,
            final Boolean isPotentiallyPrivate) {
        mKeysList.add(keys);
        mValuesList.add(values);
        mIsPotentiallyPrivate.add(isPotentiallyPrivate);
    }

    public void publishTo(final ResearchLog researchLog, final boolean isIncludingPrivateData) {
        final int size = mKeysList.size();
        for (int i = 0; i < size; i++) {
            if (!mIsPotentiallyPrivate.get(i) || isIncludingPrivateData) {
                researchLog.outputEvent(mKeysList.get(i), mValuesList.get(i));
            }
        }
    }

    public void setWord(String word) {
        mWord = word;
    }

    public String getWord() {
        return mWord;
    }

    public boolean hasWord() {
        return mWord != null;
    }

    public void setContainsDigit() {
        mContainsDigit = true;
    }

    public boolean hasDigit() {
        return mContainsDigit;
    }

    public boolean isEmpty() {
        return mKeysList.isEmpty();
    }
}
Loading