WSDItemAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.FINE, "Entering " + this.getClass().getSimpleName()); List<Candidate> candidates = new ArrayList<Candidate>(); try { for (Entry<AnnotationFS, String> entry: FeaturePathFactory.select(jcas.getCas(), featurePath)) { candidates.add(new Candidate(entry.getValue(), entry.getKey().getBegin(), entry.getKey().getEnd())); } } catch (FeaturePathException e) { throw new AnalysisEngineProcessException(e); } List<Candidate> resolvedCandidates; if (resolveOverlaps) { resolvedCandidates = resolveOverlappingCandidates(candidates); } else { resolvedCandidates = candidates; } AnnotationIndex<Annotation> candidateIndex = jcas.getAnnotationIndex(WSDItem.type); for (Candidate candidate : resolvedCandidates) { WSDItem item = new WSDItem(jcas); item.setBegin(candidate.begin); item.setEnd(candidate.end); item.setSubjectOfDisambiguation(candidate.term); if (!candidateIndex.contains(item) || allowDuplicates) { item.addToIndexes(jcas); } } }  @Override void process(JCas jcas); static final String PARAM_FEATURE_PATH; static final String PARAM_RESOLVE_OVERLAPS; static final String PARAM_ALLOW_DUPLICATES; }
@Test public void testProcessJCasTokens() throws AnalysisEngineProcessException, ResourceInitializationException { AnalysisEngine engine = AnalysisEngineFactory.createEngine( WSDItemAnnotator.class, WSDItemAnnotator.PARAM_FEATURE_PATH, Token.class.getName()); JCas aJCas = engine.newJCas(); aJCas.setDocumentText(text); Token token = new Token(aJCas,0,2); token.addToIndexes(); engine.process(aJCas); WSDItem wsdItem = JCasUtil.selectSingle(aJCas, WSDItem.class); assertNotNull(wsdItem); assertEquals(0, wsdItem.getBegin()); assertEquals(2, wsdItem.getEnd()); }