views:

351

answers:

4

Do you know any strictly equivalent implementation of the PHP similar_text function in Java?

A: 

This question was made here.

I hope this helps.

Good luck!

Drewen
A: 

As for Java, your best bet might be the StringUtils class from the Apache Commons Lang library, which contains the LevensteinDistance method that the other SO posts mention.

Roman Stolper
So you could take the longest strings length and subtract the LevensteinDistance in order to get the same number that similar_text would produce. and for the percentage result you would devide the result by the length.
smokeysonora
A: 
  1. Download the source code for PHP (http://php.net/downloads.php)
  2. Uncompress it.
  3. Convert the similar_text() function in ext\standard\string.c to Java.
  4. Then eat some ice-cream for tea :D
Mike
OK so I've converted the C similar_text() to Java. I have a love / hate relationship with C lol. Converting slightly hacky pointer code (obviously to make it efficient for PHP) to Java wasn't easy (for me anyway hehe).Unfortunately the code won't fit here... now just point 4) to finish :)
Mike
+1  A: 

Have a look at http://www.merriampark.com/ldjava.htm

Method: getLevenshteinDistance.

MasterGaurav