我正在开发一个 python 项目,在该项目中我需要过滤脏话,并且我已经有一个过滤器了。唯一的问题是,如果用户切换具有视觉相似字符的字符(例如 hello
和 h311o
),过滤器不会拾取它。有没有什么方法可以让我找到检测这些单词的方法,而无需对每个组合进行硬编码?
最佳答案
将 l331sp33ch
转换为 leetspeech
并应用简单的 levensthein 距离怎么样? (您需要先pip install editdistance
)
import editdistance
try:
from string import maketrans # python 2
except:
maketrans = str.maketrans # python 3
t = maketrans("01345", "oleas")
editdistance.eval("h3110".translate(t), 'hello')
结果0
关于python - 在 Python 中识别视觉上相似的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41769372/