
com.intuit.fuzzymatcher.component.ElementMatch Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fuzzy-matcher Show documentation
Show all versions of fuzzy-matcher Show documentation
A java library to determine probability of objects being similar
package com.intuit.fuzzymatcher.component;
import com.intuit.fuzzymatcher.domain.Element;
import com.intuit.fuzzymatcher.domain.Match;
import com.intuit.fuzzymatcher.domain.Score;
import com.intuit.fuzzymatcher.domain.Token;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Matches at element level with aggregated results from token.
* This uses the ScoringFunction defined at each element to get the aggregated Element score for matched tokens
*/
@Component
public class ElementMatch {
@Autowired
private TokenMatch tokenMatch;
public Stream> matchElements(Stream elements) {
Stream tokenStream = elements.flatMap(Element::getTokens);
Stream> matchedTokens = tokenMatch.matchTokens(tokenStream);
return rollupElementScore(matchedTokens);
}
private Stream> rollupElementScore(Stream> matchedTokenStream) {
Map>>> groupBy = matchedTokenStream
.collect(Collectors.groupingBy((matchToken -> matchToken.getData().getElement()),
Collectors.groupingBy(matchToken -> matchToken.getMatchedWith().getElement())));
return groupBy.entrySet().parallelStream().flatMap(leftElementEntry ->
leftElementEntry.getValue().entrySet().parallelStream().map(rightElementEntry -> {
List childScoreList = rightElementEntry.getValue()
.stream().map(d -> d.getScore())
.collect(Collectors.toList());
return new Match(leftElementEntry.getKey(), rightElementEntry.getKey(), childScoreList);
}).filter(match -> match.getResult() > match.getData().getThreshold()));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy