更新文档
This commit is contained in:
parent
f8b39b149c
commit
6d5f0f6df8
@ -7,9 +7,10 @@
|
|||||||
- 📖 读取Word文档(.docx格式)
|
- 📖 读取Word文档(.docx格式)
|
||||||
- 🔤 中文文本分词(基于jieba)
|
- 🔤 中文文本分词(基于jieba)
|
||||||
- 📊 词频统计分析
|
- 📊 词频统计分析
|
||||||
- 📈 生成词云图和词频柱状图
|
- 📈 生成词云图和词频柱状图(保存为文件,不弹窗显示)
|
||||||
- 📋 导出Excel分析报告
|
- 📋 导出Excel分析报告
|
||||||
- 🚫 智能过滤停用词
|
- 🚫 智能过滤停用词与标点、数字
|
||||||
|
- 📁 自动创建并使用`input`和`output`目录
|
||||||
|
|
||||||
## 安装依赖
|
## 安装依赖
|
||||||
|
|
||||||
@ -23,21 +24,28 @@ pip install -r requirements.txt
|
|||||||
|
|
||||||
### 1. 基本使用
|
### 1. 基本使用
|
||||||
|
|
||||||
将Word文档放在脚本同一目录下,然后运行:
|
将Word文档(.docx)放入脚本同级目录下的`word/input`文件夹(首次运行会自动创建),然后运行:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python word_frequency_analyzer.py
|
python word_frequency_analyzer.py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
运行完成后,所有输出会保存在`word/output`目录:
|
||||||
|
- `词频分析结果.xlsx`:Excel格式的详细分析报告(包含汇总与各文档高频词,默认前30)
|
||||||
|
- `词云图_[文档名].png`:每个文档的词云图
|
||||||
|
- `词频图_[文档名].png`:每个文档的词频柱状图(默认显示前15)
|
||||||
|
|
||||||
### 2. 自定义目录
|
### 2. 自定义目录
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from word_frequency_analyzer import WordFrequencyAnalyzer
|
from word_frequency_analyzer import WordFrequencyAnalyzer
|
||||||
|
|
||||||
# 指定Word文档所在目录
|
# 指定Word文档输入与结果输出目录
|
||||||
analyzer = WordFrequencyAnalyzer('/path/to/your/word/documents')
|
analyzer = WordFrequencyAnalyzer(input_dir='/path/to/your/word/documents',
|
||||||
|
output_dir='/path/to/output')
|
||||||
results = analyzer.analyze_all_documents()
|
results = analyzer.analyze_all_documents()
|
||||||
analyzer.print_results(results)
|
analyzer.print_results(results)
|
||||||
|
analyzer.export_to_excel(results) # 可选,未传入时默认保存到output目录
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. 单个文档分析
|
### 3. 单个文档分析
|
||||||
@ -49,9 +57,8 @@ result = analyzer.analyze_single_document('your_document.docx')
|
|||||||
|
|
||||||
## 输出文件
|
## 输出文件
|
||||||
|
|
||||||
脚本运行后会生成以下文件:
|
脚本运行后会在`output`目录生成以下文件:
|
||||||
|
- `词频分析结果.xlsx` - Excel格式的详细分析报告(包含汇总与各文档高频词)
|
||||||
- `词频分析结果.xlsx` - Excel格式的详细分析报告
|
|
||||||
- `词云图_[文档名].png` - 每个文档的词云图
|
- `词云图_[文档名].png` - 每个文档的词云图
|
||||||
- `词频图_[文档名].png` - 每个文档的词频柱状图
|
- `词频图_[文档名].png` - 每个文档的词频柱状图
|
||||||
|
|
||||||
@ -59,10 +66,9 @@ result = analyzer.analyze_single_document('your_document.docx')
|
|||||||
|
|
||||||
- 总词数统计
|
- 总词数统计
|
||||||
- 不重复词数统计
|
- 不重复词数统计
|
||||||
- 高频词排行榜(前20名)
|
- 高频词排行榜(打印前20名,Excel默认前30)
|
||||||
- 词云可视化
|
- 词云可视化
|
||||||
- 词频柱状图
|
- 词频柱状图(默认显示前15)
|
||||||
- Excel详细报告
|
|
||||||
|
|
||||||
## 支持的文档格式
|
## 支持的文档格式
|
||||||
|
|
||||||
@ -71,20 +77,25 @@ result = analyzer.analyze_single_document('your_document.docx')
|
|||||||
## 注意事项
|
## 注意事项
|
||||||
|
|
||||||
1. 确保Word文档为.docx格式(不支持.doc格式)
|
1. 确保Word文档为.docx格式(不支持.doc格式)
|
||||||
2. 脚本会自动过滤常见停用词和标点符号
|
2. 脚本会自动过滤常见停用词、标点符号以及数字;分词时会过滤长度小于2的词
|
||||||
3. 词云图需要系统支持中文字体
|
3. 图表不在窗口显示,直接保存到`output`目录
|
||||||
4. 建议在Python 3.7+环境下运行
|
4. 词云图需要系统支持中文字体
|
||||||
|
5. 建议在Python 3.7+环境下运行
|
||||||
|
|
||||||
## 自定义配置
|
## 自定义配置
|
||||||
|
|
||||||
### 修改停用词
|
### 修改停用词
|
||||||
|
|
||||||
可以在`WordFrequencyAnalyzer`类的`_load_stop_words`方法中添加或删除停用词。
|
可以在`WordFrequencyAnalyzer`类的`_load_stop_words`方法中添加或删除停用词。
|
||||||
|
|
||||||
### 调整分析参数
|
### 调整分析参数
|
||||||
|
- 修改`get_top_words`方法的`top_n`参数来改变高频词数量(默认30)
|
||||||
|
- 调整词云图和柱状图的样式参数(在`create_word_cloud`与`create_frequency_chart`中)
|
||||||
|
- 可自定义`input`与`output`目录位置(构造函数入参)
|
||||||
|
|
||||||
- 修改`get_top_words`方法的`top_n`参数来改变高频词数量
|
## 目录结构示例
|
||||||
- 调整词云图和柱状图的样式参数
|
|
||||||
|
- 输入目录:`word/input`
|
||||||
|
- 输出目录:`word/output`
|
||||||
|
|
||||||
## 故障排除
|
## 故障排除
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user