当前位置: 首页 > 工具软件 > sns4j > 使用案例 >

mmseg4j 中文分词简单代码实例

危飞跃
2023-12-01
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);
        }
    }
}
 类似资料: