/** * Return an annotation preceding or following of a given reference annotation. * * @param type * a type. * @param annotation * anchor annotation * @param index * relative position to access. A negative value selects a preceding annotation while a * positive number selects a following annotation. * @return the addressed annotation. * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a> */ public static AnnotationFS selectSingleRelative(Type type, AnnotationFS annotation, int index) { return selectSingleRelative(annotation.getView(), type, annotation, index); }
public static Token getTokenRelative(Token refToken, int index) { CAS cas = refToken.getCAS(); Type tokenType = cas.getTypeSystem().getType(Token.class.getName()); try { return (Token) CasUtil.selectSingleRelative(cas, tokenType, refToken, index); } catch (IndexOutOfBoundsException e) { return null; } }
/** * Return an annotation preceding or following of a given reference annotation. * * @param <T> * the JCas type. * @param aType * a type. * @param annotation * anchor annotation * @param index * relative position to access. A negative value selects a preceding annotation while a * positive number selects a following annotation. * @return the addressed annotation. * @throws IndexOutOfBoundsException * if the relative index points beyond the type index bounds. * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a> */ @SuppressWarnings("unchecked") public static <T extends Annotation> T selectSingleRelative(Class<T> aType, AnnotationFS annotation, int index) { CAS cas = annotation.getCAS(); Type t = CasUtil.getType(cas, aType); return (T) CasUtil.selectSingleRelative(cas, t, annotation, index); }
/** * Return an annotation preceding or following of a given reference annotation. If the type * parameter corresponds to the type or a subtype of the anchor annotation and the relative * position is 0, then the anchor annotation is returned. * * @param <T> * the JCas type. * @param aJCas * a JCas. * @param aType * type of the annotation to be returned. * @param aAnchor * anchor annotation * @param aPosition * relative position to access. A negative value selects a preceding annotation while a * positive number selects a following annotation. * @return the addressed annotation. * @throws IndexOutOfBoundsException * if the relative position points beyond the type index bounds. * @throws IllegalArgumentException * if the relative position is {@code 0} and the anchor type does not subsume the * selected type. * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a> */ @SuppressWarnings("unchecked") public static <T extends Annotation> T selectSingleRelative(JCas aJCas, Class<T> aType, AnnotationFS aAnchor, int aPosition) { Type t = getType(aJCas, aType); return (T) CasUtil.selectSingleRelative(aJCas.getCas(), t, aAnchor, aPosition); }