@Test public void calculateMinimalDistanceReturnsZeroWhenTermEqualsDerivedTerm() { var rootTerm = "banana"; var derivedTerm = "yellow-thing"; var term = derivedTerm; var calculator = new RootTermDistanceCalculator(rootTerm, Set.of(derivedTerm)); var actualMinDistance = calculator.calculateMinimalDistance(term); assertThat(actualMinDistance).isEqualTo(0); }
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);  }