From 5a346afab96186dc09aeed390b2cc70f8ec439d0 Mon Sep 17 00:00:00 2001 From: Satoshi Kataoka Date: Tue, 7 May 2013 15:19:08 +0900 Subject: [PATCH] Fix exact match profanity Bug: 8661070 This is a revival version of I421bed14cc71af771510142365 No diff in the test Change-Id: I96bc9cec531682cce78bcf83223dcd2395b2be77 --- native/jni/src/suggest/core/suggest.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/native/jni/src/suggest/core/suggest.cpp b/native/jni/src/suggest/core/suggest.cpp index 3221dee9c..a18794850 100644 --- a/native/jni/src/suggest/core/suggest.cpp +++ b/native/jni/src/suggest/core/suggest.cpp @@ -163,9 +163,14 @@ int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequen terminalDicNode->getFlags(), terminalDicNode->getAttributesPos()); const bool isPossiblyOffensiveWord = terminalDicNode->getProbability() <= 0; const bool isExactMatch = terminalDicNode->isExactMatch(); + const bool isFirstCharUppercase = terminalDicNode->isFirstCharUppercase(); + // Heuristic: We exclude freq=0 first-char-uppercase words from exact match. + // (e.g. "AMD" and "and") + const bool isSafeExactMatch = isExactMatch + && !(isPossiblyOffensiveWord && isFirstCharUppercase); const int outputTypeFlags = - isPossiblyOffensiveWord ? Dictionary::KIND_FLAG_POSSIBLY_OFFENSIVE : 0 - | isExactMatch ? Dictionary::KIND_FLAG_EXACT_MATCH : 0; + (isPossiblyOffensiveWord ? Dictionary::KIND_FLAG_POSSIBLY_OFFENSIVE : 0) + | (isSafeExactMatch ? Dictionary::KIND_FLAG_EXACT_MATCH : 0); // Entries that are blacklisted or do not represent a word should not be output. const bool isValidWord = !terminalAttributes.isBlacklistedOrNotAWord();