EN
Apache commons text similarity FuzzyScore, HammingDistance, JaccardDistance, JaccardSimilarity, JaroWinklerDistance, JaroWinklerSimilarity, LevenshteinDistance
5
points
Example:
import org.apache.commons.text.similarity.FuzzyScore;
import org.apache.commons.text.similarity.HammingDistance;
import org.apache.commons.text.similarity.JaccardDistance;
import org.apache.commons.text.similarity.JaccardSimilarity;
import org.apache.commons.text.similarity.JaroWinklerDistance;
import org.apache.commons.text.similarity.JaroWinklerSimilarity;
import org.apache.commons.text.similarity.LevenshteinDistance;
public class Example {
public static void main(String[] args) {
FuzzyScore fuzzyScore;
HammingDistance hammingDistance;
String text1 = "Partizn Belgrade";
String text2 = "Partizan Belgrade";
JaroWinklerDistance jaroWinklerDistance = new JaroWinklerDistance();
System.out.println(jaroWinklerDistance.apply(text1, text2));
JaroWinklerSimilarity jaroWinklerSimilarity = new JaroWinklerSimilarity();
System.out.println(jaroWinklerSimilarity.apply(text1, text2));
LevenshteinDistance levenshteinDistance = new LevenshteinDistance();
System.out.println(levenshteinDistance.apply(text1, text2));
JaccardSimilarity jaccardSimilarity = new JaccardSimilarity();
System.out.println(jaccardSimilarity.apply(text1, text2));
JaccardDistance jaccardDistance = new JaccardDistance();
System.out.println(jaccardDistance.apply(text1, text2));
}
}
Output:
0.9382352941176471
0.9382352941176471
1
1.0
0.0
Maven pom dependency:
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-text -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
<scope>compile</scope>
</dependency>