/** * 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. * @param comparator A comparator that is used sort the scores. * @return A SimilarityScore that has the top value amongst the features, according to the comparator. */ public SimilarityScore findTop(List<String> features, String target, Comparator<SimilarityScore> comparator) { if (features.size() == 0) { return null; } List<SimilarityScore> scores= scoreAll(features, target); Collections.sort(scores, comparator); return scores.get(0); } }
StringSimilarityService service = new StringSimilarityServiceImpl(strategy); double score = 0; double s;
StringSimilarityService service = new StringSimilarityServiceImpl(strategy); SimilarityScoreComparator comp = new SimilarityScoreComparator(); for (ComparableFilenameWord misspelledWord : words) {
@Test public void testScore() { SimilarityStrategy strategy = mock(SimilarityStrategy.class); String target = "McDonalds"; String c1 = "MacMahons"; String c2 = "McPherson"; String c3 = "McDonalds"; 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); double score = service.score(c1, target); verify(strategy).score(c1, target); assertEquals(0.90, score, 0.000); }
/** * 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. * @param comparator A comparator that is used sort the scores. * @return A SimilarityScore that has the top value amongst the features, according to the comparator. */ public SimilarityScore findTop(List<String> features, String target, Comparator<SimilarityScore> comparator) { if (features.size() == 0) { return null; } List<SimilarityScore> scores= scoreAll(features, target); Collections.sort(scores, comparator); return scores.get(0); } }
@Test public void testScoreAll() { SimilarityStrategy strategy = mock(SimilarityStrategy.class); String target = "McDonalds"; String c1 = "MacMahons"; String c2 = "McPherson"; String c3 = "McDonalds"; when(strategy.score(target, c1)).thenReturn(0.90); when(strategy.score(target, c2)).thenReturn(0.74); when(strategy.score(target, c3)).thenReturn(1.000); StringSimilarityService service = new StringSimilarityServiceImpl(strategy); List<String> features = new ArrayList<String>(); features.add(c1); features.add(c2); features.add(c3); List<SimilarityScore> scores = service.scoreAll(features, target); verify(strategy).score(c1, target); verify(strategy).score(c2, target); verify(strategy).score(c3, target); assertEquals(3, scores.size()); }
/** * 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. * @param comparator A comparator that is used sort the scores. * @return A SimilarityScore that has the top value amongst the features, according to the comparator. */ public SimilarityScore findTop(List<String> features, String target, Comparator<SimilarityScore> comparator) { if (features.size() == 0) { return null; } List<SimilarityScore> scores= scoreAll(features, target); Collections.sort(scores, comparator); return scores.get(0); } }
@Test public void testFindTop() { 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); SimilarityScore top= service.findTop(features,target); verify(strategy).score(c1, target); verify(strategy).score(c2, target); verify(strategy).score(c3, target); assertEquals(expected, top); }
/** * 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. * @param comparator A comparator that is used sort the scores. * @return A SimilarityScore that has the top value amongst the features, according to the comparator. */ public SimilarityScore findTop(List<String> features, String target, Comparator<SimilarityScore> comparator) { if (features.size() == 0) { return null; } List<SimilarityScore> scores= scoreAll(features, target); Collections.sort(scores, comparator); return scores.get(0); } }
@Test public void testFindTop_Ascending() { SimilarityStrategy strategy = mock(SimilarityStrategy.class); String target = "McDonalds"; String c1 = "MacMahons"; String c2 = "McPherson"; String c3 = "McDonalds"; SimilarityScore expected = new SimilarityScore(c2, 0.74); 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); AscendingSimilarityScoreComparator comparator = new AscendingSimilarityScoreComparator(); 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); }
@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); } }