From d631651b1291aef52bdd6ea7caaf9b95c9704506 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 15 Mar 2011 15:56:29 -0700 Subject: [PATCH] Avoid the removal of high-ranking exactly typed candidates. It used to be the case that the scoring system turns up the same word that was entered with a different capitalization, but with a lower score than some other, more frequent word. To cope with this, there was code that would order such candidates in the first slot no matter what. This processing is now useless because fully matching words now have a huge boost that ensures they will get to the top of the list, before any non-fully matching word (which means, differing only by capitalization or accents). The bug that did happen with this was, if a fully-matching word got matched by several processing passes, and the (chronologically) later score affected to this word was weaker, it would result in the duplicate removal pass removing the stronger score. This in turn would mess with autocorrect. In an effort to keep the risk at a minimum for MR1, this change does not actually remove the useless code, but adds a check in the odd case to avoid the bad situation. Another change will remove the code for ICS release. bug: 4100269 Change-Id: I18c0575332981ffec0e257e26a360995838d521e --- .../com/android/inputmethod/latin/Suggest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 9051bf762..0de474e59 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -454,7 +454,20 @@ public class Suggest implements Dictionary.WordCallback { // Check if it's the same word, only caps are different if (compareCaseInsensitive(mLowerOriginalWord, word, offset, length)) { - pos = 0; + // TODO: remove this surrounding if clause and move this logic to + // getSuggestedWordBuilder. + if (suggestions.size() > 0) { + final String currentHighestWordLowerCase = + suggestions.get(0).toString().toLowerCase(); + // If the current highest word is also equal to typed word, we need to compare + // frequency to determine the insertion position. This does not ensure strictly + // correct ordering, but ensures the top score is on top which is enough for + // removing duplicates correctly. + if (compareCaseInsensitive(currentHighestWordLowerCase, word, offset, length) + && freq <= priorities[0]) { + pos = 1; + } + } } else { if (dataType == Dictionary.DataType.UNIGRAM) { // Check if the word was already added before (by bigram data)