相似度得分

编程入门 行业动态 更新时间:2024-10-15 00:23:32
本文介绍了相似度得分 - 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));

更多推荐

相似度得分

本文发布于:2023-11-30 02:19:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648396.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:得分

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!