前置条件
l Python3
l python-Levenshtein
安装方法:
通过Pip安装
pip install fuzzywuzzy
导入库:
fromfuzzywuzzy import fuzz
做个简单的测试:
fuzz.ratio("Let’sdo a simple test", "Let us do a simple test")如结果所示,“93”表示这两个字符串有93%的相似性,这相当高了。
当有一个字符串列表,想要搜索所有的字符串,FuzzyWuzzy将帮助提取最相关的字符串及其相似性。
fromfuzzywuzzy import processchoices = ["Data Visualisation", "DataVisualization", "Customised Behaviours", "CustomizedBehaviors"]process.extract("data visulisation", choices,limit=2)
process.extract("custom behaviour", choices, limit=2)