Search in sources :

Example 1 with StringDistance

use of info.debatty.java.stringsimilarity.interfaces.StringDistance in project java-string-similarity by tdebatty.

the class nischay21 method main.

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    String s1 = "MINI GRINDER KIT";
    String s2 = "Weiler 13001 Mini Grinder Accessory Kit, For Use With Small Right Angle Grinders";
    String s3 = "Milwaukee Video Borescope, Rotating Inspection Scope, Series: M-SPECTOR 360, 2.7 in 640 x 480 pixels High-Resolution LCD, Plastic, Black/Red";
    LinkedList<StringDistance> algos = new LinkedList<StringDistance>();
    algos.add(new JaroWinkler());
    algos.add(new Levenshtein());
    algos.add(new NGram());
    algos.add(new Damerau());
    algos.add(new Jaccard());
    algos.add(new SorensenDice());
    algos.add(new Cosine());
    System.out.println("S1 vs S2");
    for (StringDistance algo : algos) {
        System.out.print(algo.getClass().getSimpleName() + " : ");
        System.out.println(algo.distance(s1, s2));
    }
    System.out.println();
    System.out.println("S1 vs S3");
    for (StringDistance algo : algos) {
        System.out.print(algo.getClass().getSimpleName() + " : ");
        System.out.println(algo.distance(s1, s3));
    }
    System.out.println();
    System.out.println("With .toLower()");
    System.out.println("S1 vs S2");
    for (StringDistance algo : algos) {
        System.out.print(algo.getClass().getSimpleName() + " : ");
        System.out.println(algo.distance(s1.toLowerCase(), s2.toLowerCase()));
    }
    System.out.println();
    System.out.println("S1 vs S3");
    for (StringDistance algo : algos) {
        System.out.print(algo.getClass().getSimpleName() + " : ");
        System.out.println(algo.distance(s1.toLowerCase(), s3.toLowerCase()));
    }
    System.out.println();
}
Also used : JaroWinkler(info.debatty.java.stringsimilarity.JaroWinkler) StringDistance(info.debatty.java.stringsimilarity.interfaces.StringDistance) NGram(info.debatty.java.stringsimilarity.NGram) Jaccard(info.debatty.java.stringsimilarity.Jaccard) SorensenDice(info.debatty.java.stringsimilarity.SorensenDice) Levenshtein(info.debatty.java.stringsimilarity.Levenshtein) Damerau(info.debatty.java.stringsimilarity.Damerau) LinkedList(java.util.LinkedList) Cosine(info.debatty.java.stringsimilarity.Cosine)

Aggregations

Cosine (info.debatty.java.stringsimilarity.Cosine)1 Damerau (info.debatty.java.stringsimilarity.Damerau)1 Jaccard (info.debatty.java.stringsimilarity.Jaccard)1 JaroWinkler (info.debatty.java.stringsimilarity.JaroWinkler)1 Levenshtein (info.debatty.java.stringsimilarity.Levenshtein)1 NGram (info.debatty.java.stringsimilarity.NGram)1 SorensenDice (info.debatty.java.stringsimilarity.SorensenDice)1 StringDistance (info.debatty.java.stringsimilarity.interfaces.StringDistance)1 LinkedList (java.util.LinkedList)1