JiebaSegmenter extends SegmenterBase { @Override protected void process(JCas aJCas, String text, int zoneBegin) throws AnalysisEngineProcessException { int sentenceBegin = 0; int sentenceEnd = text.indexOf("。"); while (sentenceEnd > sentenceBegin) { String stext = text.substring(sentenceBegin, sentenceEnd + 1); processSentence(aJCas, stext, zoneBegin + sentenceBegin); sentenceBegin = sentenceEnd + 1; sentenceEnd = text.indexOf("。", sentenceBegin); } if (sentenceBegin < text.length()) { String stext = text.substring(sentenceBegin, text.length()); processSentence(aJCas, stext, zoneBegin + sentenceBegin); } }  @Override void initialize(UimaContext aContext);  }
@Test public void testChinese() throws Exception { JCas jcas = JCasFactory.createText("这是一个伸手不见五指的黑夜。我叫孙悟空，我爱北京，我爱Python" + "和C++。我不喜欢日本和服。", "zh"); AnalysisEngine aed = createEngine(JiebaSegmenter.class); aed.process(jcas); String[] tokens = { "这是", "一个", "伸手不见五指", "的", "黑夜", "。", "我", "叫", "孙悟空", "，", "我", "爱", "北京", "，", "我", "爱", "Python", "和", "C++", "。", "我", "不", "喜欢", "日本", "和服", "。" }; assertToken(tokens, select(jcas, Token.class)); String[] sentences = { "这是一个伸手不见五指的黑夜。", "我叫孙悟空，我爱北京，我爱Python和C++。", "我不喜欢日本和服。" }; assertSentence(sentences, select(jcas, Sentence.class)); }