Replace words using Soundex, python

陌路散爱 提交于 2019-12-05 22:33:24

I'll use enchant module:

import enchant
d = enchant.Dict("en_US")

phrase = ['Jack was standing nr the tree' ,
'they were abv everything he planned' ,
'Just stand opp the counter' ,
'Go twrds the gas station']

output = []
for section in phrase:
    sect = ''
    for word in section.split():
        if d.check(word):
            sect += word + ' '
        else:
            for correct_word in d.suggest(word):
                if soundex(correct_word) == soundex(word):
                    sect +=  correct_word + ' '
    output.append(sect[:-1])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!