[Rlog24] ResearchLogger detect word boundaries in callers above commitText

multi project commit with I5847d4aba97a7224ae170a7153811c5a11816449

Change-Id: Ie6fbf6f19f0193451fe6f3ddf9d4ef1637a35db1
main
Kurt Partridge 2012-08-28 10:26:21 -07:00
parent 13b1be988d
commit f763dc5915
4 changed files with 82 additions and 37 deletions

View File

@ -1152,6 +1152,9 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
if (typedWord.length() > 0) { if (typedWord.length() > 0) {
commitChosenWord(typedWord, LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, commitChosenWord(typedWord, LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD,
separatorString); separatorString);
if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.getInstance().onWordComplete(typedWord, Long.MAX_VALUE);
}
} }
} }
@ -1187,8 +1190,10 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
if (lastTwo != null && lastTwo.length() == 2 if (lastTwo != null && lastTwo.length() == 2
&& lastTwo.charAt(0) == Constants.CODE_SPACE) { && lastTwo.charAt(0) == Constants.CODE_SPACE) {
mConnection.deleteSurroundingText(2, 0); mConnection.deleteSurroundingText(2, 0);
mConnection.commitText(lastTwo.charAt(1) + " ", 1); final String text = lastTwo.charAt(1) + " ";
mConnection.commitText(text, 1);
if (ProductionFlag.IS_EXPERIMENTAL) { if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.getInstance().onWordComplete(text, Long.MAX_VALUE);
ResearchLogger.latinIME_swapSwapperAndSpace(); ResearchLogger.latinIME_swapSwapperAndSpace();
} }
mKeyboardSwitcher.updateShiftState(); mKeyboardSwitcher.updateShiftState();
@ -1206,7 +1211,11 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
&& lastThree.charAt(2) == Constants.CODE_SPACE) { && lastThree.charAt(2) == Constants.CODE_SPACE) {
mHandler.cancelDoubleSpacePeriodTimer(); mHandler.cancelDoubleSpacePeriodTimer();
mConnection.deleteSurroundingText(2, 0); mConnection.deleteSurroundingText(2, 0);
mConnection.commitText(". ", 1); final String textToInsert = ". ";
mConnection.commitText(textToInsert, 1);
if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.getInstance().onWordComplete(textToInsert, Long.MAX_VALUE);
}
mKeyboardSwitcher.updateShiftState(); mKeyboardSwitcher.updateShiftState();
return true; return true;
} }
@ -1455,6 +1464,9 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
promotePhantomSpace(); promotePhantomSpace();
} }
mConnection.commitText(text, 1); mConnection.commitText(text, 1);
if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.getInstance().onWordComplete(text, Long.MAX_VALUE);
}
mConnection.endBatchEdit(); mConnection.endBatchEdit();
// Space state must be updated before calling updateShiftState // Space state must be updated before calling updateShiftState
mSpaceState = SPACE_STATE_NONE; mSpaceState = SPACE_STATE_NONE;
@ -1925,6 +1937,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
} }
private void handleClose() { private void handleClose() {
// TODO: Verify that words are logged properly when IME is closed.
commitTyped(LastComposedWord.NOT_A_SEPARATOR); commitTyped(LastComposedWord.NOT_A_SEPARATOR);
requestHideSelf(0); requestHideSelf(0);
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
@ -2125,7 +2138,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
if (suggestion.length() == 1 && isShowingPunctuationList()) { if (suggestion.length() == 1 && isShowingPunctuationList()) {
// Word separators are suggested before the user inputs something. // Word separators are suggested before the user inputs something.
// So, LatinImeLogger logs "" as a user's input. // So, LatinImeLogger logs "" as a user's input.
LatinImeLogger.logOnManualSuggestion("", suggestion.toString(), index, suggestedWords); LatinImeLogger.logOnManualSuggestion("", suggestion, index, suggestedWords);
// Rely on onCodeInput to do the complicated swapping/stripping logic consistently. // Rely on onCodeInput to do the complicated swapping/stripping logic consistently.
final int primaryCode = suggestion.charAt(0); final int primaryCode = suggestion.charAt(0);
onCodeInput(primaryCode, onCodeInput(primaryCode,
@ -2165,8 +2178,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// We need to log before we commit, because the word composer will store away the user // We need to log before we commit, because the word composer will store away the user
// typed word. // typed word.
final String replacedWord = mWordComposer.getTypedWord().toString(); final String replacedWord = mWordComposer.getTypedWord().toString();
LatinImeLogger.logOnManualSuggestion(replacedWord, LatinImeLogger.logOnManualSuggestion(replacedWord, suggestion, index, suggestedWords);
suggestion.toString(), index, suggestedWords);
mExpectingUpdateSelection = true; mExpectingUpdateSelection = true;
commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK, commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK,
LastComposedWord.NOT_A_SEPARATOR); LastComposedWord.NOT_A_SEPARATOR);
@ -2303,8 +2315,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
} }
mConnection.deleteSurroundingText(deleteLength, 0); mConnection.deleteSurroundingText(deleteLength, 0);
if (!TextUtils.isEmpty(previousWord) && !TextUtils.isEmpty(committedWord)) { if (!TextUtils.isEmpty(previousWord) && !TextUtils.isEmpty(committedWord)) {
mUserHistoryDictionary.cancelAddingUserHistory( mUserHistoryDictionary.cancelAddingUserHistory(previousWord, committedWord);
previousWord.toString(), committedWord.toString());
} }
mConnection.commitText(originallyTypedWord + mLastComposedWord.mSeparatorString, 1); mConnection.commitText(originallyTypedWord + mLastComposedWord.mSeparatorString, 1);
if (ProductionFlag.IS_INTERNAL) { if (ProductionFlag.IS_INTERNAL) {
@ -2312,7 +2323,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
} }
if (ProductionFlag.IS_EXPERIMENTAL) { if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.latinIME_revertCommit(originallyTypedWord); ResearchLogger.latinIME_revertCommit(committedWord, originallyTypedWord);
ResearchLogger.getInstance().onWordComplete(originallyTypedWord, Long.MAX_VALUE);
} }
// Don't restart suggestion yet. We'll restart if the user deletes the // Don't restart suggestion yet. We'll restart if the user deletes the
// separator. // separator.

View File

@ -178,9 +178,6 @@ public final class RichInputConnection {
mComposingText.setLength(0); mComposingText.setLength(0);
if (null != mIC) { if (null != mIC) {
mIC.commitText(text, i); mIC.commitText(text, i);
if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.richInputConnection_commitText(text, i);
}
} }
} }
@ -665,7 +662,11 @@ public final class RichInputConnection {
return false; return false;
} }
deleteSurroundingText(2, 0); deleteSurroundingText(2, 0);
commitText(" ", 1); final String doubleSpace = " ";
commitText(doubleSpace, 1);
if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.getInstance().onWordComplete(doubleSpace, Long.MAX_VALUE);
}
return true; return true;
} }
@ -686,7 +687,11 @@ public final class RichInputConnection {
return false; return false;
} }
deleteSurroundingText(2, 0); deleteSurroundingText(2, 0);
commitText(" " + textBeforeCursor.subSequence(0, 1), 1); final String text = " " + textBeforeCursor.subSequence(0, 1);
commitText(text, 1);
if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.getInstance().onWordComplete(text, Long.MAX_VALUE);
}
return true; return true;
} }

