lucene学习之分词信息

来源:互联网 发布:全网vip电影源码 编辑:程序博客网 时间:2024/06/03 22:58
SmartChineseAnalyzer analyzer = new SmartChineseAnalyzer();

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();
0 0
原创粉丝点击