Interface SpellChecker

All Known Implementing Classes:
SymSpell

public interface SpellChecker
A spelling corrector that proposes suggestions for individual terms and corrects whole sentences.

Implementations are expected to be thread-safe for concurrent lookup calls once their dictionary has been fully populated and safely published to the reading threads (e.g. stored in a final field, or otherwise guarded so a happens-before edge exists between population and the first read). Population itself is not required to be thread-safe.

  • Method Summary

    Modifier and Type
    Method
    Description
    lookup(String term)
    Convenience overload that uses Verbosity.TOP and the implementation's configured maximum dictionary edit distance.
    lookup(String term, Verbosity verbosity, int maxEditDistance)
    Looks up suggestions for a single term within maxEditDistance.
    lookupCompound(String input, int maxEditDistance)
    Corrects a whole input string (a phrase or sentence), supporting word splits and merges, and combining candidates using a bigram language model.
    int
     
  • Method Details

    • lookup

      List<SuggestItem> lookup(String term, Verbosity verbosity, int maxEditDistance)
      Looks up suggestions for a single term within maxEditDistance.

      A blank (empty or whitespace-only) term is a valid argument: it is looked up verbatim and, as it matches no dictionary entry, normally yields an empty list rather than an error.

      Parameters:
      term - the (possibly misspelled) term to correct; must not be null
      verbosity - controls how many suggestions are returned; must not be null
      maxEditDistance - the maximum edit distance to consider; must not be negative and must not exceed maxEditDistance()
      Returns:
      the matching suggestions in natural order (best first); never null
      Throws:
      NullPointerException - if term or verbosity is null
      IllegalArgumentException - if maxEditDistance is negative or exceeds maxEditDistance()
    • maxEditDistance

      int maxEditDistance()
      Returns:
      the largest edit distance this checker can answer queries for (the configured maximum dictionary edit distance); a maxEditDistance argument to lookup(String, Verbosity, int) must not exceed this value.
    • lookup

      List<SuggestItem> lookup(String term)
      Convenience overload that uses Verbosity.TOP and the implementation's configured maximum dictionary edit distance.

      As with lookup(String, Verbosity, int), a blank term is looked up verbatim and normally yields an empty list.

      Parameters:
      term - the (possibly misspelled) term to correct; must not be null
      Returns:
      the matching suggestions in natural order (best first); never null
      Throws:
      NullPointerException - if term is null
    • lookupCompound

      List<SuggestItem> lookupCompound(String input, int maxEditDistance)
      Corrects a whole input string (a phrase or sentence), supporting word splits and merges, and combining candidates using a bigram language model.

      A blank (empty or whitespace-only) input is a valid argument: it contains no tokens to correct, so the returned singleton holds a suggestion whose term is the empty string at edit distance 0.

      Parameters:
      input - the input phrase to correct; must not be null
      maxEditDistance - the maximum edit distance per token; must not be negative
      Returns:
      a singleton list holding the best correction of the whole input; never null
      Throws:
      NullPointerException - if input is null
      IllegalArgumentException - if maxEditDistance is negative