Is there a soundex function for python?

六眼飞鱼酱① 提交于 2019-12-12 16:15:19

问题


Is there a soundex function for python and if not how would you go about making a soundex code?

Soundex
Code    Letters 
1   B, F, P, V  
2   C, G, J, K, Q, S, X, Z  
3   D, T    
4   L   
5   M, N    
6   R   
SKIP   A, E, H, I, O, U, W, Y, H, W, and Y

For example:

Jackson = J250

Washington = W252

Clement = C455

Ashcraft = A261

Wu = W000


回答1:


You can use jellyfish

sudo pip install jellyfish

print "Soundex\t\t=", jellyfish.soundex("Ala ma kaca")
>Soundex                = A452
#...
>Metaphone              = AL M KK
>NYSIIS                 = AL
>Match rating codex     = ALMKC



回答2:


Yes , you can use Fuzzy which is a python library implementing some phonetic algorithms.

sudo pip install fuzzy

>>> import fuzzy
>>> soundex = fuzzy.Soundex(4)
>>> soundex("Jackson")
'J250'
>>> soundex("Washington")
'W252'
>>> soundex("Clement")
'C453'
>>> soundex("Ashcraft")
'A261'
>>> soundex("Wu")
'W000'


来源:https://stackoverflow.com/questions/35403335/is-there-a-soundex-function-for-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!