All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.crydee.ahocorasick.AhoCorasickHelpers Maven / Gradle / Ivy

package eu.crydee.ahocorasick;

import com.google.common.collect.SetMultimap;
import java.util.AbstractMap;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collectors;

public class AhoCorasickHelpers {

    public static  SortedSet toOccurrenceList(
            SetMultimap searchResult,
            List patterns,
            boolean isPatternToPos) {
        return searchResult.entries().stream()
                .map(e -> isPatternToPos
                                ? new AbstractMap.SimpleEntry<>(
                                        e.getValue(),
                                        e.getKey())
                                : e)
                .map(e -> new Occurrence(
                                e.getKey()
                                - patterns.get(e.getValue()).length
                                + 1,
                                e.getKey(),
                                e.getValue()))
                .collect(Collectors.toCollection(() -> new TreeSet<>()));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy