Delete 'danmaku_analyzer.py'

main
fzu102301136 5 months ago
parent 39ff70d51b
commit c17dc71935

@ -1,93 +0,0 @@
from collections import Counter
import pandas as pd
class DanmakuAnalyzer:
def __init__(self, danmakus):
self.danmakus = [d.strip() for d in danmakus if d.strip()]
self.stopwords = self.load_stopwords()
def load_stopwords(self):
"""加载停用词"""
try:
with open("stopwords.txt", "r", encoding="utf-8") as f:
return set([line.strip() for line in f.readlines()])
except:
# 默认停用词
return set(["", "", "", "", "", "", "", "", "", "", "", "", "一个", "", "", "", "", "", "", "", "", "", "", "没有", "", "", "自己", ""])
def count_danmakus(self):
"""统计弹幕数量"""
# 过滤与AI技术应用无关的弹幕
ai_related_words = ["AI", "人工智能", "大模型", "语言模型", "LLM", "训练", "算法", "数据", "应用", "成本", "效率", "伦理", "隐私", "安全", "未来", "发展", "编程", "创作", "教育"]
ai_danmakus = [d for d in self.danmakus if any(word in d for word in ai_related_words)]
# 统计所有弹幕
all_counter = Counter(self.danmakus)
# 统计AI相关弹幕
ai_counter = Counter(ai_danmakus)
return all_counter, ai_counter
def save_to_excel(self, ai_counter, filename="弹幕统计.xlsx"):
"""保存统计结果到Excel"""
# 转换为DataFrame
df = pd.DataFrame(ai_counter.most_common(), columns=["弹幕内容", "出现次数"])
# 保存到Excel
df.to_excel(filename, index=False)
print(f"统计结果已保存到{filename}")
return df
def get_main_views(self, ai_counter):
"""分析用户主流看法"""
# 分类关键词
cost_related = ["成本", "价格", "费用", "免费", "付费"]
application_related = ["应用", "使用", "场景", "领域", "行业", "教育", "医疗", "工作", "创作", "编程"]
negative_related = ["风险", "危险", "伦理", "隐私", "安全", "失业", "替代", "问题"]
positive_related = ["方便", "高效", "厉害", "强大", "有用", "帮助", "进步"]
# 统计各类别弹幕
categories = {
"应用成本": 0,
"应用领域": 0,
"不利影响": 0,
"积极影响": 0,
"其他观点": 0
}
for danmaku, count in ai_counter.items():
matched = False
for word in cost_related:
if word in danmaku:
categories["应用成本"] += count
matched = True
break
if matched:
continue
for word in application_related:
if word in danmaku:
categories["应用领域"] += count
matched = True
break
if matched:
continue
for word in negative_related:
if word in danmaku:
categories["不利影响"] += count
matched = True
break
if matched:
continue
for word in positive_related:
if word in danmaku:
categories["积极影响"] += count
matched = True
break
if matched:
continue
categories["其他观点"] += count
return categories
Loading…
Cancel
Save