use of org.eclipse.sw360.cvesearch.datasource.matcher.Match in project sw360portal by sw360.
the class SearchLevels method guessForRelease.
private List<NeedleWithMeta> guessForRelease(CveSearchGuesser cveSearchGuesser, Release release, boolean useVersionInformation) throws IOException {
if (useVersionInformation && !release.isSetVersion()) {
return Collections.emptyList();
}
List<Match> vendorProductList;
String productHaystack = release.getName();
if (release.isSetVendor() && (release.getVendor().isSetShortname() || release.getVendor().isSetFullname())) {
String vendorHaystack = nullToEmptyString(release.getVendor().getShortname()) + " " + nullToEmptyString(release.getVendor().getFullname());
vendorProductList = cveSearchGuesser.guessVendorAndProducts(vendorHaystack, productHaystack);
} else {
vendorProductList = cveSearchGuesser.guessVendorAndProducts(productHaystack);
}
String cpeNeedlePostfix = ":" + (useVersionInformation ? release.getVersion() : "") + CPE_WILDCARD;
Function<String, String> cpeBuilder = cpeNeedle -> CPE_NEEDLE_PREFIX + cpeNeedle + cpeNeedlePostfix;
return vendorProductList.stream().map(match -> new NeedleWithMeta(cpeBuilder.apply(match.getNeedle()), "heuristic (dist. " + (useVersionInformation ? "0" : "1") + match.getDistance() + ")")).collect(Collectors.toList());
}
use of org.eclipse.sw360.cvesearch.datasource.matcher.Match in project sw360portal by sw360.
the class CveSearchGuesser method getBest.
public List<Match> getBest(List<Match> matches, int threshold) {
if (matches.size() == 0) {
return Collections.EMPTY_LIST;
}
List<Match> bestMatches = new ArrayList<>();
int minDistance = matches.get(0).getDistance();
Iterator<Match> matchesIterator = matches.iterator();
Match current;
do {
current = matchesIterator.next();
if (current.getDistance() > minDistance + threshold || current.getDistance() >= cutoff) {
break;
}
bestMatches.add(current);
} while (matchesIterator.hasNext());
return bestMatches;
}
use of org.eclipse.sw360.cvesearch.datasource.matcher.Match in project sw360portal by sw360.
the class ModifiedLevenshteinDistanceTest method getDistanceTest.
@Test
public void getDistanceTest() {
String needle = "needle";
String haystack = "haystack";
Match match = levenshteinMatch(needle, haystack);
assertThat(match.getNeedle(), is(needle));
assertThat(match.getDistance(), is(greaterThan(0)));
}
use of org.eclipse.sw360.cvesearch.datasource.matcher.Match in project sw360portal by sw360.
the class ModifiedLevenshteinDistanceTest method getDistanceTestUpToPostfixMatch.
@Test
public void getDistanceTestUpToPostfixMatch() {
String needle = "needle";
String haystack = "needle postfix";
Match match = levenshteinMatch(needle, haystack);
assertThat(match.getDistance(), is(0));
}
use of org.eclipse.sw360.cvesearch.datasource.matcher.Match in project sw360portal by sw360.
the class ModifiedLevenshteinDistanceTest method getDistanceTestPartialSubstringMatch.
@Test
public void getDistanceTestPartialSubstringMatch() {
String needle = "needle";
String noise = "bla";
String haystack = "prefix needle" + noise + " postfix";
Match match = levenshteinMatch(needle, haystack);
assertThat(match.getDistance(), is(noise.length()));
}
Aggregations