Search in sources :

Example 1 with Match

use of org.eclipse.sw360.cvesearch.datasource.matcher.Match in project sw360portal by sw360.

the class ModifiedLevenshteinDistanceTest method getDistanceTestFullSubstringMatch.

@Test
public void getDistanceTestFullSubstringMatch() {
    String needle = "needle";
    String noise = "bla";
    String haystack = "prefix needle " + noise + " postfix";
    Match match = levenshteinMatch(needle, haystack);
    assertThat(match.getDistance(), is(0));
}
Also used : ModifiedLevenshteinDistance.levenshteinMatch(org.eclipse.sw360.cvesearch.datasource.matcher.ModifiedLevenshteinDistance.levenshteinMatch) Test(org.junit.Test)

Example 2 with Match

use of org.eclipse.sw360.cvesearch.datasource.matcher.Match in project sw360portal by sw360.

the class ModifiedLevenshteinDistanceTest method getDistanceTestFullMatch.

@Test
public void getDistanceTestFullMatch() {
    String needle = "needle";
    String haystack = "needle";
    Match match = levenshteinMatch(needle, haystack);
    assertThat(match.getDistance(), is(0));
}
Also used : ModifiedLevenshteinDistance.levenshteinMatch(org.eclipse.sw360.cvesearch.datasource.matcher.ModifiedLevenshteinDistance.levenshteinMatch) Test(org.junit.Test)

Example 3 with Match

use of org.eclipse.sw360.cvesearch.datasource.matcher.Match in project sw360portal by sw360.

the class ModifiedLevenshteinDistanceTest method getDistanceTestUpToPrefixMatch.

@Test
public void getDistanceTestUpToPrefixMatch() {
    String needle = "needle";
    String haystack = "prefix needle";
    Match match = levenshteinMatch(needle, haystack);
    assertThat(match.getDistance(), is(0));
}
Also used : ModifiedLevenshteinDistance.levenshteinMatch(org.eclipse.sw360.cvesearch.datasource.matcher.ModifiedLevenshteinDistance.levenshteinMatch) Test(org.junit.Test)

Example 4 with Match

use of org.eclipse.sw360.cvesearch.datasource.matcher.Match in project sw360portal by sw360.

the class ModifiedLevenshteinDistanceTest method getDistanceTestPartialMatch.

@Test
public void getDistanceTestPartialMatch() {
    String needle = "needle";
    String haystack = "ndle";
    Match match = levenshteinMatch(needle, haystack);
    assertThat(match.getDistance(), is(2));
}
Also used : ModifiedLevenshteinDistance.levenshteinMatch(org.eclipse.sw360.cvesearch.datasource.matcher.ModifiedLevenshteinDistance.levenshteinMatch) Test(org.junit.Test)

Example 5 with Match

use of org.eclipse.sw360.cvesearch.datasource.matcher.Match in project sw360portal by sw360.

the class CveSearchGuesser method guessVendorAndProducts.

public List<Match> guessVendorAndProducts(String vendorHaystack, String productHaystack) throws IOException {
    List<Match> result = new ArrayList<>();
    List<Match> vendors = guessVendors(vendorHaystack);
    for (Match vendor : vendors) {
        result.addAll(guessProducts(vendor.getNeedle(), productHaystack).stream().map(product -> vendor.concat(product)).collect(Collectors.toList()));
    }
    return result.stream().sorted((sm1, sm2) -> sm1.compareTo(sm2)).filter(sm -> cutoff == 0 || cutoff > sm.getDistance()).collect(Collectors.toList());
}
Also used : ListMatcher(org.eclipse.sw360.cvesearch.datasource.matcher.ListMatcher) Logger(org.apache.log4j.Logger) java.util(java.util) Match(org.eclipse.sw360.cvesearch.datasource.matcher.Match) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Match(org.eclipse.sw360.cvesearch.datasource.matcher.Match)

Aggregations

Test (org.junit.Test)8 ModifiedLevenshteinDistance.levenshteinMatch (org.eclipse.sw360.cvesearch.datasource.matcher.ModifiedLevenshteinDistance.levenshteinMatch)7 Match (org.eclipse.sw360.cvesearch.datasource.matcher.Match)3 IOException (java.io.IOException)2 Collectors (java.util.stream.Collectors)2 Logger (org.apache.log4j.Logger)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 PrintWriter (java.io.PrintWriter)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Properties (java.util.Properties)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Stream (java.util.stream.Stream)1 TException (org.apache.thrift.TException)1 CveSearchApi (org.eclipse.sw360.cvesearch.datasource.CveSearchApi)1