Languages
[Edit]
EN

Apache commons text similarity FuzzyScore, HammingDistance, JaccardDistance, JaccardSimilarity, JaroWinklerDistance, JaroWinklerSimilarity, LevenshteinDistance

5 points
Created by:
Inferio
328

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>

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join