将电子书自动转换为交互式知识图谱 HTML
Project description
fast-read-book
将电子书(PDF / EPUB / DOCX / PPTX / XLSX / HTML / Markdown / 图片)自动转换为交互式知识图谱。
✨ 特性
- 📚 多格式支持 — PDF / EPUB / DOCX / PPTX / XLSX / HTML / Markdown / TXT
- 可以一键生成各个章节的实体思维导图,便于快速了解全书内容和结构
- 交互性体现在可点击的思维导图实体和原文档定位,方便了用户快速导航
- 支持 LLM 摘要,为每个实体生成摘要,方便用户快速了解
- 除了思维导图功能还有论证分析和叙事分析的发展线可视化,可以添加笔记
- 🖼️ OCR 回退 — 自动检测图像型 PDF 并调用 EasyOCR(中文支持)
- 🔤 编码自动检测 — UTF-8 / GBK / GB2312 / GB18030 / Big5 / Latin-1
- 📖 参考文献识别 — 自动将"参考文献"小节的编号条目(如
[1] Singhal)提取为实体 - 🌐 桌面应用 — Tkinter 原生 GUI(双击启动)
- 🎯 三视图阅读器 — 实体列表、思维导图、原文对照
📦 安装
pip install kg-book-tool
默认已包含 PDF / EPUB / DOCX / PPTX / XLSX / HTML / OCR 全套依赖,无需手动安装额外组件。
🚀 快速开始
命令行
# 从电子书中构建知识图谱
kg-build book.pdf --output data.json --js data.js
# 启用 LLM 摘要
kg-build book.epub --summary --model qwen2.5:7b
# 支持的格式:pdf / epub / docx / pptx / xlsx / html / md / txt / 图片
kg-build book.docx --output data.json
Python API
from kg_core import KnowledgeGraphBuilder
builder = KnowledgeGraphBuilder("book.pdf", model_name="qwen2.5:3b")
builder.load_book() # 自动识别格式
builder.extract_entities() # 章节标题 + 参考文献
builder.extract_definitions_and_paragraphs() # 实体定义与上下文
builder.build_relations() # 实体关系
data = builder.build() # 返回完整字典
builder.save_json("data.json")
builder.save_js("data.js") # 前端可用
builder.save_md("data.md", book_name="我的书") # 原文按章节保存
桌面应用
# 命令行启动
kg-desktop
# 或
python -m kg_app.desktop
Tkinter 原生窗口,包含:
- 选择电子文件
- 一键构建
- 实时查看知识图谱
- 实体浏览 / 关系网络 / 原文对照
🛠️ 支持的输入格式
| 格式 | 扩展名 | 解析器 |
|---|---|---|
| PDF(文本型) | .pdf |
PyMuPDF |
| PDF(图像型) | .pdf |
EasyOCR(自动回退) |
| EPUB | .epub |
ebooklib |
| Word | .docx |
python-docx |
| PowerPoint | .pptx |
python-pptx |
| Excel | .xlsx |
openpyxl |
| HTML | .html / .htm |
beautifulsoup4 |
| Markdown | .md |
内置 |
| 纯文本 | .txt |
内置(自动检测编码) |
| 图片 | .png / .jpg / ... |
EasyOCR |
📊 输出示例
$ kg-build book.pdf --output data.json --js data.js
[kg-build] 开始构建知识图谱...
书籍: book.pdf
模型: qwen2.5:3b
摘要: 否
JSON: data.json
JS: data.js
构建完成!
实体: 304
关系: 26832
有摘要: 0
有定义: 220
有段落: 295
📂 项目结构
kg-book-tool/
├── kg_core/ # 核心库(pip 入口)
│ ├── __init__.py
│ ├── builder.py # KnowledgeGraphBuilder:构建流程
│ ├── converters.py # 多格式转换 + OCR 回退
│ ├── text_cleaner.py # 编码检测与文本清洗
│ ├── summarizer.py # LLM 摘要(Ollama)
│ └── cli.py # kg-build 命令行
├── kg_app/ # Web + 桌面应用
│ ├── desktop.py # Tkinter 桌面入口
│ ├── main.py # Flask 后端
│ ├── gui.py # 旧版 GUI
│ ├── templates/ # 渲染模板
│ │ ├── index.html
│ │ └── reader.html
│ └── static/
│ ├── data/ # 生成的知识图谱数据
│ └── uploads/ # 用户上传的电子文件
├── scripts/ # 辅助脚本
├── setup.py # pip 打包配置
├── requirements.txt
├── prompt.json # LLM prompt 配置
├── deploy.ps1 # 一键部署脚本
└── DEPLOY.md # 部署指南
🧪 验证安装
import kg_core
print(kg_core.__version__) # '1.0.0'
from kg_core import (
KnowledgeGraphBuilder,
SummaryGenerator,
clean_text,
split_chapters,
)
print("All imports OK")
🐛 故障排查
| 问题 | 解决 |
|---|---|
ModuleNotFoundError: No module named 'fitz' |
pip install pymupdf |
easyocr 首次运行慢 |
首次会下载模型(约 100MB) |
| 中文乱码 | 项目已内置 chardet + charset_normalizer 自动检测 |
| 图像型 PDF 提取为空 | 项目已内置 EasyOCR 回退 |
| 参考文献未识别 | 实体识别优先用后端 is_reference 字段,详见 kg_core/builder.py |
📜 许可
MIT License — 详见 LICENSE
🔗 链接
- 📦 PyPI: https://pypi.org/project/kg-book-tool/
- 🐙 GitHub: https://github.com/shikunpneg/fast_read_book
- 📖 文档: https://shikunpneg.github.io/fast_read_book/
- 🐛 Issues: https://github.com/shikunpneg/fast_read_book/issues
- 📜 更新日志: CHANGELOG.md
- 🚀 部署: DEPLOY.md
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
kg_book_tool-1.0.2.tar.gz
(130.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kg_book_tool-1.0.2.tar.gz.
File metadata
- Download URL: kg_book_tool-1.0.2.tar.gz
- Upload date:
- Size: 130.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc8de34299adc4082cdd81cea568069e9c7d886eb13eefc2a324767062886e18
|
|
| MD5 |
11925a95f2611f0cc1cdc65b0e4b1552
|
|
| BLAKE2b-256 |
c942d8720f69f1fce56597530099e61792a6e6b7c20bacc0c29f51827af6110e
|
File details
Details for the file kg_book_tool-1.0.2-py3-none-any.whl.
File metadata
- Download URL: kg_book_tool-1.0.2-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44518138876f3a3229cef770df2881ff59a5ec3fb98d30c7f2f4f2468cefe2e7
|
|
| MD5 |
c92ea6a393db2b8aaae24c7c7c53a34c
|
|
| BLAKE2b-256 |
94db65e4fae362a4b4b4b56d258b7f2f2dd1e0ce824d76846d5214b72a4fbb9b
|