/** * Provides a convenient way to create an annotation a single line. Note that this method does not * add a new annotation into the index, as it is done in * {@link org.apache.uima.fit.factory.AnnotationFactory#createAnnotation(org.apache.uima.jcas.JCas, int, int, Class)}. * * @param <T> the annotation type * @param jCas the JCas to create the annotation in * @param begin the begin offset * @param end the end offset * @param cls the annotation class as generated by JCasGen * @return the new annotation */ @SuppressWarnings("unchecked") public static <T extends Annotation> T create(JCas jCas, int begin, int end, Class<T> cls) { return (T) jCas.getCas().createAnnotation(JCasUtil.getAnnotationType(jCas, cls), begin, end); }
/** * Get an iterator position at the annotation with the specified address. * * @param aJcas * the CAS object * @param aType * the expected annotation type * @param aFS * the annotation to seek for * @return the iterator. */ @SuppressWarnings({ "unchecked", "rawtypes" }) private static <T extends Annotation> FSIterator<T> seekByFs(JCas aJcas, Class<T> aType, AnnotationFS aFS) { AnnotationIndex<T> idx = aJcas.getAnnotationIndex(JCasUtil .getAnnotationType(aJcas, aType)); return idx.iterator(aFS); } /**
/** * Get an iterator position at the annotation with the specified address. * * @param aJcas * the CAS object * @param aType * the expected annotation type * @param aFS * the annotation to seek for * @return the iterator. */ @SuppressWarnings({ "unchecked", "rawtypes" }) private static <T extends Annotation> FSIterator<T> seekByFs(JCas aJcas, Class<T> aType, AnnotationFS aFS) { AnnotationIndex<T> idx = aJcas.getAnnotationIndex(JCasUtil .getAnnotationType(aJcas, aType)); return idx.iterator(aFS); } /**
/** * Get an iterator position at the annotation with the specified address. * * @param aJcas * the CAS object * @param aType * the expected annotation type * @param aAddr * the annotationa address * @return the iterator. */ @SuppressWarnings({ "unchecked", "rawtypes" }) private static <T extends Annotation> FSIterator<T> seekByAddress(JCas aJcas, Class<T> aType, int aAddr) { AnnotationIndex<T> idx = aJcas.getAnnotationIndex(JCasUtil .getAnnotationType(aJcas, aType)); return idx.iterator(selectByAddr(aJcas, aAddr)); }
/** * Get an iterator position at the annotation with the specified address. * * @param aJcas * the CAS object * @param aType * the expected annotation type * @param aAddr * the annotationa address * @return the iterator. */ @SuppressWarnings({ "unchecked", "rawtypes" }) private static <T extends Annotation> FSIterator<T> seekByAddress(JCas aJcas, Class<T> aType, int aAddr) { AnnotationIndex<T> idx = aJcas.getAnnotationIndex(JCasUtil .getAnnotationType(aJcas, aType)); return idx.iterator(selectByAddr(aJcas, aAddr)); }
/** * Provides a convenient way to create an annotation and addToIndexes in a single line. * * @param <T> * the annotation type * @param jCas * the JCas to create the annotation in * @param begin * the begin offset * @param end * the end offset * @param cls * the annotation class as generated by JCasGen * @return the new annotation */ public static <T extends Annotation> T createAnnotation(JCas jCas, int begin, int end, Class<T> cls) { @SuppressWarnings("unchecked") T annotation = (T) jCas.getCas().createAnnotation(JCasUtil.getAnnotationType(jCas, cls), begin, end); annotation.addToIndexes(); return annotation; } }