修改以下的代码使其实现中文词性筛选功能#Open the text file text_file = openonline review datatxtrencoding=utf-8#Read the data text = text_fileread#Datatype of the data read print typetextprintn#Print the text printtextpr
#打开文本文件: text_file = open('online review data.txt','r',encoding='utf-8') #读取数据: text = text_file.read() #读取的数据类型: print (type(text)) print("\n")
#打印文本: print(text) print("\n")
#导入所需库: 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
原文地址: https://www.cveoy.top/t/topic/e9Qj 著作权归作者所有。请勿转载和采集!