Levenshtein的安装和测试

前言:想安装个英语单词比较的工具,将字母排列相似的单词放在一起。

先试了PYTHON自带的difflib,结果不是太理想,设置大于等于80%的相似度: ratio=difflib.SequenceMatcher(None, new_word, sheet1.cell(i,2).value).quick_ratio()
            if ratio>=0.8:
                findwords+='相似:'+sheet1.cell(i,2).value+'\t\n'

结果:

字母随机比较,不是想要的结果。想试试Levenshtein,接下来:

一、Levenshtein安装

1.命令行:pip install python-Levenshtein,安装出错,提示wheel,安装pip install wheel成功。

重新安装Levenshtein还是出错:

Building wheels for collected packages: python-Levenshtein
  Building wheel for python-Levenshtein (setup.py) ... error

  Running setup.py clean for python-Levenshtein
Failed to build python-Levenshtein
DEPRECATION: Could not build wheels for python-Levenshtein which do not use PEP

Installing collected packages: python-Levenshtein
    Running setup.py install for python-Levenshtein ... error

    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual
C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
    ----------------------------------------意识是车轮子没安好?

2.解决:到https://www.lfd.uci.edu/~gohlke/pythonlibs/下载python_Levenshtein‑0.12.0‑cp36‑cp36m‑win_amd64.whl,放到python安装目录下,再pip install python_Levenshtein‑0.12.0‑cp36‑cp36m‑win_amd64.whl,安装成功。

二、Levenshtein测试

命令:distance=Levenshtein.distance(new_word, sheet1.cell(i,2).value)
            if  distance<2 and distance>0:  #ratio>=0.8:
                findwords+='相似:'+'('+str(sheet1.cell(i,1).value)+')'+sheet1.cell(i,2).value+'\t'+'\n'

结果:

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值