public static <T extends Annotation> List<T> getAnnotations(JCas jCas, int begin, int end, Class<T> cls) { Annotation annotation = new Annotation(jCas, begin, end); return getAnnotations(jCas, annotation, cls); }
static private Annotation createAnnotation( final JCas jCas, final String className ) { try { final Class<?> clazz = Class.forName( className ); if ( Annotation.class.isAssignableFrom( clazz ) ) { final Constructor<?> constructor = clazz.getConstructor( JCas.class ); return (Annotation) constructor.newInstance( jCas ); } else { LOGGER.error( "Cannot create a ctakes annotation for class " + className ); } } catch ( ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException multE ) { LOGGER.error( "Cannot determine ctakes annotation type for class " + className ); } return new Annotation( jCas ); }
private void tryToCreateAnnotation(TextMarkerStream stream, boolean ignoreCase, int size, ArrayList<AnnotationFS> results, List<TextMarkerBasic> basicsToAdd, String lastCandidate, Annotation interResult, char[] ignoreChars, int maxIgnoredChars, boolean ignoreWS) { if (basicsToAdd.size() >= 1 && contains(lastCandidate, ignoreCase, size, ignoreChars, maxIgnoredChars, ignoreWS)) { results.add(new Annotation(stream.getJCas(), basicsToAdd.get(0).getBegin(), basicsToAdd.get( basicsToAdd.size() - 1).getEnd())); } else if (interResult != null) { results.add(interResult); } }
private void tryToCreateAnnotation(RutaStream stream, boolean ignoreCase, int size, ArrayList<AnnotationFS> results, List<RutaBasic> basicsToAdd, String lastCandidate, Annotation interResult, char[] ignoreChars, int maxIgnoredChars, boolean ignoreWS) { if (basicsToAdd.size() >= 1 && contains(lastCandidate, ignoreCase, size, ignoreChars, maxIgnoredChars, ignoreWS)) { results.add(new Annotation(stream.getJCas(), basicsToAdd.get(0).getBegin(), basicsToAdd.get( basicsToAdd.size() - 1).getEnd())); } else if (interResult != null) { results.add(interResult); } }
@Override public Type getType() { return new Annotation(jCas).getType(); } }
@Override public Annotation convert(JCas view, TopTreebankNode topNode) { Annotation annotation = new Annotation(view); List<Annotation> subAnnotations = new ArrayList<Annotation>(); for (PropbankRelation rel : this.relations) { subAnnotations.add(rel.convert(view, topNode)); } // annotation.setAnnotations(UIMAUtil.toFSArray(view, subAnnotations)); int[] span = AnnotationUtil.getAnnotationsExtent(subAnnotations); annotation.setBegin(span[0]); annotation.setEnd(span[1]); annotation.addToIndexes(); return annotation; }
@Override public Annotation convert(JCas view, TopTreebankNode topNode) { Annotation annotation = new Annotation(view); List<Annotation> subAnnotations = new ArrayList<Annotation>(); for (PropbankRelation rel : this.relations) { subAnnotations.add(rel.convert(view, topNode)); } // annotation.setAnnotations(UIMAUtil.toFSArray(view, subAnnotations)); int[] span = AnnotationUtil.getAnnotationsExtent(subAnnotations); annotation.setBegin(span[0]); annotation.setEnd(span[1]); annotation.addToIndexes(); return annotation; }
private Annotation getAnnotationObject(JCas aJCas, String viewName, String type, Integer[] index) throws Exception{ if (type.matches(txpAnn.token)) return new Token(aJCas.getView(viewName)); if (type.matches(txpAnn.lemma)) return new Lemma(aJCas.getView(viewName)); if (type.matches(txpAnn.pos)) return getAnnotationObject(aJCas, viewName, txpAnn.getAnnotation(type).get(index), POS.class); if (type.matches(txpAnn.sentence)) return new Sentence(aJCas.getView(viewName)); if (type.matches(txpAnn.ne)) return getAnnotationObject(aJCas, viewName, txpAnn.getNEtype(index), NamedEntity.class); return new Annotation(aJCas.getView(viewName)); }
/** * For correct behavior, requires types to be listed in TypePriorities so that the subiterator works as expected */ public static FSIterator getAnnotationsIteratorInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); FSIterator<?> itr = annIdx.subiterator(ann); ann.removeFromIndexes(); return itr; }
/** * returns the number of annotations of specified type in the */ public static int countAnnotationsInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); ann.removeFromIndexes(); return annIdx.size(); }
public List<Feature> extractBetween(JCas view, FOCUS_T annotation1, FOCUS_T annotation2) throws CleartkExtractorException { int begin = annotation1.getEnd(); int end = annotation2.getBegin(); // FIXME: creating a new annotation may leak memory - is there a better approach? Annotation focusAnnotation = new Annotation(view, begin, end); return this.extract(view, focusAnnotation, new NoBounds()); }
/** * For correct behavior, requires types to be listed in TypePriorities so that the subiterator works as expected */ public static FSIterator getAnnotationsIteratorInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); FSIterator<?> itr = annIdx.subiterator(ann); ann.removeFromIndexes(); return itr; }
/** * returns the number of annotations of specified type in the */ public static int countAnnotationsInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); ann.removeFromIndexes(); return annIdx.size(); }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { // Do nothing Pattern p = Pattern.compile("\\d+"); Matcher m = p.matcher(aJCas.getDocumentText()); while (m.find()) { Annotation a = new Annotation(aJCas); a.setBegin(m.start()); a.setEnd(m.end()); a.addToIndexes(); } } }
@Before public void setUp() throws UIMAException { jCas = JCasSingleton.getJCasInstance(); annotation = new Annotation(jCas); context = UimaContextFactory.createUimaContext(PipelineBuilder.PIPELINE_NAME, PIPELINE_NAME); }
@Before public void setUp() throws UIMAException { jCas = JCasSingleton.getJCasInstance(); annotation = new Annotation(jCas); context = UimaContextFactory.createUimaContext(PipelineBuilder.PIPELINE_NAME, PIPELINE_NAME); }
@Before public void setUp() throws UIMAException { jCas = JCasSingleton.getJCasInstance(); annotation = new Annotation(jCas); specifier = new CustomResourceSpecifier_impl(); }
@Test public void testGetSingleCoveredMissing() { final Annotation a = new Annotation(jCas); a.setBegin(1); a.setEnd(12); final Optional<Annotation> missing = AnnotationUtils.getSingleCovered(Annotation.class, a); Assert.assertFalse(missing.isPresent()); }
@Test public void testGetSingleCovered() { final Annotation a = new Annotation(jCas); a.setBegin(0); a.setEnd(4); final Optional<Annotation> single = AnnotationUtils.getSingleCovered(Annotation.class, a); Assert.assertEquals("012", single.get().getCoveredText()); }
@Test public void testRecordable() throws UIMAException { JCas jCas = JCasFactory.createJCas(); FakeRecordable fakeRecordable = new FakeRecordable(jCas); assertEquals(new Annotation(jCas).getType().getName(), fakeRecordable.getTypeName()); }