Shortest Levenshtein Distance? Do I need it?

狂风中的少年 提交于 2020-01-02 03:41:12

问题


I want to look up a String in a String[] for the best match of the query. I have heard of Levenshtein Distance. But I cannot determine if I need it or not.

Suppose, I have a String query = "Examples" and

String[] arrayStr = new String[] {"The Examples String", "The Example String", "Example", "Examples String", "Example String", "Examplestring"};

Now, I want to get the Example from the String[] as the best match.

So, Do I need Levenshtein Distance to do it?

Alternatively, If someone can point me a fast implementation of Levenshtein Distance for Java, it would be great. I would like to check if it works with all the kind of strings that I have. (Basically I have around 10k strings to match from 10k arrays.)


回答1:


Yes, Levenshtein Distance is the goto algorithm for this. You can find implementations in many languages, including Java, at http://rosettacode.org/wiki/Levenshtein_distance



来源:https://stackoverflow.com/questions/17274183/shortest-levenshtein-distance-do-i-need-it

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