Detecting misspelled words

2020-03-01 20:26发布

问题:

I have a list of airport names and my users have the possibility to enter one airport name to select it for futher processing.

How would you handle misspelled names and present a list of suggestions?

回答1:

Look up Levenshtein distances to match a correct name against a given user input.



回答2:

http://norvig.com/spell-correct.html
does something like levenshtein but, because he doesnt go all the way, its more efficient



回答3:

Employ spell check in your code. The list of words should contain only correct spellings of airports.

This is not a great way to do this. You should either go for a control that provides auto complete option or a drop down as someone else suggested.

Use AJAX if your technology supports.



回答4:

I know its not what you asked, but if this is an application where getting the right airport is important (e.g. booking tickets) then you might want to have a confirmation stage to make sure you have the right one. There have been cases of people getting tickets for the wrong Sydney, for instance.



回答5:

It may be better to let the user select from the list of airport names instead of letting them type in their own. No mistakes can be made that way.



回答6:

While it won't help right away, you could keep track of typos, and see which name they finally enter when a correct name is entered. That way you can track most common typos, and offer the best options.



回答7:

Adding to Kevin's suggestion, it might be a best of both worlds if you use an input box with javascript autocomplete. such as jquery autocomplete

edit: danish beat me :(



回答8:

There may be an existing spell-check library you can use. The code to do this sort of thing well is non-trivial. If you do want to write this yourself, you might want to look at dictionary trie's.

One method that may work is to just generate a huge list of possible error words and their corrections (here's an implementation in Python), which you could cache for greater performance.