IkAnalyzer3.1.6 分词 (兼容lucene2.4 和2.9)

package com.ourdms.util;

import java.io.IOException;
import java.io.StringReader;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenStream;
import org.wltea.analyzer.lucene.IKAnalyzer;


public class SegDemo {

    public static void main(String[] args) throws IOException {
        String text = "中华人民共和国 ";
        Analyzer analyzer = new IKAnalyzer();
        StringReader reader = new StringReader(text);

        long startTime = System.currentTimeMillis(); // 开始时间
        TokenStream ts = analyzer.tokenStream("", reader);
        Token token = new Token();
        token = ts.next(token);
        while(token!=null){            
            System.out.println(token.term());
            token = ts.next(token);
        }
        //System.out.println(ts.next(token).term());

        long endTime = System.currentTimeMillis(); // 结束时间
        System.out.println("IK分词耗时" + new Float((endTime - startTime)) / 1000
                + "秒!");
    }
}

你可能感兴趣的:(IKAnalyzer)