LevensteinDistance - Commons Lang 3.0 API

回眸只為那壹抹淺笑 提交于 2019-12-04 11:02:47

问题


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?

Below the example I'm using:

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);        

    }
}

Thanks!


回答1:


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).



来源:https://stackoverflow.com/questions/6629712/levensteindistance-commons-lang-3-0-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!