@Test public void testTokenOffsetsNoType() throws Exception { final JCas jCas = JCasFactory.createJCas("de.julielab.jcore.types.jcore-morpho-syntax-types", "de.julielab.jcore.types.jcore-semantics-biology-types", "de.julielab.jcore.types.jcore-document-meta-types"); final ExternalResourceDescription externalResourceDescription = ExternalResourceFactory.createExternalResourceDescription(InMemoryFileTextAnnotationProvider.class, new File("src/test/resources/geneannotations_token_offsets_notype.tsv")); final AnalysisEngine engine = AnalysisEngineFactory.createEngine(AnnotationAdderAnnotator.class, AnnotationAdderAnnotator.PARAM_OFFSET_MODE, AnnotationAdderAnnotator.OffsetMode.TOKEN, AnnotationAdderAnnotator.PARAM_DEFAULT_UIMA_TYPE, "de.julielab.jcore.types.Gene", AnnotationAdderAnnotator.KEY_ANNOTATION_SOURCE, externalResourceDescription); jCas.setDocumentText("BRCA PRKII are the genes of this sentence."); new Token(jCas, 0, 4).addToIndexes(); new Token(jCas, 5, 10).addToIndexes(); final Header h = new Header(jCas); h.setDocId("doc1"); h.addToIndexes(); engine.process(jCas); final List<Gene> genes = new ArrayList<>(JCasUtil.select(jCas, Gene.class)); assertThat(genes).hasSize(2); assertThat(genes.get(0).getBegin()).isEqualTo(0); assertThat(genes.get(0).getEnd()).isEqualTo(4); assertThat(genes.get(1).getBegin()).isEqualTo(5); assertThat(genes.get(1).getEnd()).isEqualTo(10); jCas.reset(); jCas.setDocumentText("There are no gene mentions in here"); Header h2 = new Header(jCas); h2.setDocId("doc2"); h2.addToIndexes(); engine.process(jCas); assertThat(JCasUtil.exists(jCas, Gene.class)).isFalse(); jCas.reset(); jCas.setDocumentText("PRKAVI does not exist, I think. But this is just a test so it doesn't matter."); new Token(jCas, 0, 6).addToIndexes(); Header h3 = new Header(jCas); h3.setDocId("doc3"); h3.addToIndexes(); engine.process(jCas); final Gene gene = JCasUtil.selectSingle(jCas, Gene.class); assertThat(gene.getBegin()).isEqualTo(0); assertThat(gene.getEnd()).isEqualTo(6); jCas.reset(); jCas.setDocumentText("PRKAVI BRCA IL-2 come to mind."); new Token(jCas, 0, 6).addToIndexes(); new Token(jCas, 7, 11).addToIndexes(); new Token(jCas, 12, 16).addToIndexes(); Header h4 = new Header(jCas); h4.setDocId("doc4"); h4.addToIndexes(); engine.process(jCas); final Gene gene2 = JCasUtil.selectSingle(jCas, Gene.class); assertThat(gene2.getBegin()).isEqualTo(0); assertThat(gene2.getEnd()).isEqualTo(16); }
@Override public void process(final JCas aJCas) { final String docId = JCoReTools.getDocId(aJCas); if (docId == null) log.error("The current document does not have a header. Cannot add external annotations."); final AnnotationData annotations = annotationProvider.getAnnotations(docId); final AnnotationAdderHelper helper = new AnnotationAdderHelper(); if (annotations != null) { boolean success = false; int adderNum = 0; while (adderNum < annotationAdders.size() && !(success = annotationAdders.get(adderNum).addAnnotations(annotations, helper, adderConfiguration, aJCas, preventProcessedOnDigestMismatch))) { ++adderNum; } if (!success) throw new IllegalArgumentException("There was no annotation adder to handle the annotation data of class " + annotations.getClass().getCanonicalName()); } else { log.debug("No external annotations were delivered for document ID {}", docId); } }
AnnotationAdderAnnotator extends JCasAnnotator_ImplBase { @Override public void process(final JCas aJCas) { final String docId = JCoReTools.getDocId(aJCas); if (docId == null) log.error("The current document does not have a header. Cannot add external annotations."); final AnnotationData annotations = annotationProvider.getAnnotations(docId); final AnnotationAdderHelper helper = new AnnotationAdderHelper(); if (annotations != null) { boolean success = false; int adderNum = 0; while (adderNum < annotationAdders.size() && !(success = annotationAdders.get(adderNum).addAnnotations(annotations, helper, adderConfiguration, aJCas, preventProcessedOnDigestMismatch))) { ++adderNum; } if (!success) throw new IllegalArgumentException("There was no annotation adder to handle the annotation data of class " + annotations.getClass().getCanonicalName()); } else { log.debug("No external annotations were delivered for document ID {}", docId); } } }
AnnotationAdderAnnotator extends JCasAnnotator_ImplBase { @Override public void process(final JCas aJCas) { final String docId = JCoReTools.getDocId(aJCas); if (docId == null) log.error("The current document does not have a header. Cannot add external annotations."); final AnnotationData annotations = annotationProvider.getAnnotations(docId); final AnnotationAdderHelper helper = new AnnotationAdderHelper(); if (annotations != null) { boolean success = false; int adderNum = 0; while (adderNum < annotationAdders.size() && !(success = annotationAdders.get(adderNum).addAnnotations(annotations, helper, adderConfiguration, aJCas, preventProcessedOnDigestMismatch))) { ++adderNum; } if (!success) throw new IllegalArgumentException("There was no annotation adder to handle the annotation data of class " + annotations.getClass().getCanonicalName()); } else { log.debug("No external annotations were delivered for document ID {}", docId); } }  }
AnnotationAdderAnnotator extends JCasAnnotator_ImplBase { @Override public void process(final JCas aJCas) { final String docId = JCoReTools.getDocId(aJCas); if (docId == null) log.error("The current document does not have a header. Cannot add external annotations."); final AnnotationData annotations = annotationProvider.getAnnotations(docId); final AnnotationAdderHelper helper = new AnnotationAdderHelper(); if (annotations != null) { boolean success = false; int adderNum = 0; while (adderNum < annotationAdders.size() && !(success = annotationAdders.get(adderNum).addAnnotations(annotations, helper, adderConfiguration, aJCas, preventProcessedOnDigestMismatch))) { ++adderNum; } if (!success) throw new IllegalArgumentException("There was no annotation adder to handle the annotation data of class " + annotations.getClass().getCanonicalName()); } else { log.debug("No external annotations were delivered for document ID {}", docId); } }  @Override void initialize(final UimaContext aContext); @Override void process(final JCas aJCas); }
AnnotationAdderAnnotator extends JCasAnnotator_ImplBase { @Override public void process(final JCas aJCas) { final String docId = JCoReTools.getDocId(aJCas); if (docId == null) log.error("The current document does not have a header. Cannot add external annotations."); final AnnotationData annotations = annotationProvider.getAnnotations(docId); final AnnotationAdderHelper helper = new AnnotationAdderHelper(); if (annotations != null) { boolean success = false; int adderNum = 0; while (adderNum < annotationAdders.size() && !(success = annotationAdders.get(adderNum).addAnnotations(annotations, helper, adderConfiguration, aJCas, preventProcessedOnDigestMismatch))) { ++adderNum; } if (!success) throw new IllegalArgumentException("There was no annotation adder to handle the annotation data of class " + annotations.getClass().getCanonicalName()); } else { log.debug("No external annotations were delivered for document ID {}", docId); } }  @Override void initialize(final UimaContext aContext); @Override void process(final JCas aJCas); static final String KEY_ANNOTATION_SOURCE; static final String PARAM_OFFSET_MODE; static final String PARAM_DEFAULT_UIMA_TYPE; static final String PARAM_PREVENT_PROCESSED_MARK; }