SmartChineseAnalyzer analyzer = new SmartChineseAnalyzer();
stream.reset();
System.out.print("分词:");
while(stream.incrementToken()){
System.out.print("pia:"+pia.getPositionIncrement()+" ");
System.out.print( "cta :"+cta+"["+oa.startOffset()+"->"+oa.endOffset()+"]");
System.out.println();
}
stream.end();
stream.close();
TokenStream stream = analyzer.tokenStream("", new StringReader(str));
//分词
CharTermAttribute cta = stream.addAttribute(CharTermAttribute.class);
//偏移量
OffsetAttribute oa = stream.addAttribute(OffsetAttribute.class);
//词与词中间的位置增量,一般为1
PositionIncrementAttribute pia = stream.addAttribute(PositionIncrementAttribute.class);stream.reset();
System.out.print("分词:");
while(stream.incrementToken()){
System.out.print("pia:"+pia.getPositionIncrement()+" ");
System.out.print( "cta :"+cta+"["+oa.startOffset()+"->"+oa.endOffset()+"]");
System.out.println();
}
stream.end();
stream.close();