public class StringSimilarity extends Object
| Constructor and Description |
|---|
StringSimilarity() |
| Modifier and Type | Method and Description |
|---|---|
static double |
diceCoefficientOptimized(String s,
String t)
Retrieved from https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Dice's_coefficient#Java
Here's an optimized version of the dice coefficient calculation.
|
static double |
getLevenshteinCoefficient(String a,
String b) |
public static double diceCoefficientOptimized(String s, String t)
Note that, at the time of writing, this implementation differs from the other implementations on this page. Where the other algorithms incorrectly store the generated bigrams in a set (discarding duplicates), this implementation actually treats multiple occurrences of a bigram as unique. The correctness of this behavior is most easily seen when getting the similarity between "GG" and "GGGGGGGG", which should obviously not be 1.
s - The first stringt - The second Stringnull. Also returns 0 if one or both of the strings contain
less than 2 characters and are not equal.Copyright © 2017 Global Crop Diversity Trust. All rights reserved.