diff options
author | 2013-01-08 11:18:43 -0800 | |
---|---|---|
committer | 2013-01-09 21:09:19 -0800 | |
commit | 403c423940b197e56f4d203050341b7cd90ca0cd (patch) | |
tree | c8d0afa108c44f5afbb204044a3f1ed101890eff /java/src/com/android/inputmethod/research/ResearchLogger.java | |
parent | 8bda35809b4cc02c9c41134f0a2ff9a648d25500 (diff) | |
download | latinime-403c423940b197e56f4d203050341b7cd90ca0cd.tar.gz latinime-403c423940b197e56f4d203050341b7cd90ca0cd.tar.xz latinime-403c423940b197e56f4d203050341b7cd90ca0cd.zip |
[Rlog56] Buffer words before pushing out LogUnit
Previously, a logbuffer only held an n-gram. Data went in and out of it, FIFO, until privacy
conditions were met (i.e. data not collected too frequently), and then an n-gram was saved.
E.g., if n=2, and only 10% of data is collected, then 18 words went through the logbuffer before
it captured the next 2 words.
However, if a user then went back and edited the n-gram, these edits were not captured.
This change changes the logbuffer size to temporarily hold data about words that are not recorded,
so that if the user backs up over them, the edits to an n-gram that we do eventually capture are
stored. If the example above, instead of a logbuffer holding 2 words, it holds 20. The system
waits until all the words not needed for the n-gram have been gathered (i.e. the buffer is full),
so the user has adequate time to edit, before shifting out the n-gram. The buffer is still flushed
when the user closes the IME. See the comment for MainLogBuffer for an explanation.
multi-project commit with I45317bc95eeb859adc1b35b24d0478f2df1a67f3
Change-Id: I4ffd95d08c6437dcf650d866ef9e24b6af512334
Diffstat (limited to 'java/src/com/android/inputmethod/research/ResearchLogger.java')
-rw-r--r-- | java/src/com/android/inputmethod/research/ResearchLogger.java | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java index b61db272c..f464facf4 100644 --- a/java/src/com/android/inputmethod/research/ResearchLogger.java +++ b/java/src/com/android/inputmethod/research/ResearchLogger.java @@ -85,7 +85,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang private static final String TAG = ResearchLogger.class.getSimpleName(); private static final boolean DEBUG = false && ProductionFlag.IS_EXPERIMENTAL_DEBUG; // Whether all n-grams should be logged. true will disclose private info. - private static final boolean IS_LOGGING_EVERYTHING = false + public static final boolean IS_LOGGING_EVERYTHING = false && ProductionFlag.IS_EXPERIMENTAL_DEBUG; // Whether the TextView contents are logged at the end of the session. true will disclose // private info. @@ -394,8 +394,16 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang commitCurrentLogUnit(); if (mMainLogBuffer != null) { - publishLogBuffer(mMainLogBuffer, mMainResearchLog, - IS_LOGGING_EVERYTHING /* isIncludingPrivateData */); + while (!mMainLogBuffer.isEmpty()) { + if ((mMainLogBuffer.isNGramSafe() || IS_LOGGING_EVERYTHING) && + mMainResearchLog != null) { + publishLogBuffer(mMainLogBuffer, mMainResearchLog, + true /* isIncludingPrivateData */); + mMainLogBuffer.resetWordCounter(); + } else { + mMainLogBuffer.shiftOutThroughFirstWord(); + } + } mMainResearchLog.close(null /* callback */); mMainLogBuffer = null; } @@ -702,8 +710,9 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang } if (!mCurrentLogUnit.isEmpty()) { if (mMainLogBuffer != null) { - if ((mMainLogBuffer.isSafeToLog() || IS_LOGGING_EVERYTHING) - && mMainResearchLog != null) { + if ((mMainLogBuffer.isNGramSafe() || IS_LOGGING_EVERYTHING) && + mMainLogBuffer.isNGramComplete() && + mMainResearchLog != null) { publishLogBuffer(mMainLogBuffer, mMainResearchLog, true /* isIncludingPrivateData */); mMainLogBuffer.resetWordCounter(); @@ -714,6 +723,10 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang mFeedbackLogBuffer.shiftIn(mCurrentLogUnit); } mCurrentLogUnit = new LogUnit(); + } else { + if (DEBUG) { + Log.d(TAG, "Warning: tried to commit empty log unit."); + } } } @@ -756,8 +769,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang mFeedbackLogBuffer.unshiftIn(); } if (DEBUG) { - Log.d(TAG, "uncommitCurrentLogUnit back to " + (mCurrentLogUnit.hasWord() - ? ": '" + mCurrentLogUnit.getWord() + "'" : "")); + Log.d(TAG, "uncommitCurrentLogUnit (dump=" + dumpCurrentLogUnit + ") back to " + + (mCurrentLogUnit.hasWord() ? ": '" + mCurrentLogUnit.getWord() + "'" : "")); } } @@ -773,12 +786,16 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang isIncludingPrivateData); researchLog.publish(openingLogUnit, true /* isIncludingPrivateData */); LogUnit logUnit; - while ((logUnit = logBuffer.shiftOut()) != null) { + int numWordsToPublish = MainLogBuffer.N_GRAM_SIZE; + while ((logUnit = logBuffer.shiftOut()) != null && numWordsToPublish > 0) { if (DEBUG) { Log.d(TAG, "publishLogBuffer: " + (logUnit.hasWord() ? logUnit.getWord() : "<wordless>")); } researchLog.publish(logUnit, isIncludingPrivateData); + if (logUnit.getWord() != null) { + numWordsToPublish--; + } } final LogUnit closingLogUnit = new LogUnit(); closingLogUnit.addLogStatement(LOGSTATEMENT_LOG_SEGMENT_CLOSING, @@ -1254,9 +1271,12 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang public static void latinIME_revertCommit(final String committedWord, final String originallyTypedWord, final boolean isBatchMode) { final ResearchLogger researchLogger = getInstance(); - final LogUnit logUnit = researchLogger.mMainLogBuffer.peekLastLogUnit(); + // Assume that mCurrentLogUnit has been restored to contain the reverted word. + final LogUnit logUnit = researchLogger.mCurrentLogUnit; if (originallyTypedWord.length() > 0 && hasLetters(originallyTypedWord)) { if (logUnit != null) { + // Probably not necessary, but setting as a precaution in case the word isn't + // committed later. logUnit.setWord(originallyTypedWord); } } |