public SequenceMatcher<T> matcher(List<T> list) { return pattern.getMatcher(list); }
public boolean match(List<T> list) { return pattern.getMatcher(list).matches(); }
@Override public O apply(List<? extends T> seq) { if (seq == null) return null; SequenceMatcher<T> m = pattern.getMatcher(seq); m.setMatchWithResult(matchWithResult); if (m.matches()) { return extractor.apply(m); } else { return null; } }
public SequenceMatchResult<T> apply(SequenceMatchResult<T> seqMatchResult, int... groups) { SequenceMatcher<T> matcher = pattern.getMatcher(seqMatchResult.elements()); if (matcher.find()) { return matcher; } else { return null; } } }
public Object matchWithResult(List<T> list) { SequenceMatcher<T> m = pattern.getMatcher(list); if (m.matches()) { return m.toBasicSequenceMatchResult(); } else { return null; } }
@Override public boolean extract(List<? extends T> seq, List<O> out) { if (seq == null) return false; boolean extracted = false; SequenceMatcher<T> m = pattern.getMatcher(seq); if (findType != null) { m.setFindType(findType); } m.setMatchWithResult(matchWithResult); while (m.find()) { out.add(extractor.apply(m)); extracted = true; } // System.err.println("SequencePattern " + pattern + " of type " + pattern.getClass() + " matched on " + extracted); return extracted; }
/** * Given a sequence, applies each of our patterns over the sequence and returns * all non overlapping matches for each of the patterns. * Unlike #findAllNonOverlapping, overlapping matches from different patterns are kept. * * @param elements input sequence to match against * @return iterable of match results that are non-overlapping */ public Iterable<SequenceMatchResult<T>> findAllNonOverlappingMatchesPerPattern(List<? extends T> elements) { Collection<SequencePattern<T>> triggered = getTriggeredPatterns(elements); List<Iterable<SequenceMatchResult<T>>> allMatches = new ArrayList<>(elements.size()); for (SequencePattern<T> p:triggered) { SequenceMatcher<T> m = p.getMatcher(elements); m.setMatchWithResult(matchWithResult); Iterable<SequenceMatchResult<T>> matches = m.findAllNonOverlapping(); allMatches.add(matches); } return Iterables.chain(allMatches); }
/** * Given a sequence, applies our patterns over the sequence and returns * all non overlapping matches. When multiple patterns overlaps, * matched patterns are selected to give the overall maximum score. * * @param elements input sequence to match against * @param scorer scorer for scoring each match * @return list of match results that are non-overlapping */ public List<SequenceMatchResult<T>> findNonOverlappingMaxScore(List<? extends T> elements, ToDoubleFunction<? super SequenceMatchResult> scorer) { Collection<SequencePattern<T>> triggered = getTriggeredPatterns(elements); List<SequenceMatchResult<T>> all = new ArrayList<>(); int i = 0; for (SequencePattern<T> p:triggered) { 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.getNonOverlappingMaxScore( all, SequenceMatchResult.TO_INTERVAL, scorer); res.sort(SequenceMatchResult.OFFSET_COMPARATOR); return res; }
/** * 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; }
SequenceMatcher<? super IN> matcher = sentenceBoundaryMultiTokenPattern.getMatcher(words); while (matcher.find()) { List<? super IN> nodes = matcher.groupNodes();
/** * 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; }
@Override public O apply(List<? extends T> seq) { if (seq == null) return null; SequenceMatcher<T> m = pattern.getMatcher(seq); m.setMatchWithResult(matchWithResult); if (m.matches()) { return extractor.apply(m); } else { return null; } }
public Object matchWithResult(List<T> list) { SequenceMatcher<T> m = pattern.getMatcher(list); if (m.matches()) { return m.toBasicSequenceMatchResult(); } else { return null; } }
public SequenceMatchResult<T> apply(SequenceMatchResult<T> seqMatchResult, int... groups) { SequenceMatcher<T> matcher = pattern.getMatcher(seqMatchResult.elements()); if (matcher.find()) { return matcher; } else { return null; } } }
public Object matchWithResult(List<T> list) { SequenceMatcher<T> m = pattern.getMatcher(list); if (m.matches()) { return m.toBasicSequenceMatchResult(); } else { return null; } }
public Object matchWithResult(List<T> list) { SequenceMatcher<T> m = pattern.getMatcher(list); if (m.matches()) { return m.toBasicSequenceMatchResult(); } else { return null; } }
public SequenceMatchResult<T> apply(SequenceMatchResult<T> seqMatchResult, int... groups) { SequenceMatcher<T> matcher = pattern.getMatcher(seqMatchResult.elements()); if (matcher.find()) { return matcher; } else { return null; } } }
public SequenceMatchResult<T> apply(SequenceMatchResult<T> seqMatchResult, int... groups) { SequenceMatcher<T> matcher = pattern.getMatcher(seqMatchResult.elements()); if (matcher.find()) { return matcher; } else { return null; } } }
public O apply(List<? extends T> seq) { if (seq == null) return null; SequenceMatcher<T> m = pattern.getMatcher(seq); m.setMatchWithResult(matchWithResult); if (m.matches()) { return extractor.apply(m); } else { return null; } } }
public boolean extract(List<? extends CoreMap> tokens, List<TimeExpression> out) { boolean extracted = false; SequenceMatcher<CoreMap> m = pattern.getMatcher(tokens); while (m.find()) { TimeExpression te = new TimeExpression(null, Interval.toInterval(m.start(group), m.end(group), Interval.INTERVAL_OPEN_END), extractor, m.score()); te.includeNested = includeNested; out.add(te); extracted = true; } return extracted; }