View File

@ -741,7 +741,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
private static final LogStatement LOGSTATEMENT_COMMIT_RECORD_SPLIT_WORDS = private static final LogStatement LOGSTATEMENT_COMMIT_RECORD_SPLIT_WORDS =
new LogStatement("recordSplitWords", true, false); new LogStatement("recordSplitWords", true, false);
private void onWordComplete(final String word, final long maxTime, final boolean isSplitWords) { public void onWordComplete(final String word, final long maxTime) {
final Dictionary dictionary = getDictionary(); final Dictionary dictionary = getDictionary();
if (word != null && word.length() > 0 && hasLetters(word)) { if (word != null && word.length() > 0 && hasLetters(word)) {
mCurrentLogUnit.setWord(word); mCurrentLogUnit.setWord(word);
@ -751,11 +751,6 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
} }
final LogUnit newLogUnit = mCurrentLogUnit.splitByTime(maxTime); final LogUnit newLogUnit = mCurrentLogUnit.splitByTime(maxTime);
enqueueCommitText(word); enqueueCommitText(word);
if (isSplitWords) {
enqueueEvent(LOGSTATEMENT_COMMIT_RECORD_SPLIT_WORDS);
enqueueCommitText(" ");
mStatistics.recordSplitWords();
}
commitCurrentLogUnit(); commitCurrentLogUnit();
mCurrentLogUnit = newLogUnit; mCurrentLogUnit = newLogUnit;
} }
@ -1049,12 +1044,15 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
new LogStatement("LatinIMEPickSuggestionManually", true, false, "replacedWord", "index", new LogStatement("LatinIMEPickSuggestionManually", true, false, "replacedWord", "index",
"suggestion", "x", "y"); "suggestion", "x", "y");
public static void latinIME_pickSuggestionManually(final String replacedWord, public static void latinIME_pickSuggestionManually(final String replacedWord,
final int index, CharSequence suggestion) { final int index, final String suggestion) {
final String scrubbedWord = scrubDigitsFromString(suggestion);
final ResearchLogger researchLogger = getInstance(); final ResearchLogger researchLogger = getInstance();
researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_PICKSUGGESTIONMANUALLY, researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_PICKSUGGESTIONMANUALLY,
scrubDigitsFromString(replacedWord), index, scrubDigitsFromString(replacedWord), index,
suggestion == null ? null : scrubDigitsFromString(suggestion.toString()), suggestion == null ? null : scrubbedWord, Constants.SUGGESTION_STRIP_COORDINATE,
Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE); Constants.SUGGESTION_STRIP_COORDINATE);
researchLogger.onWordComplete(scrubbedWord, Long.MAX_VALUE);
researchLogger.mStatistics.recordManualSuggestion();
} }
/** /**
@ -1065,10 +1063,11 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
private static final LogStatement LOGSTATEMENT_LATINIME_PUNCTUATIONSUGGESTION = private static final LogStatement LOGSTATEMENT_LATINIME_PUNCTUATIONSUGGESTION =
new LogStatement("LatinIMEPunctuationSuggestion", false, false, "index", "suggestion", new LogStatement("LatinIMEPunctuationSuggestion", false, false, "index", "suggestion",
"x", "y"); "x", "y");
public static void latinIME_punctuationSuggestion(final int index, public static void latinIME_punctuationSuggestion(final int index, final String suggestion) {
final CharSequence suggestion) { final ResearchLogger researchLogger = getInstance();
getInstance().enqueueEvent(LOGSTATEMENT_LATINIME_PUNCTUATIONSUGGESTION, index, suggestion, researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_PUNCTUATIONSUGGESTION, index, suggestion,
Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE); Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE);
researchLogger.onWordComplete(suggestion, Long.MAX_VALUE);
} }
/** /**
@ -1147,9 +1146,14 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
* backspace. * backspace.
*/ */
private static final LogStatement LOGSTATEMENT_LATINIME_REVERTCOMMIT = private static final LogStatement LOGSTATEMENT_LATINIME_REVERTCOMMIT =
new LogStatement("LatinIMERevertCommit", true, false, "originallyTypedWord"); new LogStatement("LatinIMERevertCommit", true, false, "committedWord",
public static void latinIME_revertCommit(final String originallyTypedWord) { "originallyTypedWord");
getInstance().enqueueEvent(LOGSTATEMENT_LATINIME_REVERTCOMMIT, originallyTypedWord); public static void latinIME_revertCommit(final String committedWord,
final String originallyTypedWord) {
final ResearchLogger researchLogger = getInstance();
researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_REVERTCOMMIT, committedWord,
originallyTypedWord);
researchLogger.mStatistics.recordRevertCommit();
} }
/** /**
@ -1259,17 +1263,27 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
final ResearchLogger researchLogger = getInstance(); final ResearchLogger researchLogger = getInstance();
researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_COMMITCURRENTAUTOCORRECTION, researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_COMMITCURRENTAUTOCORRECTION,
scrubbedTypedWord, scrubbedAutoCorrection, separatorString); scrubbedTypedWord, scrubbedAutoCorrection, separatorString);
researchLogger.onWordComplete(scrubbedAutoCorrection, Long.MAX_VALUE, researchLogger.onWordComplete(scrubbedAutoCorrection, Long.MAX_VALUE);
false /* isPartial */);
} }
private boolean isExpectingCommitText = false; private boolean isExpectingCommitText = false;
/**
* Log a call to RichInputConnection.commitPartialText
*
* SystemResponse: The IME is committing part of a word. This happens if a space is
* automatically inserted to split a single typed string into two or more words.
*/
// TODO: This method is currently unused. Find where it should be called from in the IME and
// add invocations.
private static final LogStatement LOGSTATEMENT_LATINIME_COMMIT_PARTIAL_TEXT =
new LogStatement("LatinIMECommitPartialText", true, false, "newCursorPosition");
public static void latinIME_commitPartialText(final CharSequence committedWord, public static void latinIME_commitPartialText(final CharSequence committedWord,
final long lastTimestampOfWordData) { final long lastTimestampOfWordData) {
final ResearchLogger researchLogger = getInstance(); final ResearchLogger researchLogger = getInstance();
final String scrubbedWord = scrubDigitsFromString(committedWord.toString()); final String scrubbedWord = scrubDigitsFromString(committedWord.toString());
researchLogger.onWordComplete(scrubbedWord, lastTimestampOfWordData, true /* isPartial */); researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_COMMIT_PARTIAL_TEXT);
researchLogger.isExpectingCommitText = true; researchLogger.onWordComplete(scrubbedWord, lastTimestampOfWordData);
researchLogger.mStatistics.recordSplitWords();
} }
/** /**
@ -1287,7 +1301,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
if (!researchLogger.isExpectingCommitText) { if (!researchLogger.isExpectingCommitText) {
researchLogger.enqueueEvent(LOGSTATEMENT_RICHINPUTCONNECTIONCOMMITTEXT, researchLogger.enqueueEvent(LOGSTATEMENT_RICHINPUTCONNECTIONCOMMITTEXT,
newCursorPosition); newCursorPosition);
researchLogger.onWordComplete(scrubbedWord, Long.MAX_VALUE, false /* isPartial */); researchLogger.onWordComplete(scrubbedWord, Long.MAX_VALUE);
} }
researchLogger.isExpectingCommitText = false; researchLogger.isExpectingCommitText = false;
} }
@ -1465,7 +1479,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
"isEmptinessStateKnown", "averageTimeBetweenKeys", "averageTimeBeforeDelete", "isEmptinessStateKnown", "averageTimeBetweenKeys", "averageTimeBeforeDelete",
"averageTimeDuringRepeatedDelete", "averageTimeAfterDelete", "averageTimeDuringRepeatedDelete", "averageTimeAfterDelete",
"dictionaryWordCount", "splitWordsCount", "gestureInputCount", "dictionaryWordCount", "splitWordsCount", "gestureInputCount",
"gestureCharsCount", "gesturesDeletedCount"); "gestureCharsCount", "gesturesDeletedCount", "manualSuggestionsCount",
"revertCommitsCount");
private static void logStatistics() { private static void logStatistics() {
final ResearchLogger researchLogger = getInstance(); final ResearchLogger researchLogger = getInstance();
final Statistics statistics = researchLogger.mStatistics; final Statistics statistics = researchLogger.mStatistics;
@ -1477,8 +1492,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
statistics.mDuringRepeatedDeleteKeysCounter.getAverageTime(), statistics.mDuringRepeatedDeleteKeysCounter.getAverageTime(),
statistics.mAfterDeleteKeyCounter.getAverageTime(), statistics.mAfterDeleteKeyCounter.getAverageTime(),
statistics.mDictionaryWordCount, statistics.mSplitWordsCount, statistics.mDictionaryWordCount, statistics.mSplitWordsCount,
statistics.mGesturesInputCount, statistics.mGesturesInputCount, statistics.mGesturesCharsCount,
statistics.mGesturesCharsCount, statistics.mGesturesDeletedCount, statistics.mManualSuggestionsCount,
statistics.mGesturesDeletedCount); statistics.mRevertCommitsCount);
} }
} }

