public List<PhraseMatch> findNonOverlappingPhrases(List<PhraseMatch> phraseMatches) { if (phraseMatches.size() > 1) { return IntervalTree.getNonOverlapping(phraseMatches, PHRASEMATCH_LENGTH_ENDPOINTS_COMPARATOR); } else { return phraseMatches; } }
public static <T, E extends Comparable<E>> List<T> getNonOverlapping( List<? extends T> items, Function<? super T,Interval<E>> toIntervalFunc, Comparator<? super T> compareFunc) { List<T> sorted = new ArrayList<>(items); Collections.sort(sorted, compareFunc); return getNonOverlapping(sorted, toIntervalFunc); }
public static <T extends MatchedExpression> List<T> removeOverlapping(List<T> chunks) { if (chunks.size() > 1) { for (int i = 0, sz = chunks.size(); i < sz; i++) { chunks.get(i).order = i; } return IntervalTree.getNonOverlapping(chunks, EXPR_TO_TOKEN_OFFSETS_INTERVAL_FUNC, EXPR_PRIORITY_LENGTH_COMPARATOR); } else { return chunks; } }
/** * Given a list of matches, returns all non-overlapping matches. * * @param allMatches List of matches * @param compareFunc Comparison function to use for evaluating which overlapping sub-sequence to keep. * Earlier sub-sequences based on the comparison function are favored. * @return List of matches sorted by start position */ public List<Match<K,V>> getNonOverlapping(List<Match<K,V>> allMatches, Comparator<? super Match<K,V>> compareFunc) { if (allMatches.size() > 1) { List<Match<K,V>> nonOverlapping = IntervalTree.getNonOverlapping(allMatches, compareFunc); nonOverlapping.sort(HasInterval.ENDPOINTS_COMPARATOR); return nonOverlapping; } else { return allMatches; } }
public static <T extends HasInterval<E>, E extends Comparable<E>> List<T> getNonOverlapping( List<? extends T> items) { Function<T,Interval<E>> toIntervalFunc = in -> in.getInterval(); return getNonOverlapping(items, toIntervalFunc); }
public static <T extends HasInterval<E>, E extends Comparable<E>> List<T> getNonOverlapping( List<? extends T> items, Comparator<? super T> compareFunc) { Function<T,Interval<E>> toIntervalFunc = in -> in.getInterval(); return getNonOverlapping(items, toIntervalFunc, compareFunc); }
/** * Given a sequence, applies our patterns over the sequence and returns * all non overlapping matches. When multiple patterns overlaps, * matched patterns are selected by order specified by the comparator * @param elements input sequence to match against * @param cmp comparator indicating order that overlapped sequences should be selected. * @return list of match results that are non-overlapping */ public List<SequenceMatchResult<T>> findNonOverlapping(List<? extends T> elements, Comparator<? super SequenceMatchResult> cmp) { Collection<SequencePattern<T>> triggered = getTriggeredPatterns(elements); List<SequenceMatchResult<T>> all = new ArrayList<>(); int i = 0; for (SequencePattern<T> p:triggered) { if (Thread.interrupted()) { // Allow interrupting throw new RuntimeInterruptedException(); } SequenceMatcher<T> m = p.getMatcher(elements); m.setMatchWithResult(matchWithResult); m.setOrder(i); while (m.find()) { all.add(m.toBasicSequenceMatchResult()); } i++; } List<SequenceMatchResult<T>> res = IntervalTree.getNonOverlapping( all, SequenceMatchResult.TO_INTERVAL, cmp); res.sort(SequenceMatchResult.OFFSET_COMPARATOR); return res; }
/** * Given a sequence, applies our patterns over the sequence and returns * all matches, depending on the findType. When multiple patterns overlaps, * matched patterns are selected by order specified by the comparator * @param elements input sequence to match against * @param findType whether FindType.FIND_ALL or FindType.FIND_NONOVERLAPPING * @return list of match results */ public List<SequenceMatchResult<T>> find(List<? extends T> elements, SequenceMatcher.FindType findType) { Collection<SequencePattern<T>> triggered = getTriggeredPatterns(elements); List<SequenceMatchResult<T>> all = new ArrayList<>(); int i = 0; for (SequencePattern<T> p:triggered) { if (Thread.interrupted()) { // Allow interrupting throw new RuntimeInterruptedException(); } SequenceMatcher<T> m = p.getMatcher(elements); m.setMatchWithResult(matchWithResult); m.setFindType(findType); m.setOrder(i); while (m.find()) { all.add(m.toBasicSequenceMatchResult()); } i++; } List<SequenceMatchResult<T>> res = IntervalTree.getNonOverlapping( all, SequenceMatchResult.TO_INTERVAL, SequenceMatchResult.DEFAULT_COMPARATOR); res.sort(SequenceMatchResult.OFFSET_COMPARATOR); return res; }
public static <T extends HasInterval<E>, E extends Comparable<E>> List<T> getNonOverlapping( List<? extends T> items) { Function<T,Interval<E>> toIntervalFunc = new Function<T, Interval<E>>() { @Override public Interval<E> apply(T in) { return in.getInterval(); } }; return getNonOverlapping(items, toIntervalFunc); }
public List<PhraseMatch> findNonOverlappingPhrases(List<PhraseMatch> phraseMatches) { if (phraseMatches.size() > 1) { return IntervalTree.getNonOverlapping(phraseMatches, PHRASEMATCH_LENGTH_ENDPOINTS_COMPARATOR); } else { return phraseMatches; } }
public List<PhraseMatch> findNonOverlappingPhrases(List<PhraseMatch> phraseMatches) { if (phraseMatches.size() > 1) { return IntervalTree.getNonOverlapping(phraseMatches, PHRASEMATCH_LENGTH_ENDPOINTS_COMPARATOR); } else { return phraseMatches; } }
public static <T, E extends Comparable<E>> List<T> getNonOverlapping( List<? extends T> items, Function<? super T,Interval<E>> toIntervalFunc, Comparator<? super T> compareFunc) { List<T> sorted = new ArrayList<>(items); Collections.sort(sorted, compareFunc); return getNonOverlapping(sorted, toIntervalFunc); }
public static <T, E extends Comparable<E>> List<T> getNonOverlapping( List<? extends T> items, Function<? super T,Interval<E>> toIntervalFunc, Comparator<? super T> compareFunc) { List<T> sorted = new ArrayList<T>(items); Collections.sort(sorted, compareFunc); return getNonOverlapping(sorted, toIntervalFunc); }
public static <T, E extends Comparable<E>> List<T> getNonOverlapping( List<? extends T> items, Function<? super T,Interval<E>> toIntervalFunc, Comparator<? super T> compareFunc) { List<T> sorted = new ArrayList<>(items); Collections.sort(sorted, compareFunc); return getNonOverlapping(sorted, toIntervalFunc); }
private static List<TimeExpression> removeNested(List<TimeExpression> chunks) { if (chunks.size() > 1) { // TODO: presort chunks by priority, length, given order for (int i = 0; i < chunks.size(); i++) { chunks.get(i).order = i; } return IntervalTree.getNonOverlapping(chunks, TIME_EXPR_TO_TOKEN_OFFSETS_INTERVAL_FUNC, TIME_EXPR_PRIORITY_LENGTH_COMPARATOR /* TIME_EXPR_LENGTH_COMPARATOR */); } else { return chunks; } }
public static <T extends MatchedExpression> List<T> removeOverlapping(List<T> chunks) { if (chunks.size() > 1) { for (int i = 0, sz = chunks.size(); i < sz; i++) { chunks.get(i).order = i; } return IntervalTree.getNonOverlapping(chunks, EXPR_TO_TOKEN_OFFSETS_INTERVAL_FUNC, EXPR_PRIORITY_LENGTH_COMPARATOR); } else { return chunks; } }
public static <T extends MatchedExpression> List<T> removeOverlapping(List<T> chunks) { if (chunks.size() > 1) { for (int i = 0, sz = chunks.size(); i < sz; i++) { chunks.get(i).order = i; } return IntervalTree.getNonOverlapping(chunks, EXPR_TO_TOKEN_OFFSETS_INTERVAL_FUNC, EXPR_PRIORITY_LENGTH_COMPARATOR); } else { return chunks; } }
public static <T extends HasInterval<E>, E extends Comparable<E>> List<T> getNonOverlapping( List<? extends T> items) { Function<T,Interval<E>> toIntervalFunc = in -> in.getInterval(); return getNonOverlapping(items, toIntervalFunc); }
public static <T extends HasInterval<E>, E extends Comparable<E>> List<T> getNonOverlapping( List<? extends T> items) { Function<T,Interval<E>> toIntervalFunc = in -> in.getInterval(); return getNonOverlapping(items, toIntervalFunc); }
public static <T extends HasInterval<E>, E extends Comparable<E>> List<T> getNonOverlapping( List<? extends T> items, Comparator<? super T> compareFunc) { Function<T,Interval<E>> toIntervalFunc = in -> in.getInterval(); return getNonOverlapping(items, toIntervalFunc, compareFunc); }