java 去停用词_利用jieba分词并去除停用词

该博客介绍了如何在Java文本处理中利用Python的jieba库进行中文分词,并通过创建停用词列表移除停用词。通过示例展示了读取停用词文件、分词、去除数字以及最终去除停用词的过程。
摘要由CSDN通过智能技术生成

import jieba

import re

# 停用词

# 创建停用词列表

def get_stopwords_list():

stopwords = [line.strip() for line in open('stopwords.txt',encoding='UTF-8').readlines()]

return stopwords

# 对句子进行中文分词

def seg_depart(sentence):

# 对文档中的每一行进行中文分词

sentence_depart = jieba.lcut(sentence.strip())

return sentence_depart

def remove_digits(input_str):

punc = u'0123456789.'

output_str = re.sub(r'[{}]+'.format(punc), '', input_str)

return output_str

# 去除停用词

def move_stopwords(sentence_list, stopwords_list):

# 去停用词

out_list = []

for word in sentence_list:

if word not in stopwords_list:

if not remove_digits(word):

continue

if word != '\t':

out_list.append(word)

return out_l

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值