ReadabilityAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { if (jcas.getDocumentLanguage() != null) { readability.setLanguage(jcas.getDocumentLanguage()); } int nrofSentences = 0; List<String> words = new ArrayList<String>(); for (Sentence sentence : JCasUtil.select(jcas, Sentence.class)) { nrofSentences++; List<Token> tokens = JCasUtil.selectCovered(Token.class, sentence); for (Token token : tokens) { words.add(token.getCoveredText()); } } for (Measures measure : Measures.values()) { ReadabilityScore score = new ReadabilityScore(jcas); score.setMeasureName(measure.name()); score.setScore(this.readability.getReadabilityScore(measure, words, nrofSentences)); score.addToIndexes(); } }  @Override void initialize(UimaContext context); @Override void process(JCas jcas);  }
@Test public void readabilityAnnotatorTest() throws Exception { String text = FileUtils.readFileToString( new File("src/test/resources/readability/test_document_en.txt") ); Map<String, Boolean> measureMap = new HashMap<String, Boolean>(); for (Measures measure : Measures.values()) { measureMap.put(measure.name(), true); } AnalysisEngineDescription aggregate = createEngineDescription( createEngineDescription(BreakIteratorSegmenter.class), createEngineDescription(ReadabilityAnnotator.class)); AnalysisEngine ae = createEngine(aggregate); JCas jcas = ae.newJCas(); jcas.setDocumentLanguage("en"); jcas.setDocumentText(text); ae.process(jcas); int i = 0; for (ReadabilityScore score : JCasUtil.select(jcas, ReadabilityScore.class)) { String strMeasureName = score.getMeasureName(); double dScore = score.getScore(); System.out.println(strMeasureName + " : " + score.getScore()); assertTrue(measureMap.containsKey(strMeasureName)); assertEquals(correctResult.get(strMeasureName), dScore, EPSILON); i++; } assertEquals(7, i); }