|
|
|
@ -4,13 +4,11 @@ import os
|
|
|
|
|
import re
|
|
|
|
|
from openpyxl import Workbook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def writeintxt (words,outpath):
|
|
|
|
|
with open(outpath, 'w', encoding='utf-8') as output_file:
|
|
|
|
|
for line in words:
|
|
|
|
|
output_file.write(line)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def findfrecuency(txt_path,keywords,outpath):
|
|
|
|
|
if os.path.exists(txt_path):
|
|
|
|
|
# 读取原始文本文件,按行读入lines
|
|
|
|
@ -51,7 +49,6 @@ def writeinexcel (keyword_count,savepath):
|
|
|
|
|
# 保存 Excel 文件
|
|
|
|
|
wb.save(savepath)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ =='__main__':
|
|
|
|
|
# 定义文件路径
|
|
|
|
|
txt_path = 'd:\\学习\\软件工程\\swork\\res\\total300_3.txt'#总弹幕数据
|
|
|
|
@ -59,7 +56,7 @@ if __name__ =='__main__':
|
|
|
|
|
# 初始化一个字典来存储每个关键词的计数
|
|
|
|
|
keyword_count = {keyword: 0 for keyword in keywords}
|
|
|
|
|
#定义保存位置
|
|
|
|
|
savepath = "d:\\学习\\软件工程\\swork\\res\\AI_dm_rank4.xlsx"#存放排名,个数excel
|
|
|
|
|
outpath = "d:\\学习\\软件工程\\swork\\res\\select_ai4.txt"#存放有含ai技术评论的评价txt
|
|
|
|
|
savepath = "d:\\学习\\软件工程\\swork\\res\\AI_dm_rank.xlsx"#存放排名,个数excel
|
|
|
|
|
outpath = "d:\\学习\\软件工程\\swork\\res\\select_ai.txt"#存放有含ai技术评论的评价txt
|
|
|
|
|
keyword_count = findfrecuency(txt_path,keywords,outpath) #得到排名字典
|
|
|
|
|
writeinexcel (keyword_count,savepath) #将排名写入excel
|