数据集
数据集是THUCnews的,清华大学根据新浪新闻RSS订阅频道2005-2011年间的历史数据筛选过滤生成,我对其进行了整理,只剩下一个txt文件——dataSet.txt。
链接: 数据集下载地址
提取码: rvs9
对句子进行分词
其中的停用词stopwords.txt,完整代码可以在我的github上找到——完整代码
def seg_sentence(sentence, stopwords_path):
"""
对句子进行分词
"""
# print "now token sentence..."
def stopwordslist(filepath):
"""
创建停用词list ,闭包
"""
stopwords = [line.decode('utf-8').strip() for line in open(filepath, 'rb').readlines()]
return stopwords
sentence_seged = jieba.cut(sentence.strip())
stopwords = stopwordslist(stopwords_path) # 这里加载停用词的路径
outstr = '' # 返回值是字符串
for word in sentence_s