View File

@ -47,6 +47,10 @@ public class Statistics {
int mGesturesDeletedCount; int mGesturesDeletedCount;
// Total number of characters in words entered by gesture. // Total number of characters in words entered by gesture.
int mGesturesCharsCount; int mGesturesCharsCount;
// Number of manual suggestions chosen.
int mManualSuggestionsCount;
// Number of times a commit was reverted in this session.
int mRevertCommitsCount;
// Whether the text field was empty upon editing // Whether the text field was empty upon editing
boolean mIsEmptyUponStarting; boolean mIsEmptyUponStarting;
boolean mIsEmptinessStateKnown; boolean mIsEmptinessStateKnown;
@ -111,6 +115,8 @@ public class Statistics {
mSplitWordsCount = 0; mSplitWordsCount = 0;
mGesturesInputCount = 0; mGesturesInputCount = 0;
mGesturesDeletedCount = 0; mGesturesDeletedCount = 0;
mManualSuggestionsCount = 0;
mRevertCommitsCount = 0;
mIsEmptyUponStarting = true; mIsEmptyUponStarting = true;
mIsEmptinessStateKnown = false; mIsEmptinessStateKnown = false;
mKeyCounter.reset(); mKeyCounter.reset();
@ -184,4 +190,11 @@ public class Statistics {
public void recordGestureDelete() { public void recordGestureDelete() {
mGesturesDeletedCount++; mGesturesDeletedCount++;
} }
public void recordManualSuggestion() {
mManualSuggestionsCount++;
}
public void recordRevertCommit() {
mRevertCommitsCount++;
}
} }