/** * Calculates all similarity scores for a given set of features. * @param features The list of features. * @param target The target string to compare against the features. * @return A list of similarity scores. */ public List<SimilarityScore> scoreAll(List<String> features, String target) { ArrayList<SimilarityScore> scores = new ArrayList<SimilarityScore>(); for(String feature: features) { double score = strategy.score(feature, target); scores.add(new SimilarityScore(feature, score)); } return scores; }
@Test public void testGetScore() { SimilarityScore s = new SimilarityScore("Test", 0.99); assertEquals(0.99, s.getScore(), 0.000); }
@Test public void testGetKey() { SimilarityScore s = new SimilarityScore("Test", 0.99); assertEquals("Test", s.getKey()); }
sb.append(misspelledWord).append(": "); for (SimilarityScore score : scores) { if (score.getKey().equals(misspelledWord.toString())){ continue; // ignore the comparison of the word with itself if (score.getScore()<0.85){ break; // too dissimilar sb.append(score.getKey()).append(" (").append(formatter.format(score.getScore())).append("), ");
/** * Calculates all similarity scores for a given set of features. * @param features The list of features. * @param target The target string to compare against the features. * @return A list of similarity scores. */ public List<SimilarityScore> scoreAll(List<String> features, String target) { ArrayList<SimilarityScore> scores = new ArrayList<SimilarityScore>(); for(String feature: features) { double score = strategy.score(feature, target); scores.add(new SimilarityScore(feature, score)); } return scores; }
/** * Compares two similarity scores. * @param x The first score to be compared. * @param y The second score to be compared. * @return a negative integer, zero, or a positive integer as the first score is greater than, * equal to, or less than the second score. */public int compare(SimilarityScore x, SimilarityScore y) { double first = x.getScore(); double second = y.getScore(); if (first == second) { return 0; } if (first < second) { return 1; } return -1; }
/** * Calculates all similarity scores for a given set of features. * @param features The list of features. * @param target The target string to compare against the features. * @return A list of similarity scores. */ public List<SimilarityScore> scoreAll(List<String> features, String target) { ArrayList<SimilarityScore> scores = new ArrayList<SimilarityScore>(); for(String feature: features) { double score = strategy.score(feature, target); scores.add(new SimilarityScore(feature, score)); } return scores; }
/** * Compares two similarity scores. * @param x The first score to be compared. * @param y The second score to be compared. * @return a negative integer, zero, or a positive integer as the first score is greater than, * equal to, or less than the second score. */public int compare(SimilarityScore x, SimilarityScore y) { double first = x.getScore(); double second = y.getScore(); if (first == second) { return 0; } if (first < second) { return 1; } return -1; }
/** * Calculates all similarity scores for a given set of features. * @param features The list of features. * @param target The target string to compare against the features. * @return A list of similarity scores. */ public List<SimilarityScore> scoreAll(List<String> features, String target) { ArrayList<SimilarityScore> scores = new ArrayList<SimilarityScore>(); for(String feature: features) { double score = strategy.score(feature, target); scores.add(new SimilarityScore(feature, score)); } return scores; }
/** * Compares two similarity scores. * @param x The first score to be compared. * @param y The second score to be compared. * @return a negative integer, zero, or a positive integer as the first score is greater than, * equal to, or less than the second score. */public int compare(SimilarityScore x, SimilarityScore y) { double first = x.getScore(); double second = y.getScore(); if (first == second) { return 0; } if (first < second) { return 1; } return -1; }
@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); }
/** * Compares two similarity scores. * @param x The first score to be compared. * @param y The second score to be compared. * @return a negative integer, zero, or a positive integer as the first score is less than, * equal to, or greater than the second score. */ public int compare(SimilarityScore x, SimilarityScore y) { double first = x.getScore(); double second = y.getScore(); if (first == second) { return 0; } if (first < second) { return -1; } return 1; }
@Test public void testCompareScoreSecondGreater() { SimilarityScore first = new SimilarityScore("First", 0.37); SimilarityScore second = new SimilarityScore("Second", 0.65); AscendingSimilarityScoreComparator c = new AscendingSimilarityScoreComparator(); assertTrue(c.compare(first, second)<0); assertTrue(c.compare(second, first)>0); }
/** * Compares two similarity scores. * @param x The first score to be compared. * @param y The second score to be compared. * @return a negative integer, zero, or a positive integer as the first score is greater than, * equal to, or less than the second score. */public int compare(SimilarityScore x, SimilarityScore y) { double first = x.getScore(); double second = y.getScore(); if (first == second) { return 0; } if (first < second) { return 1; } return -1; }
@Test public void testCompareScoreEquality() { SimilarityScore first = new SimilarityScore("First", 0.96); SimilarityScore second = new SimilarityScore("Second", 0.96); AscendingSimilarityScoreComparator c = new AscendingSimilarityScoreComparator(); assertEquals(c.compare(first, second), 0); assertEquals(c.compare(second, first), 0); }
/** * Compares two similarity scores. * @param x The first score to be compared. * @param y The second score to be compared. * @return a negative integer, zero, or a positive integer as the first score is less than, * equal to, or greater than the second score. */ public int compare(SimilarityScore x, SimilarityScore y) { double first = x.getScore(); double second = y.getScore(); if (first == second) { return 0; } if (first < second) { return -1; } return 1; }
@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); }
/** * Compares two similarity scores. * @param x The first score to be compared. * @param y The second score to be compared. * @return a negative integer, zero, or a positive integer as the first score is less than, * equal to, or greater than the second score. */ public int compare(SimilarityScore x, SimilarityScore y) { double first = x.getScore(); double second = y.getScore(); if (first == second) { return 0; } if (first < second) { return -1; } return 1; }
@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); }