From 77c4a27c4c37b3620defcab94ffd1b2f536c88cb Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Mon, 2 Feb 2026 00:20:00 +0100 Subject: Spell checking (#1137) This adds dictionary-based spell checking to the keyboard. The keyboard looks at the word being typed and matches it against a dictionary to either complete the rest of the word or find alternative spellings. The core of this feature is implemented in cdict, which is included as a submodule in vendor/cidct. Cdict is developped at https://github.com/Julow/cdict The dictionaries are hosted at https://github.com/Julow/Unexpected-Keyboard-dictionaries/ The wordlists used to build the dictionaries are the same ones used by HeliBoard from https://codeberg.org/Helium314/aosp-dictionaries - Add an activity accessible from the launcher app that lists available dictionaries with a download button. The DictionaryListView view shows the list of available dictionaries and handles downloading and installing them. - The Dictionaries class manages installed dictionaries. Dictionaries are installed as individual files into the app's private directory. - Available dictionaries are listed in dictionaries.xml, which is generated when building Unexpected-Keyboard-dictionaries. method.xml mentions the dictionary name for each locales. --- srcs/juloo.keyboard2/suggestions/Suggestions.java | 27 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'srcs/juloo.keyboard2/suggestions/Suggestions.java') diff --git a/srcs/juloo.keyboard2/suggestions/Suggestions.java b/srcs/juloo.keyboard2/suggestions/Suggestions.java index 50c64e0..998d40d 100644 --- a/srcs/juloo.keyboard2/suggestions/Suggestions.java +++ b/srcs/juloo.keyboard2/suggestions/Suggestions.java @@ -2,28 +2,47 @@ package juloo.keyboard2.suggestions; import java.util.Arrays; import java.util.List; +import juloo.cdict.Cdict; +import juloo.keyboard2.dict.Dictionaries; +import juloo.keyboard2.Config; /** Keep track of the word being typed and provide suggestions for [CandidatesView]. */ public final class Suggestions { Callback _callback; + Config _config; - public Suggestions(Callback c) + public Suggestions(Callback c, Config conf) { _callback = c; + _config = conf; } public void currently_typed_word(String word) { - if (word.equals("")) + Cdict dict = _config.current_dictionary; + if (word.length() < 2 || dict == null) { _callback.set_suggestions(NO_SUGGESTIONS); } else { - // TODO - _callback.set_suggestions(Arrays.asList(word)); + Cdict.Result r = dict.find(word); + String[] suggestions = new String[3]; + int i = 0; + if (r.found) + suggestions[i++] = word; + int[] suffixes = dict.suffixes(r, 3); + int[] dist = dict.distance(word, 1, 3); + for (int j = 0; j < 3 && i < 3; j++) + { + if (suffixes.length > j) + suggestions[i++] = dict.word(suffixes[j]); + if (dist.length > j && i < 3) + suggestions[i++] = dict.word(dist[j]); + } + _callback.set_suggestions(Arrays.asList(suggestions)); } } -- cgit v1.2.3