Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortest Levenshtein Distance? Do I need it?

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

like image 281
Writwick Avatar asked Jun 24 '13 11:06

Writwick


1 Answers

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

like image 104
GreyBeardedGeek Avatar answered Oct 22 '22 15:10

GreyBeardedGeek