@Override public void moveTo(FeatureStructure fs) { try { currentIt.moveTo(fs); } catch (Exception e) { // e.printStackTrace(); } }
/** * 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; }
@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 static boolean areAdjoining(Token t1, Token t2) { JCas jCas = getJCas(t1); FSIterator<Annotation> tokenIter = jCas.getAnnotationIndex(Token.typeIndexID).iterator(); tokenIter.moveTo(t1); assert (t1.equals(tokenIter.get())); tokenIter.moveToNext(); return tokenIter.isValid() && tokenIter.get().equals(t2); }
/** * 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; }
public void moveTo(FeatureStructure fs) { try { currentIt.moveTo(fs); } catch (Exception e) { e.printStackTrace(); } }
completeIt.moveToLast(); } else { completeIt.moveTo(windowAnnotation);
protected List<Annotation> getRightScopeContextAnnotations(JCas jCas, Annotation focus, Annotation window) throws AnalysisEngineProcessException { List<Annotation> scopeContextAnnotations = new ArrayList<Annotation>(); // if focus is not completely contained inside the window annotation, // then return empty list. if (focus.getBegin() < window.getBegin() || focus.getEnd() > window.getEnd()) return scopeContextAnnotations; FSIterator subiterator = jCas.getAnnotationIndex(contextType).subiterator(window); subiterator.moveTo(focus); subiterator.moveToPrevious(); if (!subiterator.isValid()) subiterator.moveTo(focus); while (scopeContextAnnotations.size() < rightScopeSize) { subiterator.moveToNext(); if (subiterator.isValid()) { Annotation contextAnnotation = (Annotation) subiterator.get(); if (contextAnnotation.getBegin() < focus.getEnd()) { continue; } if (!contextAnalyzer.isBoundary(contextAnnotation, RIGHT_SCOPE)) { scopeContextAnnotations.add(contextAnnotation); } else { break; } } else { break; } } return scopeContextAnnotations; }
/** * @see org.apache.uima.cas.FSIterator#moveTo(FeatureStructure) */ public void moveTo(FeatureStructure fs) { this.nonFlatIterator.moveTo(fs); this.flatIterator.moveTo(fs); }
/** * @see org.apache.uima.cas.FSIterator#moveTo(FeatureStructure) */ public void moveTo(FeatureStructure fs) { this.it.moveTo(fs); adjustForConstraintForward(); }
protected List<Annotation> getRightScopeContextAnnotations(JCas jCas, Annotation focus, Annotation window) throws AnalysisEngineProcessException { List<Annotation> scopeContextAnnotations = new ArrayList<Annotation>(); // if focus is not completely contained inside the window annotation, // then return empty list. if (focus.getBegin() < window.getBegin() || focus.getEnd() > window.getEnd()) return scopeContextAnnotations; FSIterator subiterator = jCas.getAnnotationIndex(contextType).subiterator(window); subiterator.moveTo(focus); subiterator.moveToPrevious(); if (!subiterator.isValid()) subiterator.moveTo(focus); while (scopeContextAnnotations.size() < rightScopeSize) { subiterator.moveToNext(); if (subiterator.isValid()) { Annotation contextAnnotation = (Annotation) subiterator.get(); if (contextAnnotation.getBegin() < focus.getEnd()) { continue; } if (!contextAnalyzer.isBoundary(contextAnnotation, RIGHT_SCOPE)) { scopeContextAnnotations.add(contextAnnotation); } else { break; } } else { break; } } return scopeContextAnnotations; }
public RutaBasic getFirstBasicInWindow(AnnotationFS windowAnnotation, FSIterator<AnnotationFS> it) { if (windowAnnotation instanceof RutaBasic) { return (RutaBasic) windowAnnotation; } it.moveTo(windowAnnotation); if (it.isValid()) { return (RutaBasic) it.get(); } return null; }
@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); }
public TextMarkerBasic getFirstBasicInWindow(AnnotationFS windowAnnotation, FSIterator<AnnotationFS> it) { if (windowAnnotation instanceof TextMarkerBasic) { return (TextMarkerBasic) windowAnnotation; } it.moveTo(windowAnnotation); if (it.isValid()) { return (TextMarkerBasic) it.get(); } return null; }
pointer = stream.getBeginAnchor(annotation.getBegin()); it.moveTo(pointer); int count = 0; while (count <= maxValue) {
public RutaBasic getNextBasic2(AnnotationFS previous) { AnnotationFS pointer = cas.createAnnotation(basicType, previous.getEnd() - 1, previous.getEnd()); currentIt.moveTo(pointer); if (currentIt.isValid()) { RutaBasic basic = (RutaBasic) currentIt.get(); return basic; } return null; }
public TextMarkerBasic getNextBasic2(AnnotationFS previous) { AnnotationFS pointer = cas .createAnnotation(basicType, previous.getEnd() - 1, previous.getEnd()); currentIt.moveTo(pointer); if (currentIt.isValid()) { TextMarkerBasic basic = (TextMarkerBasic) currentIt.get(); return basic; } return null; }
|| expression.getAnnotationListExpression() != null) { iterator = new AnnotationListFSIterator(expression.getAnnotationList(context, stream)); iterator.moveTo(annotation); } else { Type type = matcher.getType(parent, stream);