public Interval<Integer> getInterval() { if (span == null) span = Interval.toInterval(tokenBegin, tokenEnd, Interval.INTERVAL_OPEN_END); return span; } }
public Interval<Integer> getInterval() { if (span == null) span = Interval.toInterval(begin, end, Interval.INTERVAL_OPEN_END); return span; } }
/** * Create an interval with the specified endpoints in the specified order. * Returns null if a does not come before b (invalid interval). * * @param a start endpoints * @param b end endpoint * @param <E> type of the interval endpoints * @return Interval with endpoints in specified order, null if a does not come before b */ public static <E extends Comparable<E>> Interval<E> toInterval(E a, E b) { return toInterval(a,b,0); }
public static <E extends Comparable<E>, T extends HasInterval<E>> void getOverlapping(TreeNode<E,T> n, E p, List<T> result) { getOverlapping(n, Interval.toInterval(p,p), result); }
public static <E extends Comparable<E>, T extends HasInterval<E>> boolean overlaps(TreeNode<E,T> n, E p) { return overlaps(n, Interval.toInterval(p,p)); } public static <E extends Comparable<E>, T extends HasInterval<E>> boolean overlaps(TreeNode<E,T> node, Interval<E> target) {
public static <E extends Comparable<E>, T extends HasInterval<E>> boolean containsInterval(IntervalTree<E,T> n, E p, boolean exact) { return containsInterval(n, Interval.toInterval(p, p), exact); }
protected Collection<Interval<Integer>> match(List<? extends CoreMap> nodes, int start) { List<Interval<Integer>> matched = new ArrayList<>(); int minEnd = start + minNodes; int maxEnd = nodes.size(); if (maxNodes >= 0 && maxNodes + start < nodes.size()) { maxEnd = maxNodes + start; } for (int end = minEnd; end <= maxEnd; end++) { CoreMap chunk = ChunkAnnotationUtils.getMergedChunk(nodes, start, end, aggregators, null); if (nodePattern.match(chunk)) { matched.add(Interval.toInterval(start, end)); } } return matched; }
@Override public boolean extract(List<? extends CoreMap> seq, List<MatchedExpression> out) { boolean extracted = false; for (int i = 0; i < seq.size(); i++) { CoreMap t = seq.get(i); Value v = extractor.apply(t); if (v != null) { MatchedExpression te = extractor.createMatchedExpression(Interval.toInterval(i, i + 1, Interval.INTERVAL_OPEN_END), null); out.add(te); extracted = true; } } return extracted; } }
/** * Returns interval that is the intersection of this and the other interval * Returns null if intersect is null * @param other interval with which to intersect * @return interval that is the intersection of this and the other interval */ public Interval intersect(Interval<E> other) { if (other == null) return null; E a = max(this.first, other.first); E b = min(this.second, other.second); return toInterval(a,b); }
@Override public Interval<Integer> apply(MR in) { return Interval.toInterval(in.start(group), in.end(group), Interval.INTERVAL_OPEN_END); } }
/** * Returns (smallest) interval that contains both this and the other interval * @param other - Other interval to include * @return Smallest interval that contains both this and the other interval */ public Interval expand(Interval<E> other) { if (other == null) return this; E a = min(this.first, other.first); E b = max(this.second, other.second); return toInterval(a,b); }
/** * Return chunk offsets * @param chunkList - List of chunks * @param charStart - character begin offset * @param charEnd - character end offset * @return chunk offsets */ public static Interval<Integer> getChunkOffsetsUsingCharOffsets(List<? extends CoreMap> chunkList, int charStart, int charEnd) { int chunkStart = 0; int chunkEnd = chunkList.size(); // Find first chunk with start > charStart for (int i = 0; i < chunkList.size(); i++) { int start = chunkList.get(i).get(CoreAnnotations.CharacterOffsetBeginAnnotation.class); if (start > charStart) { break; } chunkStart = i; } // Find first chunk with start >= charEnd for (int i = chunkStart; i < chunkList.size(); i++) { int start = chunkList.get(i).get(CoreAnnotations.CharacterOffsetBeginAnnotation.class); if (start >= charEnd) { chunkEnd = i; break; } } return Interval.toInterval(chunkStart, chunkEnd, Interval.INTERVAL_OPEN_END); }
int p = res.end-1; if (res.alignments[p] == null) { res.alignments[p] = Interval.toInterval(res.matched.size()-1, res.matched.size()); } else { res.alignments[p] = Interval.toInterval(res.alignments[p].getBegin(), res.alignments[p].getEnd() + 1);
@Override public MatchedExpression apply(MatchResult matched) { MatchedExpression te = extractor.createMatchedExpression(Interval.toInterval(matched.start(group), matched.end(group), Interval.INTERVAL_OPEN_END), null); return te; } }
@Override public MatchedExpression apply(SequenceMatchResult<CoreMap> matched) { MatchedExpression te = extractor.createMatchedExpression(null, Interval.toInterval(matched.start(group), matched.end(group), Interval.INTERVAL_OPEN_END)); if (Double.isNaN(te.priority)) { te.priority = matched.priority(); } if (Double.isNaN(te.weight)) { te.weight = matched.score(); } if (this.group != 0) { // Save context so value evaluation can happen te.context = matched.toBasicSequenceMatchResult(); } return te; } }
protected boolean extractAnnotation(List<? extends CoreMap> source, CoreMapAggregator aggregator) { annotation = aggregator.merge(source, chunkOffsets.getBegin(), chunkOffsets.getEnd()); charOffsets = Interval.toInterval(annotation.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class), annotation.get(CoreAnnotations.CharacterOffsetEndAnnotation.class), Interval.INTERVAL_OPEN_END); tokenOffsets = Interval.toInterval(annotation.get(CoreAnnotations.TokenBeginAnnotation.class), annotation.get(CoreAnnotations.TokenEndAnnotation.class), Interval.INTERVAL_OPEN_END); text = annotation.get(CoreAnnotations.TextAnnotation.class); extractFunc.annotate(this, source.subList(chunkOffsets.getBegin(), chunkOffsets.getEnd())); return true; }
/** * Returns list of merged tokens and original tokens. * * @param annotation */ public List<CoreMap> extractCoreMapsMergedWithTokens(CoreMap annotation) { List<CoreMap> res = extractCoreMaps(annotation); Integer startTokenOffset = annotation.get(CoreAnnotations.TokenBeginAnnotation.class); if (startTokenOffset == null) { startTokenOffset = 0; } final Integer startTokenOffsetFinal = startTokenOffset; List<CoreMap> merged = CollectionUtils.mergeListWithSortedMatchedPreAggregated( annotation.get(tokensAnnotationKey), res, (CoreMap in) -> Interval.toInterval(in.get(CoreAnnotations.TokenBeginAnnotation.class) - startTokenOffsetFinal, in.get(CoreAnnotations.TokenEndAnnotation.class) - startTokenOffsetFinal) ); return merged; }
in -> Interval.toInterval( in.get(CoreAnnotations.TokenBeginAnnotation.class) - startTokenOffsetFinal, in.get(CoreAnnotations.TokenEndAnnotation.class) - startTokenOffsetFinal)
public static List<CoreMap> findAndAnnotateNumericExpressionsWithRanges(CoreMap annotation) { Integer startTokenOffset = annotation.get(CoreAnnotations.TokenBeginAnnotation.class); if (startTokenOffset == null) { startTokenOffset = 0; } List<CoreMap> mergedNumbers = NumberNormalizer.findAndMergeNumbers(annotation); annotation.set(CoreAnnotations.NumerizedTokensAnnotation.class, mergedNumbers); // Find and label number ranges List<CoreMap> numberRanges = NumberNormalizer.findNumberRanges(annotation); final Integer startTokenOffsetFinal = startTokenOffset; List<CoreMap> mergedNumbersWithRanges = CollectionUtils.mergeListWithSortedMatchedPreAggregated( annotation.get(CoreAnnotations.NumerizedTokensAnnotation.class), numberRanges, (CoreMap in) -> Interval.toInterval( in.get(CoreAnnotations.TokenBeginAnnotation.class) - startTokenOffsetFinal, in.get(CoreAnnotations.TokenEndAnnotation.class) - startTokenOffsetFinal) ); annotation.set(CoreAnnotations.NumerizedTokensAnnotation.class, mergedNumbersWithRanges); return mergedNumbersWithRanges; }
charOffsets = Interval.toInterval(annotation.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class), annotation.get(CoreAnnotations.CharacterOffsetEndAnnotation.class)); tokenOffsets = Interval.toInterval(annotation.get(CoreAnnotations.TokenBeginAnnotation.class), annotation.get(CoreAnnotations.TokenEndAnnotation.class), Interval.INTERVAL_OPEN_END); } else { tokenOffsets = Interval.toInterval(annotation.get(CoreAnnotations.TokenBeginAnnotation.class), annotation.get(CoreAnnotations.TokenEndAnnotation.class), Interval.INTERVAL_OPEN_END); annotation.set(tokensAnnotationKey, annotation2.get(tokensAnnotationKey));