ancient-book-kb
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "ancient-book-kb" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-4dc61341d61b737bac2e07c57a2e2e1a4b0b0bdc81cc657391dfdae294c81663. Verify the upstream source and version against https://skillhub.cn/skills/user_df439908/ancient-book-kb before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
An end-to-end ancient-book processing skill covering scanned facsimile OCR and already-digitized texts: OCR acquisition and fallback correction, sentence segmentation and layout, error annotation, 18-category entity annotation (NER), entity/relationship tagging, and export to knowledge base/triples. Methodology is based on the referenced project and is invoked when users mention related keywords or request its use.
Introduction source: third_party · user_df439908 · 1.0.3 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Audience
- Translation pending; see source documentation.
- Inputs and outputs
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: ancient-book-kb
description: 古籍(影印版扫描图 OCR / 已数字化文本)端到端处理技能。当用户提到"古书、古籍、影印本、OCR、古书识别、句读、实体标注、NER、命名实体识别、知识库、知识图谱、人物关系",或提供古书文本/图片需要结构化标注时使用。覆盖 OCR 获取全链路(查数字化库→本地 VLM→云端 API→回退校正)、句读排版、错字标注、18 类实体标注与知识库/三元组导出。方法论源自 github.com/baojie/shiji-kb。用户也可显式要求"用 ancient-book-kb 处理"来手动调用本技能。
agent_created: true
version: 1.1.2
license: Apache-2.0
author: JIANG-SMALL
homepage: https://github.com/baojie/shiji-kb古籍识别与知识库构建 (Ancient Book KB)
Overview
将 shiji-kb 的"智能体本体"方法论(自然语言 SKILL 驱动 Agent + 行内实体标注 + lint 校验 + 人在环)封装为端到端可复用流程,把影印版古书图片或已数字化文本转化为带句读、带 18 类实体标注、可导出三元组的知识库。
输入形态(任一皆可)
- 影印版扫描图(
.jpg/.png/.pdf)→ 先走 阶段 0(OCR 获取) 得到纯文本,再走阶段 A/B/C - OCR 后的纯文本(无标点、有错字、排版乱)→ 走阶段 A 后处理
- 已数字化带标点文本(维基文库 / ctext / 书格等)→ 直接进阶段 B 实体标注
产出
- 句读 + 错字标注的 Markdown 底本(
.md) - 18 类实体行内标注(
.tagged.md) - 实体清单与关系三元组(
entities.csv/triples.csv/knowledge.json/kg.ttl/kg.cypher/kg.gml/ Neo4j 导入对),可导入知识图谱 / 图数据库 / RDF / 可视化工具
阶段 0:OCR 获取全链路(影印版图片入口)★ 新增
这是小白落地的关键阶段。 完整可操作指南见 references/ocr_workflow.md,三个现成脚本见 scripts/。决策顺序如下,能省一步是一步:
0.1 先查数字化库(零成本、零 OCR 错误,优先做)
很多古籍已被数字化,直接拿到带标点的 clean 文本,可跳过整个 OCR 环节。
- 用
python scripts/find_digitized.py "书名"一键生成各大库的检索链接(维基文库 / ctext / 书格 / 识典古籍 / 国学大师 / 汉典)。 - 找到即下载
.txt,因已句读,可跳过阶段 A-4 句读,只做错字校对(A-5)后直接进阶段 B。 - 详见
references/ocr_workflow.md§0.1 的库清单与检索技巧。
0.2 本地 VLM OCR(隐私优先,适合珍本/未公开影印本)
数据不出本机,但需要 NVIDIA 显卡。两个开源模型任选:
- FireRed-OCR(小红书,2B,最易跑,~8GB 显存,Apache-2.0) — 纯
transformers,脚本scripts/ocr_firered_local.py开箱即用:pip install -U transformers qwen-vl-utils torch pillow python scripts/ocr_firered_local.py --input ./scan_pages --output ./ocr_raw输出每页一个 Markdown(
page_001.md)。详见references/ocr_workflow.md§0.2-A。 ★ 脚本支持断点续跑 + 自动重试:固定page_NNN编号,跑一半失败直接重跑同一条命令即只重试失败的页;偶发显存不足(CUDA OOM)会自动缩小--max-tokens再试;--retries控重试次数,--force全量重跑。 - DeepSeek-OCR-2(DeepSeek,更强,~24GB 显存) — 支持 vLLM / transformers 双路径,原生处理竖排/繁体/夹注/朱批。详见
references/ocr_workflow.md§0.2-B(含 conda 安装 + 推理代码)。
0.3 云端 API OCR(最快上手,按量付费,图片出公网)
- 腾讯云 通用印刷体识别
GeneralBasicOCR(ocr.tencentcloudapi.com,zh_rare支持繁体/生僻字)。脚本scripts/ocr_tencent.py封装好,填密钥即可批量跑:pip install tencentcloud-sdk-python pillow set TENCENT_SECRET_ID=xxx & set TENCENT_SECRET_KEY=yyy python scripts/ocr_tencent.py --input ./scan_pages --output ./ocr_raw --lang zh_rare⚠️ 关键限制:腾讯云 OCR 无竖排参数。竖排古籍须先切列并旋转 90° 成横排(
scripts/ocr_tencent.py自带--rotate-cw旋转,但仍需自行按列切图后逐列识别再拼接)。详见references/ocr_workflow.md§0.3。 ★ 脚本支持断点续跑 + 自动重试:失败页重跑即自动重试(密钥/权限类永久错误不重试,限频/网络抖动按--retries重试);--force可全量重跑。 - 备选云端:华为云文字识别(竖排/表格较强)、阿里云读光 OCR、百度智能云 OCR。
0.4 回退与校正(混合路线的核心)
- 主用本地 VLM,对低置信度/生僻字列,用云端 API 二次识别做交叉验证。
- 共识策略:两者一致→接受;不一致→标记
〈疑X〉交人工(阶段 A-5 接手)。 - 云端作金标准校正:本地 VLM 对某类难字反复出错时,用云端结果覆盖该字。
- 阶段 0 全部跑完后,
ocr_raw/下应有一页一文件的纯文本(不要加标点,句读交给阶段 A)。
无论哪条路径,阶段 0 的输出都应是无标点的原始识别文本,进入阶段 A 做句读/错字标注。
阶段 A:OCR 后处理(仅 OCR/影印本文本需要)
源自 SKILL_01i,按单向流水线逐层降噪(详见 references/annotation_method.md §一):
- 勘探 — 统计噪声形态、识别卷/篇结构
- 清洗 — 去重复页标、折叠空行、剥行首缩进
- 结构化 — Markdown 层级对应原书卷/篇/段
- 句读 — 分段(<800 字)送 LLM,用
references/prompts.md的"句读前置提示"规避三类系统偏差 - 错字标注 —
〈疑X〉(有候选) /〈?〉(无候选) /〈OCR:X〉(已确认误识),只标不改 - 引号作用域修复 —
python scripts/fix_quotes_scoped.py <md>(处理【】夹注独立作用域) - 校验 —
python scripts/verify_ocr_preserve.py <原OCR.txt> <整理后.md>,须逐字一致
铁律:字符保真。不得修改/增删/替换任何原文字符,不得繁简转换、异体字归并。订正交由多版本互校在阶段外进行。
阶段 B:18 类实体标注
源自 SKILL_03a(详见 references/annotation_method.md §二、references/prompts.md):
- 用 SYSTEM_PROMPT(temperature=0)逐章标注
- 严格使用 18 类标记
〖TYPE 实体〗(完整表见references/annotation_method.md§二) - 铁律:只加标记不改原文;严禁嵌套;标题行(
#开头)不标 - 消歧语法:
〖TYPE 显示名|规范名〗(如〖@台|吕台〗、〖=函谷|函谷关〗) - 校验 —
python scripts/lint_tags.py <tagged.md> --base <底本.md>(语法 lint + 字符保真)
阶段 C:知识库导出(独立工具 export_kb.py)
一键把 .tagged.md 解析为多格式知识库,不再依赖手工产出:
python scripts/export_kb.py a.tagged.md b.tagged.md --merge # 多卷合并为一个知识库 kb.*
python scripts/export_kb.py x.tagged.md --format ttl # 仅 RDF Turtle(需 rdflib)
产出(默认全部,--format 可单选:csv/json/ttl/neo4j/all):
entities.csv— 实体清单(去重、按 18 类分组、含出现频次)triples.csv— 关系三元组(同句共现 + 18 类类型对启发式语义关系:担任/活动于/隶属/出自/遣…)knowledge.json— 实体 + 三元组(供可视化 / 二次开发)kg.ttl— RDF Turtle(18 类本体 + 实例 + 三元组,可进 Apache Jena / RDFLib 校验)neo4j_nodes.csv+neo4j_relationships.csv— Neo4jadmin import格式,直进图数据库
实体/三元组去重键为 (类型, 规范名);多文件用
--merge合并去重;--out-dir指定输出目录,--json-report输出结构化报告。仅 TTL 需要rdflib(见 requirements.txt 路径 C)。 可选接入 9 步管线(结构→事件→关系→本体→推理→SKU→应用),见references/annotation_method.md§三。
局限与不适用场景
为正确预期,先说明本技能不能处理什么(完整版见 README.md「局限与不适用场景」):
- 图像质量:模糊、严重噪点、缺损、透视畸变的页面识别率显著下降;纯手写批注识别差,需先预处理。
- 单页长度:本地 OCR 单页约 8192 token 上限,超长页需切图;云端 API 单图 ≤10MB,超限跳过。
- 版面:竖排需按列切图;多栏混排 / 表中表易出现"结构幻觉",需人工复核。
- 硬件:本地 VLM 需 NVIDIA GPU(约 8GB 显存);无显卡请走查库或云端 API。
- 版权:未公开 / 受版权古籍优先本地 VLM 避免文本出公网,并先取得授权。
- AI 标注固有误差:实体边界 / 关系推断可能有错漏,坚持"只标不改、可迭代校对",配合
lint_tags.py与人工复核。
Resources
references/ocr_workflow.md— OCR 全链路操作手册(数字化库清单+检索技巧 / 本地 VLM 安装运行 / 云端 API 调用 / 回退校正 / 预处理竖排)references/annotation_method.md— 完整方法论(01i 七阶段 + 03a 18 类体系 + 铁律 + lint + 反思 + 9 步管线)references/prompts.md— 可复制的 LLM 提示词(句读前置提示、实体标注 SYSTEM_PROMPT)scripts/find_digitized.py— 生成各大数字化库检索链接(阶段 0.1)scripts/ocr_firered_local.py— 本地 FireRed-OCR 批量识别(阶段 0.2-A)scripts/ocr_tencent.py— 腾讯云 GeneralBasicOCR 批量识别(阶段 0.3)scripts/verify_ocr_preserve.py— 字符保真校验(阶段 A-7)scripts/lint_tags.py— 标记语法/lint + 字符保真(阶段 B-5)scripts/fix_quotes_scoped.py— 引号作用域栈修复(阶段 A-6)scripts/export_kb.py— 阶段 C 一键导出多格式知识库(csv/json/ttl/neo4j)
文档导航:深内容(OCR 手册 / 方法论 / 提示词 / 18 类实体 / 局限)在
README.md顶部的「📑 目录」与「🧭 深入阅读 / 进阶」有一站式跳转;完整方法论见references/。
使用示例
- "帮我把这批《XX》影印图识别并建知识库" → 0(查库/本地或云端 OCR)→ A → B → C → 产出
.tagged.md+entities.csv+triples.csv - "帮我把这段《XX》OCR 文本做句读和实体标注" → A → B → C
- "这段文字已经标点好了,直接做实体标注和三元组" → B → C
- "先看看《XX》网上有没有现成文本" → 0.1(find_digitized.py)
Current listing version
1.0.3
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 端到端古籍 OCR 与知识库构建流程
- 覆盖本地 VLM 与云端 API 多路径 OCR
- 支持 18 类实体标注与多格式知识库导出
Highlights
- 触发词覆盖全面,包含关键词与手动调用方式
Highlights
- 阶段划分清晰,含完整示例与脚本指引
Areas to improve
-
依赖声明不完整 Reported severity: Minor
scripts/export_kb.py 生成 TTL 格式需 rdflib,但未在 requirements.txt 显式声明
Recommendation: 在 requirements.txt 或文档中显式声明 rdflib 依赖
Highlights
- 工具来源明确,参数说明详细
- 覆盖断点续跑、自动重试、共识策略等异常处理
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 43, 53 -
Accounts, secrets or authorization
Use a dedicated least-privilege account. Keep secrets out of public content and command logs; verify the receiving service and tenant.
Mentioned in main document · lines 51, 58
Domains or addresses referenced in the document
These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.
- github.com
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.