CoveredTextExtractor implements NamedFeatureExtractor1<T> { @Override public List<Feature> extract(JCas jCas, Annotation focusAnnotation) { String jCasText = jCas.getDocumentText(); int begin = focusAnnotation.getBegin(); int end = focusAnnotation.getEnd(); String spannedText = jCasText == null ? null : jCasText.substring(begin, end); Feature feature = new Feature(spannedText); return Collections.singletonList(feature); }  @Override String getFeatureName(); @Override List<Feature> extract(JCas jCas, Annotation focusAnnotation);  }
@Test public void testSameJCas() { this.jCas.setDocumentText("abcdefg"); Token token = new Token(this.jCas, 1, 3); CoveredTextExtractor<Token> extractor = new CoveredTextExtractor<Token>(); Assert.assertEquals(Arrays.asList(new Feature("bc")), extractor.extract(this.jCas, token)); }
@Test public void testDifferentJCas() throws Exception { this.jCas.setDocumentText("abcdefg"); JCas fooJCas = this.jCas.createView("foo"); fooJCas.setDocumentText("zyxwvut"); Token token = new Token(this.jCas, 1, 3); CoveredTextExtractor<Token> extractor = new CoveredTextExtractor<Token>(); Assert.assertEquals(Arrays.asList(new Feature("yx")), extractor.extract(fooJCas, token)); }