验证中...
10月20日,北京【人工智能】源创会火热报名中,点击报名收获 AI 训练指南
Languages: Python
Categories: 其他
Latest update 2018-01-14 13:34
qq_group_wordcloud.py
Raw Copy
import re
import jieba
import matplotlib.pyplot as plt
from wordcloud import WordCloud
chat_log_file = ""
qq_number = ""
exclusion = ["表情", "图片"]
def exclude_word(wordlist):
for wl in wordlist:
jieba.del_word(wl)
with open(chat_log_file, "r", encoding="utf-8") as in_file:
content = "".join(in_file.readlines())
personal_record = "".join(re.findall(f"""(?<={qq_number}\)\n)(.*?)(?=\n\n)""", content))
exclude_word(exclusion)
wordlist_jieba = jieba.cut(personal_record, cut_all=True)
wl_space_split = " ".join(wordlist_jieba)
wc = WordCloud(font_path="simsun.ttc", width=600,
height=600, background_color="white",
scale=1.25, min_font_size=12)
my_wordcloud = wc.generate(wl_space_split)
plt.figure(figsize=(7, 7))
plt.imshow(my_wordcloud)
plt.axis("off")
plt.show()
# plt.savefig('test.png')

Comment list( 0 )

You need to Sign in for post a comment

Help Search