nonebot-plugin-wordcloud icon indicating copy to clipboard operation
nonebot-plugin-wordcloud copied to clipboard

Feature: 想去掉输出词云中出现的数字和标点符号,有没有方法

Open liuzj288 opened this issue 2 years ago • 4 comments

image

liuzj288 avatar Oct 09 '22 05:10 liuzj288

现在似乎还真没有什么好方法…可以暂时在 stopwords 里加上,但没法过滤全。

he0119 avatar Oct 09 '22 05:10 he0119

你好,我最近也在研究词云,这是目前我能想到的解决方案

import re

# 去除 CQ 码
message = re.sub(r"\[CQ:(.+)]", "", message)

# 去除 QQ 表情包
message = re.sub(r"[(.+)]", "", message)

# 去除实数
message = re.sub(r"^(\-|\+)?\d+(\.\d+)?$", "", message)

# 去除标点符号
# message = re.sub(r"\p{P}|\p{S}", "", message)

标点符号我主观认为可能会影响分词效果,所以我注释了那部分,不知道如何处理。


另外,由于在 Python 标准库中的正则模块不支持表达式使用 \p 的快捷符,所以我使用的是 PyPI 上的 regex,该库与标准库的用法大部分兼容。

- import re
+ import regex as re

目前能解决的问题:

  • [x] 数字(包括整数和浮点数)
  • [x] 中英文标点 (注:影响未知,需研究)
  • [x] CQ 码
  • [x] QQ 表情包

MSDNicrosoft avatar Jan 24 '23 08:01 MSDNicrosoft

现在似乎还真没有什么好方法…可以暂时在 stopwords 里加上,但没法过滤全。

stopwords是什么,可以设置屏蔽关键词吗,求教!

wei-z-git avatar Mar 13 '23 12:03 wei-z-git

stopwords是什么,可以设置屏蔽关键词吗,求教!

是的,设置了 stopwords 的词语不会出现在词云中。

he0119 avatar Mar 13 '23 12:03 he0119