From 330c84e7fce8be7d5ab8ebd3ccb4c3d6530d7773 Mon Sep 17 00:00:00 2001 From: pzb7h6yxf <1736289433@qq.com> Date: Tue, 17 Sep 2024 10:00:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1AI=E6=8A=80=E6=9C=AF=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=96=B9=E9=9D=A2=E7=9A=84=E6=AF=8F=E7=A7=8D=E5=BC=B9?= =?UTF-8?q?=E5=B9=95=E6=95=B0=E9=87=8F=EF=BC=8C=E5=B9=B6=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E6=8E=92=E5=90=8D=E5=89=8D8=E7=9A=84?= =?UTF-8?q?=E5=BC=B9=E5=B9=95=20Initial=20commit(2-2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.2.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 2.2.py diff --git a/2.2.py b/2.2.py new file mode 100644 index 0000000..9d71ab3 --- /dev/null +++ b/2.2.py @@ -0,0 +1,35 @@ +from collections import Counter + +# 读取TXT文件并统计AI相关关键词 +def count_ai_keywords(file_path): + # 定义与AI技术相关的关键词列表 + ai_keywords = [ + "AI", "人工智能", "Machine learning", "机器学习", "Deep learning", "深度学习", + "Neural network", "神经网络", "自然语言处理", "Natural language processing", + "计算机视觉", "Computer vision", "Robotics", "机器人", "自动化", "Automation", + "人脸识别", "Face recognition", "大数据", "数据挖掘", "智能系统", "自动驾驶", "无人驾驶","AI技术" + ] + + # 用来存储统计结果的Counter + keyword_count = Counter() + + # 读取文件 + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + # 遍历每个关键词,统计弹幕中包含关键词的数量 + for keyword in ai_keywords: + if keyword.lower() in line.lower(): # 统计关键词忽略大小写 + keyword_count[keyword] += 1 + + # 输出排名前8的关键词及其对应的数量 + top_keywords = keyword_count.most_common(8) + + print("AI 技术相关的前8条弹幕关键词统计:") + for keyword, count in top_keywords: + print(f"{keyword}: {count} 条弹幕") + +# 文件路径 +file_path = "danmakus_2024_olympics.txt" + +# 调用函数并统计 +count_ai_keywords(file_path)