forked from LC044/WeChatMsg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
210 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
from .analysis import Analysis | ||
|
||
__all__=['Analysis'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from collections import Counter | ||
|
||
from app.DataBase import msg_db, MsgType | ||
from app.person_pc import ContactPC | ||
import jieba | ||
from pyecharts import options as opts | ||
from pyecharts.charts import Pie, WordCloud, Calendar, Bar, Line, Timeline, Grid | ||
|
||
charts_width = 800 | ||
charts_height = 450 | ||
wordcloud_width = 780 | ||
wordcloud_height = 720 | ||
|
||
|
||
def wordcloud(wxid): | ||
import jieba | ||
txt_messages = msg_db.get_messages_by_type(wxid, MsgType.TEXT) | ||
text = ''.join(map(lambda x: x[7], txt_messages)) | ||
total_msg_len = len(text) | ||
# 使用jieba进行分词,并加入停用词 | ||
words = jieba.cut(text) | ||
# 统计词频 | ||
word_count = Counter(words) | ||
# 过滤停用词 | ||
stopwords_file = '../data/stopwords.txt' | ||
with open(stopwords_file, "r", encoding="utf-8") as stopword_file: | ||
stopwords = set(stopword_file.read().splitlines()) | ||
filtered_word_count = {word: count for word, count in word_count.items() if len(word) > 1 and word not in stopwords} | ||
|
||
# 转换为词云数据格式 | ||
data = [(word, count) for word, count in filtered_word_count.items()] | ||
# text_data = data | ||
data.sort(key=lambda x: x[1], reverse=True) | ||
|
||
text_data = data[:100] if len(data) > 100 else data | ||
# 创建词云图 | ||
keyword, max_num = text_data[0] | ||
w = ( | ||
WordCloud(init_opts=opts.InitOpts(width=f"{wordcloud_width}px", height=f"{wordcloud_height}px")) | ||
.add(series_name="聊天文字", data_pair=text_data, word_size_range=[20, 100]) | ||
.set_global_opts( | ||
title_opts=opts.TitleOpts( | ||
title=f"词云图", subtitle=f"总计{total_msg_len}字", | ||
title_textstyle_opts=opts.TextStyleOpts(font_size=23) | ||
), | ||
tooltip_opts=opts.TooltipOpts(is_show=True), | ||
legend_opts=opts.LegendOpts(is_show=False) | ||
) | ||
) | ||
# return w.render_embed() | ||
return { | ||
'chart_data': w.dump_options_with_quotes(), | ||
'keyword': keyword, | ||
'max_num': str(max_num), | ||
'dialogs': msg_db.get_messages_by_keyword(wxid, keyword, num=5) | ||
} | ||
|
||
|
||
class Analysis: | ||
pass | ||
|
||
|
||
if __name__ == '__main__': | ||
msg_db.init_database(path='../DataBase/Msg/MSG.db') | ||
w = wordcloud('wxid_0o18ef858vnu22') | ||
print(w) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
wxid | ||
就 | ||
说 | ||
啥 | ||
好 | ||
干 | ||
哦 | ||
好 | ||
嗯 | ||
恩 | ||
噢 | ||
喔 | ||
行 | ||
拿 | ||
乡村 | ||
炸弹 | ||
腹肌 | ||
|
@@ -2518,3 +2531,11 @@ sup | |
他 | ||
她 | ||
它 | ||
听 | ||
哪 | ||
想 | ||
打 | ||
🙄 | ||
奥 | ||
真 | ||
旺柴 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters