python - 在 Python 中识别视觉上相似的字符串

标签 python filter

我正在开发一个 python 项目,在该项目中我需要过滤脏话,并且我已经有一个过滤器了。唯一的问题是,如果用户切换具有视觉相似字符的字符(例如 helloh311o),过滤器不会拾取它。有没有什么方法可以让我找到检测这些单词的方法,而无需对每个组合进行硬编码?

最佳答案

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/

相关文章:

python - 这个介绍 Flask 代码中发生了什么?

python - 带有 $$ 的数据框列名称在过滤条件中失败并出现解析错误

python - Scapy 详细模式文档

jquery - 根据 div 的 id 过滤

javascript - 为什么 this.state.items.filter 从数组中删除一个项目

python - 当前路径 account/login/与其中任何一个都不匹配?

python - 黑盒测试时的结果执行和呈现

jquery fullcalendar 事件过滤

python - Geodjango:如何从点缓冲

elasticsearch - ElasticSearch按汇总结果过滤