@Override public void moveToPrevious() { currentIt.moveToPrevious(); }
public void moveToPrevious() { currentIt.moveToPrevious(); }
public FSListIteratorImpl(FSIterator<T> it) { super(); this.forward = it; this.back = it.copy(); it.moveToPrevious(); }
/** * @see org.apache.uima.cas.FSIterator#moveToPrevious() */ public void moveToPrevious() { this.nonFlatIterator.moveToPrevious(); this.flatIterator.moveToPrevious(); }
public void moveToPrevious() { this.it.moveToPrevious(); adjustForConstraintBackward(); }
/** * Move the iterator so that the next call to {@link #next() next()} will return the first element * in the index (for a non-empty index). */ public void moveToStart() { // Move the forward pointer to the start. this.forward.moveToFirst(); // Move the back pointer past the start. this.back.moveToFirst(); this.back.moveToPrevious(); }
/** * @see ListIterator#previous() */ public T previous() throws NoSuchElementException { // See comments for next(). if (!this.back.isValid()) { throw new NoSuchElementException(); } this.back.moveToPrevious(); if (this.forward.isValid()) { this.forward.moveToPrevious(); } else { this.forward.moveToLast(); } return this.forward.get(); }
private void moveOn(boolean after, FSIterator<AnnotationFS> iterator, RutaStream stream) { if (after) { iterator.moveToNext(); } else { iterator.moveToPrevious(); } while (iterator.isValid() && !stream.isVisible(iterator.get())) { if (after) { iterator.moveToNext(); } else { iterator.moveToPrevious(); } } }
private void adjustForConstraintBackward() { // If the iterator is valid, but doesn't match the constraint, advance. while (this.it.isValid() && !this.cons.match(this.it.get())) { this.it.moveToPrevious(); } }
public void moveToPrevious() { // No point in going anywhere if iterator is not valid. if (!isValid()) { return; } // Grab current iterator and dec. FSIterator<T> current = this.iterators.get(this.iteratorIndex); current.moveToPrevious(); // If we're ok with the current iterator, return. if (current.isValid()) { return; } --this.iteratorIndex; while (this.iteratorIndex >= 0) { current = this.iterators.get(this.iteratorIndex); current.moveToLast(); if (current.isValid()) { return; } --this.iteratorIndex; } // If we get here, the iterator is no longer valid, there are no more elements. Set internal // counter to the invalid position. this.iteratorIndex = this.iterators.size(); }
/** * Return previous element if exists. Always save iterator position. * * @param iter * iterator * @return previous element if exists or null otherwise */ private static <T extends FeatureStructure> T lookupPrevious(FSIterator<T> iter) { iter.moveToPrevious(); T result; if (iter.isValid()) { result = iter.get(); iter.moveToNext(); } else { result = null; iter.moveToFirst(); } return result; }
/** * Return next element if exists. Always save iterator position. * * @param iter * iterator * @return next element if exists or null otherwise */ private static <T extends FeatureStructure> T lookupNext(FSIterator<T> iter) { iter.moveToNext(); T result; if (iter.isValid()) { result = iter.get(); iter.moveToPrevious(); } else { result = null; iter.moveToLast(); } return result; }
@SuppressWarnings("unchecked") public static <T extends Annotation> T get(JCas jCas, T annotation, int relativePosition, Annotation windowAnnotation) { FSIterator<?> cursor = jCas.getAnnotationIndex(annotation.getType()).iterator(); cursor.moveTo(annotation); if (relativePosition > 0) { for (int i = 0; i < relativePosition && cursor.isValid(); i++) cursor.moveToNext(); } else { for (int i = 0; i < -relativePosition && cursor.isValid(); i++) cursor.moveToPrevious(); } if (cursor.isValid()) { Annotation relativeAnnotation = (Annotation) cursor.get(); T returnValue = ((Class<T>) annotation.getClass()).cast(relativeAnnotation); if (windowAnnotation != null) { if (AnnotationUtil.contains(windowAnnotation, relativeAnnotation)) return returnValue; else return null; } else return returnValue; } else return null; }
public List<AnnotationFS> getOverappingAnnotations(AnnotationFS window, Type type) { List<AnnotationFS> result = new ArrayList<AnnotationFS>(); AnnotationFS newWindow = cas.createAnnotation(type, window.getBegin(), window.getEnd() - 1); FSIterator<AnnotationFS> iterator = cas.getAnnotationIndex(type).iterator(newWindow); if (!iterator.isValid()) { iterator.moveToLast(); } while (iterator.isValid()) { FeatureStructure fs = iterator.get(); if (fs instanceof AnnotationFS) { AnnotationFS a = (AnnotationFS) fs; if (a.getEnd() >= window.getEnd() && a.getBegin() <= window.getBegin()) { result.add(a); } } iterator.moveToPrevious(); } return result; }
public List<AnnotationFS> getOverappingAnnotations(AnnotationFS window, Type type) { List<AnnotationFS> result = new ArrayList<AnnotationFS>(); AnnotationFS newWindow = cas.createAnnotation(type, window.getBegin(), window.getEnd() - 1); FSIterator<AnnotationFS> iterator = cas.getAnnotationIndex(type).iterator(newWindow); if (!iterator.isValid()) { iterator.moveToLast(); } while (iterator.isValid()) { FeatureStructure fs = iterator.get(); if (fs instanceof AnnotationFS) { AnnotationFS a = (AnnotationFS) fs; if (a.getEnd() >= window.getEnd() && a.getBegin() <= window.getBegin()) { result.add(a); } } iterator.moveToPrevious(); } return result; }
private boolean check(AnnotationFS annotation, TextMarkerStream stream, Type t) { boolean result = false; FSIterator<AnnotationFS> it = stream.getCas().getAnnotationIndex(t).iterator(annotation); if (!it.isValid()) { it.moveToLast(); } while (it.isValid()) { AnnotationFS a = (AnnotationFS) it.get(); if (a.getBegin() <= annotation.getBegin()) { result = true; break; } it.moveToPrevious(); } return result; }
private boolean check(AnnotationFS annotation, RutaStream stream, Type t) { boolean result = false; FSIterator<AnnotationFS> it = stream.getCas().getAnnotationIndex(t).iterator(annotation); if (!it.isValid()) { it.moveToLast(); } while (it.isValid()) { AnnotationFS a = it.get(); if (a.getBegin() <= annotation.getBegin()) { result = true; break; } it.moveToPrevious(); } return result; }
/** * We initially used the AnnotationIndex.subiterator() but ran into issues * that we wanted to work around concerning the use of type priorities when * the window and windowed annotations have the same begin and end offsets. * By using our own iterator we can back up to the first annotation that has * the same begining as the window annotation and avoid having to set type * priorities. * * @param jCas * @param windowAnnotation * @return an FSIterator that is at the correct position */ private static FSIterator<?> initializeWindowCursor(final JCas jCas, final Annotation windowAnnotation) { final FSIterator<?> cursor = jCas.getAnnotationIndex().iterator(); cursor.moveTo(windowAnnotation); while (cursor.isValid() && (((Annotation) cursor.get()).getBegin() >= windowAnnotation .getBegin())) cursor.moveToPrevious(); if (cursor.isValid()) cursor.moveToNext(); else cursor.moveToFirst(); return cursor; }
/** * We initially used the AnnotationIndex.subiterator() but ran into issues that we wanted to work around concerning * the use of type priorities when the window and windowed annotations have the same begin and end offsets. By using * our own iterator we can back up to the first annotation that has the same begining as the window annotation and * avoid having to set type priorities. * * @param jCas * @param windowAnnotation * @return an FSIterator that is at the correct position */ private static FSIterator<?> initializeWindowCursor(JCas jCas, Annotation windowAnnotation) { FSIterator<?> cursor = jCas.getAnnotationIndex().iterator(); cursor.moveTo(windowAnnotation); while (cursor.isValid() && ((Annotation) cursor.get()).getBegin() >= windowAnnotation.getBegin()) { cursor.moveToPrevious(); } if (cursor.isValid()) { cursor.moveToNext(); } else { cursor.moveToFirst(); } return cursor; }
@Override public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, TextMarkerStream stream, InferenceCrowd crowd) { FSIterator<AnnotationFS> it = filtered.getBooleanValue(element.getParent()) ? stream : stream .getUnfilteredBasicIterator(); it.moveTo(annotation); int count = 0; while (count <= max.getIntegerValue(element.getParent())) { if (count >= min.getIntegerValue(element.getParent()) && it.isValid()) { FeatureStructure featureStructure = it.get(); if (featureStructure instanceof TextMarkerBasic) { TextMarkerBasic each = (TextMarkerBasic) featureStructure; if (each.isPartOf(type.getType(element.getParent()))) { return new EvaluatedCondition(this, true); } } } if (forward.getBooleanValue(element.getParent())) { it.moveToNext(); } else { it.moveToPrevious(); } count++; } return new EvaluatedCondition(this, false); }