|
| 1 | +/* |
| 2 | + * The MIT License |
| 3 | + * |
| 4 | + * Copyright 2017 Thibault Debatty. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +package info.debatty.java.stringsimilarity.examples; |
| 26 | + |
| 27 | +import info.debatty.java.stringsimilarity.Cosine; |
| 28 | +import info.debatty.java.stringsimilarity.Damerau; |
| 29 | +import info.debatty.java.stringsimilarity.Jaccard; |
| 30 | +import info.debatty.java.stringsimilarity.JaroWinkler; |
| 31 | +import info.debatty.java.stringsimilarity.Levenshtein; |
| 32 | +import info.debatty.java.stringsimilarity.NGram; |
| 33 | +import info.debatty.java.stringsimilarity.SorensenDice; |
| 34 | +import info.debatty.java.stringsimilarity.interfaces.StringDistance; |
| 35 | +import java.util.LinkedList; |
| 36 | + |
| 37 | +/** |
| 38 | + * |
| 39 | + * @author Thibault Debatty |
| 40 | + */ |
| 41 | +public class nischay21 { |
| 42 | + |
| 43 | + /** |
| 44 | + * @param args the command line arguments |
| 45 | + */ |
| 46 | + public static void main(String[] args) { |
| 47 | + |
| 48 | + String s1 = "MINI GRINDER KIT"; |
| 49 | + String s2 = "Weiler 13001 Mini Grinder Accessory Kit, For Use With Small Right Angle Grinders"; |
| 50 | + 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"; |
| 51 | + |
| 52 | + LinkedList<StringDistance> algos = new LinkedList<StringDistance>(); |
| 53 | + algos.add(new JaroWinkler()); |
| 54 | + algos.add(new Levenshtein()); |
| 55 | + algos.add(new NGram()); |
| 56 | + algos.add(new Damerau()); |
| 57 | + algos.add(new Jaccard()); |
| 58 | + algos.add(new SorensenDice()); |
| 59 | + algos.add(new Cosine()); |
| 60 | + |
| 61 | + |
| 62 | + System.out.println("S1 vs S2"); |
| 63 | + for (StringDistance algo : algos) { |
| 64 | + System.out.print(algo.getClass().getSimpleName() + " : "); |
| 65 | + System.out.println(algo.distance(s1, s2)); |
| 66 | + } |
| 67 | + System.out.println(); |
| 68 | + |
| 69 | + System.out.println("S1 vs S3"); |
| 70 | + for (StringDistance algo : algos) { |
| 71 | + System.out.print(algo.getClass().getSimpleName() + " : "); |
| 72 | + System.out.println(algo.distance(s1, s3)); |
| 73 | + } |
| 74 | + System.out.println(); |
| 75 | + |
| 76 | + System.out.println("With .toLower()"); |
| 77 | + System.out.println("S1 vs S2"); |
| 78 | + for (StringDistance algo : algos) { |
| 79 | + System.out.print(algo.getClass().getSimpleName() + " : "); |
| 80 | + System.out.println(algo.distance(s1.toLowerCase(), s2.toLowerCase())); |
| 81 | + } |
| 82 | + System.out.println(); |
| 83 | + |
| 84 | + System.out.println("S1 vs S3"); |
| 85 | + for (StringDistance algo : algos) { |
| 86 | + System.out.print(algo.getClass().getSimpleName() + " : "); |
| 87 | + System.out.println(algo.distance(s1.toLowerCase(), s3.toLowerCase())); |
| 88 | + } |
| 89 | + System.out.println(); |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | +} |
0 commit comments