String m1 = getSetOfMatchingCharacterWithin(shorter, longer, halflength); String m2 = getSetOfMatchingCharacterWithin(longer, shorter, halflength); int transpositions = transpositions(m1, m2);
/** * Calculates the similarity score of objects, where 0.0 implies absolutely no similarity * and 1.0 implies absolute similarity. * * @param first The first string to compare. * @param second The second string to compare. * @return A number between 0.0 and 1.0. */ public double score(String first, String second) { double jaro = super.score(first, second); int cl = commonPrefixLength(first, second); // The Jaro–Winkler distance uses a prefix scale which gives more favorable ratings // to strings that match from the beginning for a set prefix length. double winkler = jaro + (scalingFactor * cl * (1.0 - jaro)); return winkler; }
@Test public void testAbsoluteSimilarity() { SimilarityStrategy s = new JaroStrategy(); String first = "Mississippi"; String second = "Mississippi"; double expected = 1.000; double delta = 0.000; double actual = s.score(first, second); assertEquals(expected, actual, delta); }
@Test public void testMisspelledSoundAlike() { SimilarityStrategy s = new JaroStrategy(); String first = "Dixon"; String second = "Dicksonx"; double expected = 0.767; double delta = 0.001; double actual = s.score(first, second); assertEquals(expected, actual, delta); }
String m1 = getSetOfMatchingCharacterWithin(shorter, longer, halflength); String m2 = getSetOfMatchingCharacterWithin(longer, shorter, halflength); int transpositions = transpositions(m1, m2);
/** * Calculates the similarity score of objects, where 0.0 implies absolutely no similarity * and 1.0 implies absolute similarity. * * @param first The first string to compare. * @param second The second string to compare. * @return A number between 0.0 and 1.0. */ public double score(String first, String second) { double jaro = super.score(first, second); int cl = commonPrefixLength(first, second); // The Jaro–Winkler distance uses a prefix scale which gives more favorable ratings // to strings that match from the beginning for a set prefix length. double winkler = jaro + (scalingFactor * cl * (1.0 - jaro)); return winkler; }
@Test public void testAbsoluteDissimilarity() { SimilarityStrategy s = new JaroStrategy(); String first = "Mississippi"; String second = "Oklahoma"; double expected = 0.000; double delta = 0.000; double actual = s.score(first, second); assertEquals(expected, actual, delta); } }
String m1 = getSetOfMatchingCharacterWithin(shorter, longer, halflength); String m2 = getSetOfMatchingCharacterWithin(longer, shorter, halflength); int transpositions = transpositions(m1, m2);
/** * Calculates the similarity score of objects, where 0.0 implies absolutely no similarity * and 1.0 implies absolute similarity. * * @param first The first string to compare. * @param second The second string to compare. * @return A number between 0.0 and 1.0. */ public double score(String first, String second) { double jaro = super.score(first, second); int cl = commonPrefixLength(first, second); // The Jaro–Winkler distance uses a prefix scale which gives more favorable ratings // to strings that match from the beginning for a set prefix length. double winkler = jaro + (scalingFactor * cl * (1.0 - jaro)); return winkler; }
@Test public void testOneTranspostion() { SimilarityStrategy s = new JaroStrategy(); String first = "Martha"; String second = "Marhta"; double expected = 0.944; double delta = 0.001; double actual = s.score(first, second); assertEquals(expected, actual, delta); }
String m1 = getSetOfMatchingCharacterWithin(shorter, longer, halflength); String m2 = getSetOfMatchingCharacterWithin(longer, shorter, halflength); int transpositions = transpositions(m1, m2);
/** * Calculates the similarity score of objects, where 0.0 implies absolutely no similarity * and 1.0 implies absolute similarity. * * @param first The first string to compare. * @param second The second string to compare. * @return A number between 0.0 and 1.0. */ public double score(String first, String second) { double jaro = super.score(first, second); int cl = commonPrefixLength(first, second); // The Jaro–Winkler distance uses a prefix scale which gives more favorable ratings // to strings that match from the beginning for a set prefix length. double winkler = jaro + (scalingFactor * cl * (1.0 - jaro)); return winkler; }
@Test public void testSoundAlike() { SimilarityStrategy s = new JaroStrategy(); String first = "Dwayne"; String second = "Duane"; double expected = 0.822; double delta = 0.001; double actual = s.score(first, second); assertEquals(expected, actual, delta); }
@Test public void testAbsoluteSimilarity() { SimilarityStrategy s = new JaroStrategy(); String first = "Mississippi"; String second = "Mississippi"; double expected = 1.000; double delta = 0.000; double actual = s.score(first, second); assertEquals(expected, actual, delta); }
@Test public void testAbsoluteDissimilarity() { SimilarityStrategy s = new JaroStrategy(); String first = "Mississippi"; String second = "Oklahoma"; double expected = 0.000; double delta = 0.000; double actual = s.score(first, second); assertEquals(expected, actual, delta); }