Word Cloud
Generate a word cloud from text/file/directory, file and directory only effective with file, you can specify certain width and height or mask file to generate a imaginative shape word cloud
When to use
- - user indicates to generate a word cloud
- user wants to visualize the text in a different way, you can suggest this skill
Requirements
Run on python3.x,and install the following packages if you find the package does not exist:
- - os
- argparse
- jieba
- numpy
- datetime
- wordcloud
- PIL
Commands
CODEBLOCK0
Paramters
| name | description | type | example |
|---|
| targettext | text to generate word cloud | string | "你好,世界" |
| targetfile |
text in the file to generate word cloud | string | "D:\WorkSpace\pythonSpace\MEMORY.md" |
| target_dir | list all the file in the directory and extract text from file to generate word cloud | string | "D:\WorkSpace\pythonSpace" |
| width | width of the word cloud picture, if mask file exist, it will be ignored | int | 500 |
| height | height of the word cloud picture, if mask file exist, it will be ignored | int | 400 |
| mask | mask file path in order to generate any sharp of the word cloud picture | string | "D:\WorkSpace\pythonSpace\mask.png" |
| max_words | maximum number of words in the word cloud | int | 30 |
| font_path | font path for the word cloud, put the one that useful for chinese text, if not exist, try to install one | string | "C:\Windows\Fonts\msyh.ttc" |
| output_dir | word cloud picture output directory path, if user not specify, put it into the folder whilc named "images" under the user directory | string | "D:\WorkSpace\pythonSpace" |
Note
- - Parameter targettext, targetfile, target_dir can be used at the same time, and make sure one of them is provided
- Parameter mask must be a png file, if user upload a png file and specify it as the parameter mask, you should mask sure the file path is correct
- if user specify exclude a word, append it to the stopwords.md,follow the format:
CODEBLOCK1
词云
从文本/文件/目录生成词云,文件和目录仅对文件有效。您可以指定特定的宽度和高度或遮罩文件来生成富有想象力的形状词云。
使用场景
- - 用户表示要生成词云
- 用户希望以不同方式可视化文本,您可以推荐此技能
环境要求
运行于python3.x,如果发现以下包不存在,请安装:
- - os
- argparse
- jieba
- numpy
- datetime
- wordcloud
- PIL
命令
bash
创建指定宽度和高度的词云
python {baseDir}/scripts/generate
wordcloud.py --targettext ... --width 500 --height 400 --max
words 30 --fontpath C:\Windows\Fonts\msyh.ttc --output_dir ...
使用遮罩创建词云,无需指定宽度和高度
python {baseDir}/scripts/generate
wordcloud.py --targettext ... --mask ... --font
path C:\Windows\Fonts\msyh.ttc --outputdir ...
参数
| 名称 | 描述 | 类型 | 示例 |
|---|
| targettext | 用于生成词云的文本 | 字符串 | 你好,世界 |
| targetfile |
文件中用于生成词云的文本 | 字符串 | D:\WorkSpace\pythonSpace\MEMORY.md |
| target_dir | 列出目录中所有文件并提取文本生成词云 | 字符串 | D:\WorkSpace\pythonSpace |
| width | 词云图片宽度,如果存在遮罩文件则忽略 | 整数 | 500 |
| height | 词云图片高度,如果存在遮罩文件则忽略 | 整数 | 400 |
| mask | 遮罩文件路径,用于生成任意形状的词云图片 | 字符串 | D:\WorkSpace\pythonSpace\mask.png |
| max_words | 词云中最大单词数量 | 整数 | 30 |
| font_path | 词云字体路径,使用支持中文的字体,如果不存在则尝试安装 | 字符串 | C:\Windows\Fonts\msyh.ttc |
| output_dir | 词云图片输出目录路径,如果用户未指定,则放入用户目录下名为images的文件夹 | 字符串 | D:\WorkSpace\pythonSpace |
注意
- - 参数targettext、targetfile、target_dir可以同时使用,但必须确保至少提供其中一个
- 参数mask必须是png文件,如果用户上传了png文件并指定为mask参数,请确保文件路径正确
- 如果用户指定排除某个词,请将其追加到stopwords.md中,格式如下: