Python 中的字符串相似度度量 [英] String similarity metrics in Python

查看:60
本文介绍了Python 中的字符串相似度度量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到两个字符串之间的字符串相似度.页面提供了其中一些示例.Python 实现了 Levenshtein 算法.在这些限制下,是否有更好的算法(希望有一个 Python 库).

I want to find string similarity between two strings. This page has examples of some of them. Python has an implemnetation of Levenshtein algorithm. Is there a better algorithm, (and hopefully a python library), under these contraints.

  1. 我想在字符串之间进行模糊匹配.例如matches('Hello, All you people', 'hello, all You peopl') 应该返回True
  2. 假阴性是可以接受的,假阳性是可以接受的,除非在极少数情况下不能.
  3. 这是在非实时设置中完成的,因此速度不是(非常)关注的问题.
  4. 我正在比较多字串.

除 Levenshtein 距离(或 Levenshtein 比率)之外的其他算法是否适合我的情况?

Would something other than Levenshtein distance(or Levenshtein ratio) be a better algorithm for my case?

推荐答案

谢菲尔德大学有大量关于字符串相似性度量的资源.它有一个各种指标的列表(不仅仅是 Levenshtein),并且有它们的开源实现.看起来其中很多应该很容易适应 Python.

There's a great resource for string similarity metrics at the University of Sheffield. It has a list of various metrics (beyond just Levenshtein) and has open-source implementations of them. Looks like many of them should be easy to adapt into Python.

http://web.archive.org/web/20081224234350/http://www.dcs.shef.ac.uk/~sam/stringmetrics.html

这里有一些列表:

  • 汉明距离
  • 莱文斯坦距离
  • Needleman-Wunch 距离或卖家算法
  • 还有更多……

这篇关于Python 中的字符串相似度度量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