Created
April 18, 2014 16:02
-
-
Save cneud/11051543 to your computer and use it in GitHub Desktop.
Beanshell for calculating Levenshtein distance of two input strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.lang.StringUtils; | |
import java.text.DecimalFormat; | |
double ld = StringUtils.getLevenshteinDistance(text1, text2); | |
double avglen = ((double)text1.length()+(double)text2.length())/2.0; | |
double m = 1.0-(ld/avglen); | |
double normVal = (m<0)?0.0:m; | |
float f = (float) normVal * 100; | |
DecimalFormat s = new DecimalFormat("##.##"); | |
normalized_levenshtein_distance = s.format(f); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment