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 using the argued 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> |
getDeletions(java.lang.String s)
A deletion is defined as a removing a single character.
|
java.util.Set<java.lang.String> |
getInsertions(java.lang.String s)
An insertion is defined as inserting a single character.
|
java.util.Set<java.lang.String> |
getSubstitutions(java.lang.String s)
A substitution is defined as replacing a single character with another.
|
public Levenshtein(Dictionary dict)
IllegalArgumentException
if the aruged Dictionary is null.dict
- The Dictionary for this correctorjava.lang.IllegalArgumentException
- If the argued Dictionary is nullpublic java.util.Set<java.lang.String> getDeletions(java.lang.String s)
s
- The input stringpublic 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)
For any input that is *not* a valid word, throw an IllegalArgumentException. A valid word is any sequence of letters (as determined by Character.isLetter) or apostrophes characters. The set of corrections will be all of the corrections that are a single deletion or single insertion or single substitution away from the argued word according to the above defintions.
getCorrections
in class Corrector
wrong
- The misspelled wordjava.lang.IllegalArgumentException
- If the input is not a valid word (i.e. not composed of only
letters and/or apostrophes)