public class Levenshtein extends Corrector
NOTE: This corrector is a "challenge" problem and does not count towards your grade.
The Levenshtein distance between two words is the smallest number of edits needed to transform one word to the other. An "edit" can be either an:
This Corrector suggests any words in the dictionary that are exactly a distance of one edit away from the given incorrect word.
Constructor and Description |
---|
Levenshtein(Dictionary dict)
Constructs a Levenshtein Corrector instance using the given Dictionary.
|
Modifier and Type | Method and Description |
---|---|
java.util.Set<java.lang.String> |
getCorrections(java.lang.String wrong)
Returns a set of proposed corrections for an incorrectly spelled word.
|
java.util.Set<java.lang.String> |
getInsertions(java.lang.String s) |
java.util.Set<java.lang.String> |
getSubstitutions(java.lang.String s) |
public Levenshtein(Dictionary dict)
IllegalArgumentException
if the dictionary
provided is null.dict
- public java.util.Set<java.lang.String> getSubstitutions(java.lang.String s)
s
- the input stringpublic java.util.Set<java.lang.String> getInsertions(java.lang.String s)
s
- the input stringpublic java.util.Set<java.lang.String> getCorrections(java.lang.String wrong)
Corrector
Any input that is *not* a valid word (i.e. only composed of letters and/or apostrophes) should throw an IllegalArgumentException.
getCorrections
in class Corrector
wrong
- the misspelled word