Overview
This skill generates word frequency statistics and word cloud images from social media comment data.
Usage
Provide comment data in JSON format. The script will automatically:
- Read and parse comment data
- Use jieba for Chinese word segmentation
- Filter stop words
- Calculate word frequency
- Generate word cloud
- Output word frequency JSON and word cloud PNG
Input Format
Comment data should be in JSON format, each element contains a content field:
[
{"content": "This product is very useful"},
{"content": "High cost performance, recommend purchase"}
]
Output Format
{output_dir}/word_freq.json: Word frequency statistics{output_dir}/word_cloud.png: Word cloud image
Tech Stack
- Python 3.11+
- jieba 0.42.1
- wordcloud 1.9.3
- matplotlib 3.9.0
Parameters
data_source: Comment data file path (required)output_dir: Output directory (required)stop_words: Stop words file path (optional)custom_words: Custom vocabulary (optional, comma separated)max_words: Max words in word cloud (optional, default 200)
Example
python scripts/generate_wordcloud.py references/sample_comments.json output/ --max-words 10
Notes
- Need to install Python dependencies: jieba, wordcloud, matplotlib
- Need Chinese font file (use system font by default)
- Stop words file is a text file with one word per line
- Custom vocabulary will be added to tokenizer with priority
微信扫一扫