mmseg4j 中文分词简单代码实例

import com.chenlb.mmseg4j.*;
import com.chenlb.mmseg4j.analysis.ComplexAnalyzer;

import java.io.StringReader;

/**
 * Created by me on 17-5-9.
 */
public class WordSeg {
    public static void main(String[] args){
        String txt = "Jim喜欢写代码";
        Dictionary dic = Dictionary.getInstance("");
        Seg seg = new ComplexSeg(dic);
        MMSeg mmSeg = new MMSeg(new StringReader(txt), seg);
        Word word = null;
        try {
            while ((word = mmSeg.next()) != null) {
                System.out.print(word + "|");
            }
        } catch (Exception e) {
            System.exit(0);
        }
    }
}
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页