Update danmu.py

main
pkf2ew7r5 11 months ago
parent 46bec89339
commit 3de1cd7a90

@ -97,6 +97,10 @@ def get_wordcloud(ai_danmu):
ai = ' '.join(ai_danmu)
# 使用jieba分词对连接后的字符串进行分词并将分词结果再次连接成一个长字符串分词之间用空格分隔
cut_t = ' '.join(jieba.cut(ai))
# 设置停用词,减少无效信息
stop_words = set()
content = [line.strip() for line in open('停用词.txt', 'r', encoding='utf-8').readlines()]
stop_words.update(content)
# 创建一个WordCloud对象设置词云图的参数
wordcloud = WordCloud(background_color="white", # 设置背景颜色为白色
width=800, # 设置词云图的宽度
@ -106,12 +110,12 @@ def get_wordcloud(ai_danmu):
font_path='msyh.ttc', # 设置字体路径,确保能够显示中文
contour_width=2, # 设置词云图的轮廓宽度
contour_color='steelblue', # 设置词云图轮廓的颜色
repeat='true' # 设置单词课重复出现
repeat='true', # 设置单词课重复出现
stopwords = stop_words, # 设置停用词
).generate(cut_t)
# 将生成的词云图保存为PNG文件
wordcloud.to_file('词云图.png')
if __name__ == '__main__':
bvlist = get_bvlist()
cidlist = get_cidlist(bvlist)

Loading…
Cancel
Save