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'

结果:

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页