Class SwapCorrector

java.lang.Object
  extended by Corrector
      extended by SwapCorrector

public class SwapCorrector
extends Corrector

A Corrector whose spelling suggestions come from "swapped letter" typos.

A common misspelling is accidentally swapping two adjacent letters, e.g. "with" -> "wiht". This Corrector is given a Dictionary of valid words and proposes corrections that are precisely one "swap" away from the incorrect word.

For example, if the incorrect word is "haet", then this Corrector might suggest "heat" and "hate", provided that both of these words occur in the dictionary.

Only swaps between adjacent letters are considered by this corrector.


Constructor Summary
SwapCorrector(Dictionary dict)
          Constructs a SwapCorrector instance using the given Dictionary.
 
Method Summary
 java.util.Set<java.lang.String> getCorrections(java.lang.String wrong)
          Returns a set of proposed corrections for an incorrect word.
 
Methods inherited from class Corrector
matchCase
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwapCorrector

public SwapCorrector(Dictionary dict)
Constructs a SwapCorrector instance using the given Dictionary. Should throw an IllegalArgumentException if the Dictionary provided is null.

Parameters:
dict - the reference dictionary to use to look for corrections arising from letter swaps
Method Detail

getCorrections

public java.util.Set<java.lang.String> getCorrections(java.lang.String wrong)
Description copied from class: Corrector
Returns a set of proposed corrections for an incorrect word. The corrections should match the case of the input; the matchCase method may be helpful here.

Specified by:
getCorrections in class Corrector
Parameters:
wrong - the misspelled word. Assume any leading or trailing whitespace has already been removed.
Returns:
a (potentially empty) set of proposed corrections