Letter substitution generates a new string by replacing one letter in an existing string with another. In spelling suggestions, it tests whether changing each position to each alphabet letter produces a correctly spelled word. section 7.3
Use letter substitution as one of several small spelling-correction operations:
- Loop through each letter position in the input word. section 7.5.2
- Replace the selected letter with each other letter in the alphabet. section 7.3
- Keep only generated strings that are real words. section 7.4
Correcting acceptible
Changing the i to an a produces acceptable. The change_letter function generates this candidate alongside many other one-letter substitutions, which can then be checked against a collection of correctly spelled words. section 7.3 section 7.5.2
Table 7.2 Examples of the add_letter, delete_letter, and change_letter function
|
Input String
|
Strings Returned by
add_letter
|
Strings Returned by
delete_letter
|
Strings Returned by
change_letter
|
|---|---|---|---|
cu
|
acu, bcu, ccu, …, zcu cau, cbu, ccu, …, czu cua, cub, cuc, …, cuz
|
u, c
|
au, bu, du, …, zu, ca, cb, cc, …, cz
|
cad
|
acad, bcad, ccad, …, zcad caad, cbad, ccad, …, czad caad, cabd, cacd, …, cazd cada, cadb, cadc, …, cadz
|
ad, cd, ca
|
aad, bad, dad, …, za cbd, ccd, cdd, …, czd caa, cab, cac, …, caz
|
Compare the strings produced by changing one letter with those produced by adding or deleting one letter. section 7.5.2
