/** * Finds the feature within a set of given features that best match the target string. * @param features A list of strings containing the features to compare. * @param target The target string to compare against the features. * @return The similarity score with the highest value. */ public SimilarityScore findTop(List<String> features, String target) { return findTop(features, target, new DescendingSimilarityScoreComparator()); }
@Test public void testCompareScoreFirstGreater() { SimilarityScore first = new SimilarityScore("First", 0.87); SimilarityScore second = new SimilarityScore("Second", 0.54); DescendingSimilarityScoreComparator c = new DescendingSimilarityScoreComparator(); assertTrue(c.compare(first, second)<0); assertTrue(c.compare(second, first)>0); }
@Test public void testCompareScoreSecondGreater() { SimilarityScore first = new SimilarityScore("First", 0.37); SimilarityScore second = new SimilarityScore("Second", 0.65); DescendingSimilarityScoreComparator c = new DescendingSimilarityScoreComparator(); assertTrue(c.compare(first, second)>0); assertTrue(c.compare(second, first)<0); }
/** * Finds the feature within a set of given features that best match the target string. * @param features A list of strings containing the features to compare. * @param target The target string to compare against the features. * @return The similarity score with the highest value. */ public SimilarityScore findTop(List<String> features, String target) { return findTop(features, target, new DescendingSimilarityScoreComparator()); }
@Test public void testCompareScoreEquality() { SimilarityScore first = new SimilarityScore("First", 0.96); SimilarityScore second = new SimilarityScore("Second", 0.96); DescendingSimilarityScoreComparator c = new DescendingSimilarityScoreComparator(); assertEquals(c.compare(first, second), 0); assertEquals(c.compare(second, first), 0); }
/** * Finds the feature within a set of given features that best match the target string. * @param features A list of strings containing the features to compare. * @param target The target string to compare against the features. * @return The similarity score with the highest value. */ public SimilarityScore findTop(List<String> features, String target) { return findTop(features, target, new DescendingSimilarityScoreComparator()); }
/** * Finds the feature within a set of given features that best match the target string. * @param features A list of strings containing the features to compare. * @param target The target string to compare against the features. * @return The similarity score with the highest value. */ public SimilarityScore findTop(List<String> features, String target) { return findTop(features, target, new DescendingSimilarityScoreComparator()); }
@Test public void testFindTop_Descending() { SimilarityStrategy strategy = mock(SimilarityStrategy.class); String target = "McDonalds"; String c1 = "MacMahons"; String c2 = "McPherson"; String c3 = "McDonalds"; SimilarityScore expected = new SimilarityScore(c3, 1.000); when(strategy.score(c1, target)).thenReturn(0.90); when(strategy.score(c2, target)).thenReturn(0.74); when(strategy.score(c3, target)).thenReturn(1.000); StringSimilarityService service = new StringSimilarityServiceImpl(strategy); List<String> features = new ArrayList<String>(); features.add(c1); features.add(c2); features.add(c3); DescendingSimilarityScoreComparator comparator = new DescendingSimilarityScoreComparator(); SimilarityScore top= service.findTop(features,target, comparator); verify(strategy).score(c1, target); verify(strategy).score(c2, target); verify(strategy).score(c3, target); assertEquals(expected, top); } }