常见分词工具总结

由于中文不像英文那样具有天然的分隔符,所以一般情况下,中文自然语言处理的第一步就是要对语料进行分词处理,下面就总结以下我用过的一些常见的中文分词工具。


1.Stanford NLP

使用斯坦福大学的分词器,下载地址http://nlp.stanford.edu/software/segmenter.shtml

在工程里配置好之后,需要加载Properties文件,Properties文件是一些参数设置。

接下来让我们看一个示例:

package com.sectong.application;

    import java.util.List;

    import edu.stanford.nlp.ling.CoreAnnotations;
    import edu.stanford.nlp.ling.CoreAnnotations.NamedEntityTagAnnotation;
    import edu.stanford.nlp.ling.CoreAnnotations.PartOfSpeechAnnotation;
    import edu.stanford.nlp.ling.CoreAnnotations.TextAnnotation;
    import edu.stanford.nlp.ling.CoreLabel;
    import edu.stanford.nlp.pipeline.Annotation;
    import edu.stanford.nlp.pipeline.StanfordCoreNLP;
    import edu.stanford.nlp.util.CoreMap;

    public class CoreNLPSegment {

        public static void main(String[] args) {

            // 载入自定义的Properties文件
            StanfordCoreNLP pipeline = new StanfordCoreNLP("CoreNLP-chinese.properties");

            // 用一些文本来初始化一个注释。文本是构造函数的参数。
            Annotation annotation;
            annotation = new Annotation("我爱北京天安门,天安门上太阳升。");

            // 运行所有选定的代码在本文
            pipeline.annotate(annotation);

            // 从注释中获取CoreMap List,并取第0个值
            List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
            CoreMap sentence = sentences.get(0);

            // 从CoreMap中取出CoreLabel List,逐一打印出来
            List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
            System.out.println("字/词" + "\
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值