You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
analyzer.py
分析模块:根据关键词频率生成结论文本
"""
import os
class Analyzer:
"""弹幕关键词分析与结论生成"""
def __init__(self, output_dir="output"):
self.output_dir = output_dir
os.makedirs(self.output_dir, exist_ok=True)
print("🧠 分析器初始化")
def generate_conclusion(self, freq_counter, keyword):
"""生成分析结论"""
print("💡 生成数据分析结论")
total_words = sum(freq_counter.values())
top_words = freq_counter.most_common(8)
lines = []
lines.append(f"关键词分析主题:{keyword}")
lines.append(f"弹幕总词数:{total_words}")
lines.append("最常出现的热词:")
for w, c in top_words:
lines.append(f" - {w}: {c}")
# 简单趋势判断
focus = [w for w, _ in top_words]
if any("学习" in w for w in focus):
trend = "教育与学习相关方向热度高"
elif any("内容" in w or "创作" in w for w in focus):
trend = "内容创作与AI结合趋势明显"
elif any("应用" in w or "工具" in w for w in focus):
trend = "AI应用工具成为讨论焦点"
else:
trend = "整体舆情积极,用户关注技术与实践结合"
lines.append(f"\n趋势预测:{trend}")
lines.append("\n总体结论:")
lines.append(f"在B站关于「{keyword}」的讨论中观众总体情绪积极对AI技术发展充满兴趣。")
conclusion_path = os.path.join(self.output_dir, "conclusion.txt")
with open(conclusion_path, "w", encoding="utf-8") as f:
f.write("\n".join(lines))
print(f"✅ 结论已保存至: {conclusion_path}")