diff options
author | 2013-04-25 11:33:05 +0000 | |
---|---|---|
committer | 2013-04-25 11:33:05 +0000 | |
commit | 1919072cfc88dfb6f8120fe6a646146eae6694c2 (patch) | |
tree | 2689e2449f631a351b6f87ff7ce21be9586b0538 /java/src | |
parent | fb34869f5ac29c76e0147ff3760ed92dcea9a187 (diff) | |
parent | 99e998286d71cf698d0a809a29b15d1a231ebbb1 (diff) | |
download | latinime-1919072cfc88dfb6f8120fe6a646146eae6694c2.tar.gz latinime-1919072cfc88dfb6f8120fe6a646146eae6694c2.tar.xz latinime-1919072cfc88dfb6f8120fe6a646146eae6694c2.zip |
Merge "[ZF1] Check profanity in Java rather than in native"
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/latin/BinaryDictionary.java | 14 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/SuggestedWords.java | 6 |
2 files changed, 18 insertions, 2 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index dbc2b9082..03f7d1c10 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -147,10 +147,20 @@ public final class BinaryDictionary extends Dictionary { ++len; } if (len > 0) { - final int score = SuggestedWordInfo.KIND_WHITELIST == mOutputTypes[j] + final int flags = mOutputTypes[j] & SuggestedWordInfo.KIND_MASK_FLAGS; + if (0 != (flags & SuggestedWordInfo.KIND_FLAG_POSSIBLY_OFFENSIVE) + && 0 == (flags & SuggestedWordInfo.KIND_FLAG_EXACT_MATCH)) { + // If the word is possibly offensive, we don't output it unless it's also + // an exact match. + continue; + } + final int kind = mOutputTypes[j] & SuggestedWordInfo.KIND_MASK_KIND; + final int score = SuggestedWordInfo.KIND_WHITELIST == kind ? SuggestedWordInfo.MAX_SCORE : mOutputScores[j]; + // TODO: check that all users of the `kind' parameter are ready to accept + // flags too and pass mOutputTypes[j] instead of kind suggestions.add(new SuggestedWordInfo(new String(mOutputCodePoints, start, len), - score, mOutputTypes[j], mDictType)); + score, kind, mDictType)); } } return suggestions; diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 616e1911b..dfddb0ffe 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -122,6 +122,7 @@ public final class SuggestedWords { public static final class SuggestedWordInfo { public static final int MAX_SCORE = Integer.MAX_VALUE; + public static final int KIND_MASK_KIND = 0xFF; // Mask to get only the kind public static final int KIND_TYPED = 0; // What user typed public static final int KIND_CORRECTION = 1; // Simple correction/suggestion public static final int KIND_COMPLETION = 2; // Completion (suggestion with appended chars) @@ -132,6 +133,11 @@ public final class SuggestedWords { public static final int KIND_SHORTCUT = 7; // A shortcut public static final int KIND_PREDICTION = 8; // A prediction (== a suggestion with no input) public static final int KIND_RESUMED = 9; // A resumed suggestion (comes from a span) + + public static final int KIND_MASK_FLAGS = 0xFFFFFF00; // Mask to get the flags + public static final int KIND_FLAG_POSSIBLY_OFFENSIVE = 0x80000000; + public static final int KIND_FLAG_EXACT_MATCH = 0x40000000; + public final String mWord; public final int mScore; public final int mKind; // one of the KIND_* constants above |