LevensteinDistance - 共享郎3.0 API [英] LevensteinDistance - Commons Lang 3.0 API

查看:279
本文介绍了LevensteinDistance - 共享郎3.0 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过共享郎API我可以计算通过<一两个字符串之间的相似性href=\"http://commons.apache.org/lang/api-2.3/org/apache/commons/lang/StringUtils.html#getLevenshteinDistance%28java.lang.String,%20java.lang.String%29\">LevensteinDistance.其结果是需要改变一个串到另一个变化的数量。我希望的结果是从0到1,在那里它会更容易识别的字符串之间的相似度的范围内。其结果将是接近0很大的相似性。这可能吗?

With Commons Lang api I can calculate the similarity between two strings through the LevensteinDistance. The result is the number of changes needed to change one string into another. I wish the result was within the range from 0 to 1, where it would be easier to identify the similarity between the strings. The result would be closer to 0 great similarity. Is it possible?

下面我使用的例子:

public class TesteLevenstein {

    public static void main(String[] args) {      

        int distance1 = StringUtils.getLevenshteinDistance("Boat", "Coat");
        int distance2 = StringUtils.getLevenshteinDistance("Remember", "Alamo");
        int distance3 = StringUtils.getLevenshteinDistance("Steve", "Stereo");

        System.out.println("distance(Boat, Coat): " + distance1);
        System.out.println("distance(Remember, Alamo): " + distance2);
        System.out.println("distance(Steve, Stereo): " + distance3);        

    }
}

谢谢!

推荐答案

只是一些数除以。现在的问题是什么号码?可能对于给定的一对串的最大可能距离。我认为这是较长的字符串的长度(即所有的人物都不同,加上一些更多的添加,用较短的字符串相比较)。

Just divide by some number. The question is what number? Probably the maximum possible distance for the given pair of strings. I think that's the length of the longer string (ie all the characters are different, plus a few more were added, compared with the shorter string).

这篇关于LevensteinDistance - 共享郎3.0 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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