HanLP中文分词

HanLP是由一系列模型与算法组成的工具包,目标是普及自然语言处理在生产环境中的应用。HanLP具备功能完善、性能高效、架构清晰、语料时新、可自定义的特点;提供词法分析(中文分词、词性标注、命名实体识别)、句法分析、文本分类和情感分析等功能。

官方文档:https://github.com/hankcs/HanLP
Java1.X官方文档:https://github.com/hankcs/HanLP/tree/1.x

快速入门HanLP:
https://www.cnblogs.com/world-0-1/articles/8087381.html

data-for-1.7.5.zip下载地址:
https://github.com/hankcs/HanLP/releases/tag/v1.7.5

hanlp用法中文智能分词自动识别文字提取:
https://blog.csdn.net/qq_37755661/article/details/80040847

简单使用HanLP教程:
https://blog.csdn.net/tianbwin2995/article/details/50938796?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

文本聚类
https://www.meiwen.com.cn/subject/yyiapqtx.html

项目结构

在这里插入图片描述该项目中,.jar和data文件夹和.properties需要下载。
下载链接:https://download.csdn.net/download/qq_36649744/12562214

项目配置

在这里插入图片描述
配置文件的作用是告诉HanLP数据包的位置,只需修改第一行:
root=usr/home/HanLP/为data的 父目录 即可,比如data目录是 /Users/hankcs/Documents/data ,那么 root=/Users/hankcs/Documents/ 。

测试代码

		File file = new File("D:/eclipse-workspace/HanLP/a.txt");// Test文件
		File file2 = new File("D:/eclipse-workspace/HanLP/aend.txt");
		
		BufferedReader br = new BufferedReader(new FileReader(file));
		String str = null;
		PrintWriter pw = new PrintWriter(file2);
		
		while((str = br.readLine()) != null) {
			ArrayList<String> aList = new ArrayList();
			StringBuilder sb = new StringBuilder();
			HanLP.Config.ShowTermNature = false; // 关闭词性显示
			List<Term> termList = HanLP.segment(str);
     		for(int i=0;i<termList.size();i++) {
				aList.add(termList.get(i).toString());
			}
			System.out.println(termList);
			for( int i =0;i<aList.size();i++) {
				sb.append(aList.get(i));
				sb.append(" ");
				sb.toString();
			}
			pw.print(sb);
  	     	pw.write("\r\n");
			pw.flush();	
		}
		pw.close();
		br.close();

本测试代码主要是读取TXT文件,通过HanLP进行分词处理之后再输出到TXT文件中。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值