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 |
---|
SwapCorrector(Dictionary dict)
Constructs a SwapCorrector instance using the given Dictionary.
|
Modifier and Type | Method and Description |
---|---|
java.util.Set<java.lang.String> |
getCorrections(java.lang.String wrong)
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 swapsjava.lang.IllegalArgumentException
- if the provided Dictionary is nullpublic 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.
getCorrections
in class Corrector
wrong
- the input wordjava.lang.IllegalArgumentException
- if the input is not a valid word
(i.e. only composed of letters and/or apostrophes)