Fuzzy string matching?

Fredrik Lundh fredrik at pythonware.com
Fri Aug 27 09:52:04 CEST 1999


Hans Nowak <hnowak at cuci.nl> wrote:
> The background is this... I want to write a deck managing program for 
> Magic the Gathering (or other CCGs or similar games). The program has 
> a collection of cards it knows (ideally, all kinds of cards in 
> existance). Now I want people to enter decks, by entering names of 
> cards. However, since some card names are quite difficult or have 
> funny characters in them, I expect that some of their input will not 
> be recognized in the card database. In such cases, I would like to 
> present the user with a list of card names which match the input 
> closely, but not entirely... strings that 'almost match'. OK, so it's 
> just a fuzzy string match. Is such a thing done in Python already? If 
> not, would it be difficult to do? (I obviously don't how to do it 
> myself otherwise I would have done so already... :-/  )

the soundex module (or a similar technique, tuned to
your dictionary) could be what you need:

import soundex
print soundex.sound_similar("fredrik", "frederick")
1
print soundex.sound_similar("fredrik", "hans")
0

</F>





More information about the Python-list mailing list