Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,8 @@ class DictionaryFacilitatorImpl : DictionaryFacilitator {
"it" -> listOf("è", "di", "la", "il", "che", "in", "e", "un", "per", "non", "una", "sono")
"pt" -> listOf("de", "a", "o", "que", "e", "do", "da", "em", "um", "para", "com", "não")
"ru" -> listOf("и", "в", "не", "на", "я", "что", "быть", "с", "он", "как", "это", "по")
else -> listOf("the", "is", "to", "and", "you", "are", "in", "it", "that", "have")
// no curated list for this language: never fall back to English words
else -> emptyList()
}
}

Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/helium314/keyboard/latin/Suggest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -680,13 +680,17 @@ class Suggest(private val mDictionaryFacilitator: DictionaryFacilitator) {
if (lowercaseEntries.isEmpty()) return
candidates.removeAll { info ->
val word = info.mWord
if (word.isEmpty() || !word[0].isUpperCase() || word.drop(1).any { it.isUpperCase() })
return@removeAll false
if (word.isEmpty() || !word[0].isUpperCase()) return@removeAll false
val hasMoreCapitals = word.drop(1).any { it.isUpperCase() }
// all caps ("NOW") is only dropped below when its lowercase form is at least as likely, so "OK" stays
val isAllCaps = hasMoreCapitals && word.none { it.isLowerCase() }
if (hasMoreCapitals && !isAllCaps) return@removeAll false
val locale = info.mSourceDict.mLocale
// lowercase with ROOT too, as e.g. Turkish lowercases "I" to dotless "ı"
val lowercaseForms = setOf(word.lowercase(Locale.ROOT), word.lowercase(locale ?: Locale.ROOT))
lowercaseEntries.any { it.mWord in lowercaseForms
&& (it.mSourceDict.mLocale == locale || locale != currentLocale) }
&& (it.mSourceDict.mLocale == locale || locale != currentLocale)
&& (!isAllCaps || it.mScore >= info.mScore) }
}
}

Expand Down
10 changes: 9 additions & 1 deletion app/src/test/java/helium314/keyboard/latin/SuggestTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,20 @@ class SuggestTest {

@Test fun `keep proper nouns and all caps words`() {
val candidates = mutableListOf(suggestion("London", 500000, Locale.ENGLISH), suggestion("OK", 400000, Locale.ENGLISH))
Suggest.removeTitleCaseVariants(suggestion("ok", 1500000, Locale.ENGLISH), candidates, Locale.ENGLISH)
Suggest.removeTitleCaseVariants(suggestion("ok", 300000, Locale.ENGLISH), candidates, Locale.ENGLISH)
// "london" typed is not valid (typedWordInfo null) so "London" stays; "OK" is not title case
Suggest.removeTitleCaseVariants(null, candidates, Locale.ENGLISH)
assertEquals(listOf("London", "OK"), candidates.map { it.mWord })
}

@Test fun `all caps variant of a more likely lowercase word is dropped`() {
val typed = suggestion("now", 1709823, Locale.ENGLISH)
val candidates = mutableListOf(suggestion("NOW", 1459295, Locale.ENGLISH), suggestion("Noe", 671391, Locale.ENGLISH))
Suggest.removeTitleCaseVariants(typed, candidates, Locale.ENGLISH)
// "Noe" has no lowercase counterpart, so it stays
assertEquals(listOf("Noe"), candidates.map { it.mWord })
}

@Test fun `missing apostrophe contraction is moved first, so auto-correct commits it`() {
val candidates = mutableListOf(suggestion("did", 1000000, Locale.ENGLISH), suggestion("didn't", 900000, Locale.ENGLISH))
Suggest.promoteMissingApostropheContraction("didnt", null, candidates)
Expand Down
Loading