简体   繁体   中英

Generate deletion, insertion, substitution, transpotions for a string

I am implementing a spell checker algorithm. I have constructed a Trie that stores my words for quick searching.

When a given input string is passed what I want to do is generate potential deletions, insertions, substitutions and transpositions for that string with an edit distance of 1. Using this super set I can then try to find the word in my Trie and offer the user "did you mean?" type results.

I have looked online and most solutions mention calculating the Levenstein Distance. That only works if you already know the two strings and you want to find the edit distance between the two.

Suggestions?

I would use an 2 pass algo:

Pass 1

look and calculate the distance for all words starting with the same letter as the word to spell check. This will be fast. you can stop the depth search when the number of chars is greater then spell word length + 2 (then this obiously another word)
Display results of pass1, eg by marking word red underline

Pass 2

look for all words and stop when length + 3 or 4 Update the results found in pass 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM