AvgTokensPerSentenceMeasure extends JCasTextSimilarityMeasureBase { @Override public double getSimilarity(JCas jcas1, JCas jcas2, Annotation coveringAnnotation1, Annotation coveringAnnotation2) throws SimilarityException { List<Sentence> s1 = JCasUtil.selectCovered(jcas1, Sentence.class, coveringAnnotation1); List<Sentence> s2 = JCasUtil.selectCovered(jcas2, Sentence.class, coveringAnnotation2); int noOfTokens = 0; for (Sentence sentence : s1) { noOfTokens += JCasUtil.selectCovered(jcas1, Token.class, sentence).size(); } for (Sentence sentence : s2) { noOfTokens += JCasUtil.selectCovered(jcas1, Token.class, sentence).size(); } return (double) noOfTokens / (s1.size() + s2.size()); }  @Override double getSimilarity(JCas jcas1, JCas jcas2,
    		Annotation coveringAnnotation1, Annotation coveringAnnotation2);  }
@Test public void run() throws Exception { JCasTextSimilarityMeasure comparator = new AvgTokensPerSentenceMeasure(); AnalysisEngine ae = AnalysisEngineFactory.createEngine(BreakIteratorSegmenter.class); JCasBuilder cb = new JCasBuilder(ae.newJCas()); cb.add("One two three four"); cb.close(); JCas jcas = cb.getJCas(); ae.process(jcas); assertEquals(4, comparator.getSimilarity(jcas, jcas), epsilon); }