public static Interval grow(final Collection<? extends Interval> ivals) { if (ivals.size() == 0) { return null; } final Interval first = ivals.iterator().next(); int start = first.getStart(); int end = first.getEnd(); for (final Interval s : ivals) { if (s.getStart() < start) { start = s.getStart(); } if (s.getEnd() > end) { end = s.getEnd(); } } return new ImmutableInterval(start, end); }
@Override public Interval overlap(final Interval i) { final boolean start_inside = (getStart() <= i.getStart()) && (i.getStart() < getEnd()); final boolean end_inside = (getStart() < i.getEnd()) && (i.getEnd() <= getEnd()); if (start_inside) { if (end_inside) { return new ImmutableInterval(i); } else if (getEnd() <= i.getEnd()) { return new ImmutableInterval(i.getStart(), getEnd()); } } else if (end_inside && (i.getStart() <= getStart())) { return new ImmutableInterval(getStart(), i.getEnd()); } else if ((i.getStart() <= getStart()) && (getEnd() <= i.getEnd())) { return new ImmutableInterval(this); } return null; }
private void updateOffsets(CAS sourceView, JCas targetView, AlignedString as, PositiveIntSet aCopiedFs) throws CASException, AnalysisEngineProcessException { // We only update annotations that were copied, nothing that was already there. IntListIterator it = aCopiedFs.iterator(); while (it.hasNext()) { FeatureStructure fs = targetView.getLowLevelCas().ll_getFSForRef(it.next()); if (fs instanceof Annotation) { // Now we update the offsets Annotation a = (Annotation) fs; // System.out.printf("Orig %s %3d %3d : %s%n", a.getType().getShortName(), // a.getBegin(), a.getEnd(), // sourceView.getDocumentText().substring(a.getBegin(), a.getEnd())); // System.out.printf("Before %s %3d %3d : %s%n", a.getType().getShortName(), // a.getBegin(), a.getEnd(), a.getCoveredText()); Interval resolved = as.resolve(new ImmutableInterval(a.getBegin(), a.getEnd())); a.setBegin(resolved.getStart()); a.setEnd(resolved.getEnd()); // System.out.printf("After %s %3d %3d : %s%n", a.getType().getShortName(), // a.getBegin(), a.getEnd(), a.getCoveredText()); } } } }
Interval i = alignedString.inverseResolve(new ImmutableInterval(annoFs .getBegin(), annoFs.getEnd())); fsCopy.setIntValue(beginFeature, i.getStart());
final Interval ulpos = resolve(new ImmutableInterval(seg.getStart(), seg.getEnd())); return new ImmutableInterval(start, end);
return new ImmutableInterval(start, end);