相似度得分 - Levenshtein [英] Similarity Score - Levenshtein

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

问题描述

我在Java中实现了Levenshtein算法,现在我正在通过算法进行校正,a.k.a。成本。这确实有点帮助但不多,因为我希望结果为百分比。

I implemented the Levenshtein algorithm in Java and am now getting the corrections made by the algorithm, a.k.a. the cost. This does help a little but not much since I want the results as a percentage.

所以我想知道如何计算这些相似点。

So I want to know how to calculate those similarity points.

我也想知道你是怎么做的人们这样做以及为什么。

I would also like to know how you people do it and why.

推荐答案


Levenshtein 两个字符串之间的距离定义为将一个字符串转换为另一个字符串所需的最小编辑数,允许的编辑操作是插入,删除,或替换单个字符。 (维基百科)

The Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character. (Wikipedia)




  • 所以Levenshtein距离为0表示:两个字符串相等

  • Levenshtein的最大距离(所有字符都不同)是max(string1.length,string2.length)

  • 因此,如果您需要一个百分比,您必须使用它来指向比例。例如:

    So if you need a percentage, you have to use this to points to scale. For example:

    你好,你好 - > Levenstein距离1
    这两个字符串的最大Levenstein距离是:5.
    所以20%的字符不匹配。

    "Hallo", "Hello" -> Levenstein distance 1 Max Levenstein distance for this two strings is: 5. So the 20% of the characters do not match.

    String s1 = "Hallo";
    String s2 = "Hello";
    int lfd = calculateLevensteinDistance(s1, s2);
    double ratio = ((double) lfd) / (Math.max(s1.length, s2.length));
    

    这篇关于相似度得分 - Levenshtein的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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