先前的功能需求都是自己需要才做的
所以今天就来做个工会频道的文字云了解一下我们频道常聊的主题是什麽看看能不能透过bot来解决他们的问题
excel的输出结果:
爬下来的资料笔数为7810笔,这扩充功能还很贴心的告诉我们哪笔对话是BOT,Mentions栏位是指该对话有@别人,Attachments是该对话有上传附件档案,整体看下来是个相当乾净的资料,希望我们公司资料也能这麽乾净就好了ㄎㄎ
接下来开始先初步的清洗资料,清的对象有以下几点:
清完後的笔数为6482笔,接下来就是对聊天内容进行断词及辨识词性,断词的套件我推荐用CkipTagger,照连结的安装就可以了大家可以试试,比较可能会遇到问题的是不知道里面词性代表的意思是什麽,可以从这个连结查询
怕字数不够放个清整时的程序码,我只提取跟名词有关的词性
import pandas as pd
from ckiptagger import data_utils, construct_dictionary, WS, POS, NER
if __name__ == '__main__':
rdf = pd.read_excel("chathistory.xlsx",engine='openpyxl')
df = rdf[(rdf["Is bot"]=="No")&(rdf["Author username"]!="joe_美国爸爸ㄧ岛")]
df.dropna(subset=["Content"],inplace=True)
#对Content栏位里筛选出有中文的笔数
chinese_pattern = '[\u4e00-\u9fa5]+'
df = df[df['Content'].str.contains(chinese_pattern,regex=True)]
ws = WS(r"./data")
pos = POS(r"./data")
ner = NER(r"./data")
sentence_list = df['Content'].tolist()
word_sentence_list = ws(sentence_list)
pos_sentence_list = pos(word_sentence_list)
entity_sentence_list = ner(word_sentence_list, pos_sentence_list)
pos_list = ["Na","Nb","Nc","Ncd","Nd"]
clean_list = []
for i, sentence in enumerate(sentence_list):
# print_word_pos_sentence(word_sentence_list[i], pos_sentence_list[i])
assert len(word_sentence_list[i]) == len(pos_sentence_list[i])
for word, pos in zip(word_sentence_list[i], pos_sentence_list[i]):
if pos in pos_list:
# print("word")
clean_list.append(word)
with open("fout.txt", "w",encoding="utf-8") as fout:
print(*clean_list, sep="\n", file=fout)
根据文字云上的词其实可以判断出工会主要的玩家以新手居多,翻了一下对话纪录像是公会出现那麽多次是因为找管理员申请进公会,还有我发现主线跟副本出现次数多代表公会频其实有找团的需求,所以之後我会建一个找团的功能减少他们找团的时间
<<: Day 28 Chatbot integration- 汇率预测小工具
>>: Day 15 AWS云端实作起手式第五弹 建立流量负载分流Elastic Load Balancer (ELB)
上章我们在进行图像轮廓增强的处理时,有用到影像膨胀函数cv2.dilate,但那时候只是稍微带过,读...
不怎麽重要的前言 选择写这个大概一方面因为我有个程序设计基础零的朋友,因为教起来得太详细,不如乾脆一...
今天要来练习六指渊霓虹灯:https://www.sixvfx.com/night_club_neo...
Record the questions 时间越接近终点,反而越是卡关,於day20提到要拆解Pi...
假如一台电脑上,USB接数把不同品牌的量仪, 请问有甚麽方法或技术,可以撷取仪器讯号,得知量测数据是...