【HanLP】--自然语言处理场景应用

一、前言

HanLP 是由一系列模型与算法组成的工具包,主要功能包括分词、词性标注、关键词提取、自动摘要、依存句法分析、命名实体识别、短语提取、拼音转换、简繁转换等等。
下面将介绍HanLP如何本地集成及一些常用功能在项目的应用!

二、Springboot集成HanLP

HanLP需要一些数据集和配置【参考HanLP的GitHub项目】。准备data、hanlp.properties,放到/resources目录下。
在这里插入图片描述
引用jar包

<dependency>
            <groupId>com.hankcs</groupId>
            <artifactId>hanlp</artifactId>
            <version>portable-1.7.5</version>
        </dependency>

----按照上面的配置好,就可以使用HanLP了。

三、HanLP分词

相关代码操作

  String[] wordStr = new String[]{
   "中华","华夏","中国","炎黄"};
        List<String> wordList = Arrays.asList(wordStr);
        wordList.forEach(item -> CustomDictionary.insert(item, "cus"));
        BinTrie<CoreDictionary.Attribute> trie =  CustomDictionary.getTrie();

 List<Term> termList1 = HanLP.segment("你好,欢迎使用HanLP汉语处理包!中华人.华夏无敌");
        System.out.println("1-->" + termList1);
        for (Term term : termList1) {
   
            String word = term.word;
            String nature = term.nature.toString();
            System.out.println("word-->" + word+"    nature--->"+nature);
        }

输出结果是:

1-->[你好/vl,/w, 欢迎/v, 使用/v, HanLP/nx, 汉语/gi, 处理/vn,/v,/w,/f, 华人/n, ./w, 华夏/cus, 无敌/vi]
word-->你好    nature
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DreamBoy_W.W.Y

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值