Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Move error handling of spelling loader to eliminate duplication

AuthorDaveJarvis <email>
Date2022-12-04 18:10:43 GMT-0800
Commit74bac689c967d3b066b46f3c738106c2183eedd3
Parent2e0e4dc
Delta8 lines added, 12 lines removed, 4-line decrease
src/main/java/com/keenwrite/spelling/impl/SymSpellSpeller.java
import io.gitlab.rxp90.jsymspell.Verbosity;
import io.gitlab.rxp90.jsymspell.api.SuggestItem;
+import io.gitlab.rxp90.jsymspell.exceptions.NotInitializedException;
import java.text.BreakIterator;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import static com.keenwrite.events.StatusEvent.clue;
import static io.gitlab.rxp90.jsymspell.Verbosity.ALL;
import static io.gitlab.rxp90.jsymspell.Verbosity.CLOSEST;
* lexicon cannot be loaded.
*/
- public static SpellChecker forLexicon( final Map<String, Long> lexicon ) {
+ public static SpellChecker forLexicon( final Map<String, Long> lexicon )
+ throws NotInitializedException {
assert lexicon != null;
assert !lexicon.isEmpty();
- try {
- return new SymSpellSpeller(
- new SymSpellBuilder()
- .setUnigramLexicon( lexicon )
- .build()
- );
- } catch( final Exception ex ) {
- clue( ex );
- return new PermissiveSpeller();
- }
+ final var symSpell = new SymSpellBuilder()
+ .setUnigramLexicon( lexicon )
+ .build();
+
+ return new SymSpellSpeller( symSpell );
}