@Test(expected = IllegalArgumentException.class) public void testGetFuzzyDistance_NullStringLocale() throws Exception { StringUtils.getFuzzyDistance(null, "clear", Locale.ENGLISH); }
@Test(expected = IllegalArgumentException.class) public void testGetFuzzyDistance_NullNullNull() throws Exception { StringUtils.getFuzzyDistance(null, null, null); }
@Test public void testGetFuzzyDistance() throws Exception { assertEquals(0, StringUtils.getFuzzyDistance("", "", Locale.ENGLISH)); assertEquals(0, StringUtils.getFuzzyDistance("Workshop", "b", Locale.ENGLISH)); assertEquals(1, StringUtils.getFuzzyDistance("Room", "o", Locale.ENGLISH)); assertEquals(1, StringUtils.getFuzzyDistance("Workshop", "w", Locale.ENGLISH)); assertEquals(2, StringUtils.getFuzzyDistance("Workshop", "ws", Locale.ENGLISH)); assertEquals(4, StringUtils.getFuzzyDistance("Workshop", "wo", Locale.ENGLISH)); assertEquals(3, StringUtils.getFuzzyDistance("Apache Software Foundation", "asf", Locale.ENGLISH)); }
@Test(expected = IllegalArgumentException.class) public void testGetFuzzyDistance_StringNullLoclae() throws Exception { StringUtils.getFuzzyDistance(" ", null, Locale.ENGLISH); }
@Test(expected = IllegalArgumentException.class) public void testGetFuzzyDistance_StringStringNull() throws Exception { StringUtils.getFuzzyDistance(" ", "clear", null); }
/******************************************************************************************************************* * * * * ******************************************************************************************************************/ public static int similarity (final @Nonnull String a, final @Nonnull String b) { int score = StringUtils.getFuzzyDistance(a.toLowerCase(), b.toLowerCase(), Locale.UK); // // While this is a hack, it isn't so ugly as it might appear. The idea is to give a lower score to // collections and records with a generic title, hoping that a better one is picked. // FIXME: put into a map and then into an external resource with the delta score associated. // FIXME: with the filtering on collection size, this might be useless? // if (a.matches("^Great Violin Concertos.*") || a.matches("^CBS Great Performances.*")) { score -= 50; } if (a.matches("^Piano Concertos$") || a.matches("^Klavierkonzerte$")) { score -= 30; } return score; }
private static Set<CombinedFuzzySearchResult> performFuzzyStringSearch(String searchString, Collection<String> stringsToSearch) { Set<CombinedFuzzySearchResult> resultsOfFuzzyDistanceSearch = new HashSet<>(); for (String stringToSearch : stringsToSearch) { int fuzzyDistance = StringUtils.getFuzzyDistance(stringToSearch, searchString, Locale.ENGLISH); if (fuzzyDistance > 0) { resultsOfFuzzyDistanceSearch .add(new CombinedFuzzySearchResult(stringToSearch, CombinedFuzzySearchResult.CombinedFuzzySearchResultType.FUZZY, fuzzyDistance, searchString.split(""))); } } TreeSet<CombinedFuzzySearchResult> sortedResults = new TreeSet<>(new SortFuzzyMatchesDescendingByFuzzyDistanceComparator()); sortedResults.addAll(resultsOfFuzzyDistanceSearch); return sortedResults; }
private static Set<CombinedFuzzySearchResult> performFuzzyStringSearch(String searchString, Collection<String> stringsToSearch) { Set<CombinedFuzzySearchResult> resultsOfFuzzyDistanceSearch = new HashSet<>(); for (String stringToSearch : stringsToSearch) { int fuzzyDistance = StringUtils.getFuzzyDistance(stringToSearch, searchString, Locale.ENGLISH); if (fuzzyDistance > 0) { resultsOfFuzzyDistanceSearch .add(new CombinedFuzzySearchResult(stringToSearch, CombinedFuzzySearchResult.CombinedFuzzySearchResultType.FUZZY, fuzzyDistance, searchString.split(""))); } } TreeSet<CombinedFuzzySearchResult> sortedResults = new TreeSet<>(new SortFuzzyMatchesDescendingByFuzzyDistanceComparator()); sortedResults.addAll(resultsOfFuzzyDistanceSearch); return sortedResults; }
for (int i = 0; i < tokensList.length; i++) { if (f[i] == max && tokensList[i].length - f[i] == min) { int d = StringUtils.getFuzzyDistance(tokens[i].getValue(), source, Locale.ENGLISH); if (d > best) { best = d;