public class SwapCorrector extends Corrector
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 and Description|
Constructs a SwapCorrector instance using the given Dictionary.
|Modifier and Type||Method and Description|
Suggests as corrections any words in the Dictionary (provided when the object is constructed) that are one swap away from the input word.
public SwapCorrector(Dictionary dict)
dict- the reference dictionary to use to look for corrections arising from letter swaps
java.lang.IllegalArgumentException- if the provided Dictionary is null
public java.util.Set<java.lang.String> getCorrections(java.lang.String wrong)
For example, if the dictionary contains the word "heat" and "hate", then both should be returned if the input word is "haet".
If the provided word is already spelled correctly, then the empty set should be returned. See superclass documentation for more information.