Search in sources :

Example 1 with HMMSegment

use of com.hankcs.hanlp.seg.HMM.HMMSegment in project HanLP by hankcs.

the class DemoHMMSegment method main.

public static void main(String[] args) {
    // 关闭词性显示
    HanLP.Config.ShowTermNature = false;
    Segment segment = new HMMSegment();
    String[] sentenceArray = new String[] { "HanLP是由一系列模型与算法组成的Java工具包,目标是普及自然语言处理在生产环境中的应用。", // 专业名词有一定辨识能力
    "高锰酸钾,强氧化剂,紫红色晶体,可溶于水,遇乙醇即被还原。常用作消毒剂、水净化剂、氧化剂、漂白剂、毒气吸收剂、二氧化碳精制剂等。", // 非新闻语料
    "《夜晚的骰子》通过描述浅草的舞女在暗夜中扔骰子的情景,寄托了作者对庶民生活区的情感", // 微博
    "这个像是真的[委屈]前面那个打扮太江户了,一点不上品...@hankcs", "鼎泰丰的小笼一点味道也没有...每样都淡淡的...淡淡的,哪有食堂2A的好次", "克里斯蒂娜·克罗尔说:不,我不是虎妈。我全家都热爱音乐,我也鼓励他们这么做。", "今日APPS:Sago Mini Toolbox培养孩子动手能力", "财政部副部长王保安调任国家统计局党组书记", "2.34米男子娶1.53米女粉丝 称夫妻生活没问题", "你看过穆赫兰道吗", "乐视超级手机能否承载贾布斯的生态梦" };
    for (String sentence : sentenceArray) {
        List<Term> termList = segment.seg(sentence);
        System.out.println(termList);
    }
    // 测个速度
    String text = "江西鄱阳湖干枯,中国最大淡水湖变成大草原";
    System.out.println(segment.seg(text));
    long start = System.currentTimeMillis();
    int pressure = 1000;
    for (int i = 0; i < pressure; ++i) {
        segment.seg(text);
    }
    double costTime = (System.currentTimeMillis() - start) / (double) 1000;
    System.out.printf("HMM2分词速度:%.2f字每秒\n", text.length() * pressure / costTime);
}
Also used : Term(com.hankcs.hanlp.seg.common.Term) Segment(com.hankcs.hanlp.seg.Segment) HMMSegment(com.hankcs.hanlp.seg.HMM.HMMSegment) HMMSegment(com.hankcs.hanlp.seg.HMM.HMMSegment)

Example 2 with HMMSegment

use of com.hankcs.hanlp.seg.HMM.HMMSegment in project HanLP by hankcs.

the class TestCharacterBasedGenerativeModel method testSegment.

public void testSegment() throws Exception {
    HanLP.Config.ShowTermNature = false;
    String text = "我实现了一个基于Character Based TriGram的分词器";
    Segment segment = new HMMSegment();
    List<Term> termList = segment.seg(text);
    System.out.println(termList);
}
Also used : Term(com.hankcs.hanlp.seg.common.Term) Segment(com.hankcs.hanlp.seg.Segment) HMMSegment(com.hankcs.hanlp.seg.HMM.HMMSegment) CharacterBasedGenerativeModelSegment(com.hankcs.hanlp.seg.CharacterBasedGenerativeModelSegment) HMMSegment(com.hankcs.hanlp.seg.HMM.HMMSegment)

Aggregations

HMMSegment (com.hankcs.hanlp.seg.HMM.HMMSegment)2 Segment (com.hankcs.hanlp.seg.Segment)2 Term (com.hankcs.hanlp.seg.common.Term)2 CharacterBasedGenerativeModelSegment (com.hankcs.hanlp.seg.CharacterBasedGenerativeModelSegment)1