@Test public void testConvertEditDistanceToSimilarity() throws Exception { assertEquals(100d, DistanceUtils.convertEditDistanceToSimilarity(0, "1234567890", "1234567890"), delta); assertEquals(67.0d, DistanceUtils.convertEditDistanceToSimilarity(2, "12345678", "12345678"), delta); assertEquals(42.0d, DistanceUtils.convertEditDistanceToSimilarity(3, "12345678", "12345678"), delta); assertEquals(86.0d, DistanceUtils.convertEditDistanceToSimilarity(1, "1234567", "123456789"), delta); assertEquals(90.0d, DistanceUtils.convertEditDistanceToSimilarity(1, "12345678901234", "1234567890x234"), delta); assertEquals(74.0d, DistanceUtils.convertEditDistanceToSimilarity(2, "12345678901234", "1234567890x234"), delta); assertEquals(53.0d, DistanceUtils.convertEditDistanceToSimilarity(3, "12345678901234", "1234567890x234"), delta); assertEquals(100d, DistanceUtils.convertEditDistanceToSimilarity(0, "12", "123456789"), delta); assertEquals(0d, DistanceUtils.convertEditDistanceToSimilarity(10, "1234567", "123456789"), delta); }
public static double convertEditDistanceToSimilarity(int edits, String s1, String s2) { int length = Math.min(10, Math.min(s1.length(), s2.length())) ; double dist = Math.pow(edits, 1.4) / (double) length; double sim = edits > length || dist > 1.0d ? 0 : 100d * (1d - dist); return Math.round(sim); }
DistanceUtils { public static double convertEditDistanceToSimilarity(int edits, String s1, String s2) { int length = Math.min(10, Math.min(s1.length(), s2.length())) ; double dist = Math.pow(edits, 1.4) / (double) length; double sim = edits > length || dist > 1.0d ? 0 : 100d * (1d - dist); return Math.round(sim); } }
DistanceUtils { public static double convertEditDistanceToSimilarity(int edits, String s1, String s2) { int length = Math.min(10, Math.min(s1.length(), s2.length())) ; double dist = Math.pow(edits, 1.4) / (double) length; double sim = edits > length || dist > 1.0d ? 0 : 100d * (1d - dist); return Math.round(sim); }  }
DistanceUtils { public static double convertEditDistanceToSimilarity(int edits, String s1, String s2) { int length = Math.min(10, Math.min(s1.length(), s2.length())) ; double dist = Math.pow(edits, 1.4) / (double) length; double sim = edits > length || dist > 1.0d ? 0 : 100d * (1d - dist); return Math.round(sim); }  static double convertEditDistanceToSimilarity(int edits, String s1, String s2); }
DistanceUtils { public static double convertEditDistanceToSimilarity(int edits, String s1, String s2) { int length = Math.min(10, Math.min(s1.length(), s2.length())) ; double dist = Math.pow(edits, 1.4) / (double) length; double sim = edits > length || dist > 1.0d ? 0 : 100d * (1d - dist); return Math.round(sim); }  static double convertEditDistanceToSimilarity(int edits, String s1, String s2);  }