@Test public void calculateMinimalDistanceReturnsMinimalDistanceToRootTermAndDerivedTerms() { var rootTerm = "banana"; var derivedTerms = Set.of("yellow-thing", "monkey-snack"); var term = "yllow-thing"; var expectedMinDistance = 1; var calculator = new RootTermDistanceCalculator(rootTerm, derivedTerms); var actualMinDistance = calculator.calculateMinimalDistance(term); assertThat(actualMinDistance).isEqualTo(expectedMinDistance); }
public int calculateMinimalDistance(String stringToMatch) { var lowerCaseStringToMatch = stringToMatch.toLowerCase(); var mergedSet = mergeRootTermAndDerivedTerms(); boolean matchesRootTermOrDerivedTerm = mergedSet.contains(lowerCaseStringToMatch); if(matchesRootTermOrDerivedTerm) { return 0; } return mergedSet.parallelStream() .mapToInt(term -> calculateLevenshteinDistance(term, lowerCaseStringToMatch)) .min() .orElse(0); }
RootTermDistanceCalculator { public int calculateMinimalDistance(String stringToMatch) { var lowerCaseStringToMatch = stringToMatch.toLowerCase(); var mergedSet = mergeRootTermAndDerivedTerms(); boolean matchesRootTermOrDerivedTerm = mergedSet.contains(lowerCaseStringToMatch); if(matchesRootTermOrDerivedTerm) { return 0; } return mergedSet.parallelStream() .mapToInt(term -> calculateLevenshteinDistance(term, lowerCaseStringToMatch)) .min() .orElse(0); } }
RootTermDistanceCalculator { public int calculateMinimalDistance(String stringToMatch) { var lowerCaseStringToMatch = stringToMatch.toLowerCase(); var mergedSet = mergeRootTermAndDerivedTerms(); boolean matchesRootTermOrDerivedTerm = mergedSet.contains(lowerCaseStringToMatch); if(matchesRootTermOrDerivedTerm) { return 0; } return mergedSet.parallelStream() .mapToInt(term -> calculateLevenshteinDistance(term, lowerCaseStringToMatch)) .min() .orElse(0); } RootTermDistanceCalculator(String rootTerm, Set<String> derivedTerms); }
RootTermDistanceCalculator { public int calculateMinimalDistance(String stringToMatch) { var lowerCaseStringToMatch = stringToMatch.toLowerCase(); var mergedSet = mergeRootTermAndDerivedTerms(); boolean matchesRootTermOrDerivedTerm = mergedSet.contains(lowerCaseStringToMatch); if(matchesRootTermOrDerivedTerm) { return 0; } return mergedSet.parallelStream() .mapToInt(term -> calculateLevenshteinDistance(term, lowerCaseStringToMatch)) .min() .orElse(0); } RootTermDistanceCalculator(String rootTerm, Set<String> derivedTerms); int calculateMinimalDistance(String stringToMatch); static String nearestRootTerm(Set<RootTermDistanceCalculator> distanceCalculators, String term, int threshold); }
RootTermDistanceCalculator { public int calculateMinimalDistance(String stringToMatch) { var lowerCaseStringToMatch = stringToMatch.toLowerCase(); var mergedSet = mergeRootTermAndDerivedTerms(); boolean matchesRootTermOrDerivedTerm = mergedSet.contains(lowerCaseStringToMatch); if(matchesRootTermOrDerivedTerm) { return 0; } return mergedSet.parallelStream() .mapToInt(term -> calculateLevenshteinDistance(term, lowerCaseStringToMatch)) .min() .orElse(0); } RootTermDistanceCalculator(String rootTerm, Set<String> derivedTerms); int calculateMinimalDistance(String stringToMatch); static String nearestRootTerm(Set<RootTermDistanceCalculator> distanceCalculators, String term, int threshold);  }