| | import java.io.InputStreamReader; |
| | import java.text.BreakIterator; |
| | -import java.util.*; |
| | +import java.util.ArrayList; |
| | +import java.util.HashMap; |
| | +import java.util.List; |
| | +import java.util.Map; |
| | |
| | import static com.keenwrite.constants.Constants.LEXICONS_DIRECTORY; |
 |
| | /** |
| | * Prevent direct instantiation so that only the {@link SpellChecker} |
| | - * interface |
| | - * is available. |
| | + * interface is available. |
| | * |
| | * @param symSpell The implementation-specific spell checker. |
| | */ |
| | private SymSpellSpeller( final SymSpell symSpell ) { |
| | mSymSpell = symSpell; |
| | } |
| | |
| | + /** |
| | + * This expensive operation is only called for viable words, not for |
| | + * single punctuation characters or whitespace. |
| | + * |
| | + * @param lexeme The word to check for correctness. |
| | + * @return {@code false} if the word is not in the lexicon. |
| | + */ |
| | @Override |
| | public boolean inLexicon( final String lexeme ) { |
| | - return lookup( lexeme, CLOSEST ).size() == 1; |
| | + assert lexeme != null; |
| | + assert !lexeme.isBlank(); |
| | + |
| | + final var words = lookup( lexeme, CLOSEST ); |
| | + return !words.isEmpty() && lexeme.equals( words.get( 0 ).getSuggestion() ); |
| | } |
| | |
 |
| | @Override |
| | public void proofread( |
| | - final String text, final SpellCheckListener consumer ) { |
| | + final String text, |
| | + final SpellCheckListener consumer ) { |
| | assert text != null; |
| | assert consumer != null; |
 |
| | */ |
| | private boolean isWord( final String word ) { |
| | - return !word.isEmpty() && isLetter( word.charAt( 0 ) ); |
| | + return !word.isBlank() && isLetter( word.charAt( 0 ) ); |
| | } |
| | |