# file_parser **Repository Path**: liusssyang/file_parser ## Basic Information - **Project Name**: file_parser - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-08-23 - **Last Updated**: 2025-08-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 📄 支持格式文件批处理切块工具 本脚本用于对指定目录下的多种类型文件(如 Word、PDF、图像等)进行格式转换、解析、OCR 识别,并最终按指定大小进行文本切块处理。支持命令行参数配置,适用于自动化预处理流程。 ------ ## 🔧 功能说明 **对文件中的文字,表格,图像内容进行分块 ** - 支持的文件格式 - 文档类:`doc`, `docx`, `pdf`, `ofd`, `xml`, `txt` - 表格类:`xls`, `xlsx` - 图像类:`jpg`, `jpeg`, `png`, `gif`, `bmp`, `tiff`, `jfif`, `exif`, `wmf` ------ ## 📦 依赖项 确保以下模块/工具已安装并配置: ```bash python 3.12 pip install -r requirements.txt sudo apt install libreoffice ``` ------ ## 🚀 使用方式 ### ✅ 命令行调用示例 ```bash python main.py --input /your/input/folder --output /your/output/folder --chunk_size 400 --chunk_overlap 50 ``` ------ ## ⚙️ 命令行参数说明 | 参数名 | 类型 | 默认值 | 说明 | |-------------------|-------|---------|-----------------------| | `--input` | `str` | 必填 | 输入文件夹路径,支持包含子目录 | | `--output` | `str` | 同输入目录同级 | 输出目录路径 | | `--chunk_size` | `int` | `400` | 文本切块大小(字符数) | | `--chunk_overlap` | `int` | `50` | 文本切块重叠大小(字符数) | | `--use_cpu_only` | | | 加上这个参数不使用cuda对OCR模型加速 | ------ ## 🛠️ 输出文件夹结构说明 ``` /your/output/folder ├── unstc_data.json ├── unstc_failed.json └── unstc_index.json ``` 运行完成后,输出目录中将生成以下文件: | 文件名 | 内容说明 | |---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `unstc_data.json` | 主体切块结果,结构为一个字典,包含以下字段:
- `block`: 文本块列表
- `blockPosition`: 列表,每个文本块的位置信息(需要用的时候再联系我,可忽略)
- `imagePath`: 列表,若文本块由图像内容提取,则为对应图像路径;否则为空
- `fileName`: 列表,每个文本块来源的原始文件名
- `addedValue`: 列表,其他附加信息(一般不使用,可忽略) | | `unstc_failed.json` | 记录处理失败的文件信息,结构为列表,每项为字典,格式如:
`{'filePath': '失败文件的路径', 'reason': '失败原因'}` | | `unstc_index.json` | 切块结果的索引信息,结构为列表,每项元素为列表:
`[文件名, 文件扩展名, 起始索引(开区间), 结束索引(闭区间)]`
用于快速定位某个文件在 `unstc_data.json->block` 列表中的位置区间 |