打开文本文件:

text_file = open('online review data.txt','r',encoding='utf-8')

读取数据:

text = text_file.read()

读取的数据类型:

print (type(text)) print(" ")

打印文本:

print(text) print(" ")

导入所需库:

import jieba

按句子对文本进行分词:

sentences = list(jieba.cut(text, cut_all=False)) print("精确模式: " + " / ".join(sentences))

打印分词结果:

#print(sentences) print(sentences)

import jieba.posseg as pseg tag_filter = ['n'] words_pair = pseg.cut(text) result = [] for word, flag in words_pair: if flag in tag_filter: result.append(word) print("词性过滤完成") print(result)

Python 中文词性筛选:使用 Jieba 库提取名词

原文地址: https://www.cveoy.top/t/topic/n2K1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录