Skip to main content

classics-index

从扫描本的版心(页边书眉)OCR 里建章回索引:卷 → 篇 → 回。不依赖任何在线服务,纯 Python,无第三方运行时依赖(OCR 引擎是可选的)。

pip install -e .
classics-index volumes --headers heads.jsonl --out toc.json
classics-index pian    --toc toc.json --band titles.jsonl --out toc-pian.json
classics-index hui     --ocr hui.jsonl --names "1=西游记,2=水浒传" --out hui.json
classics-index find    --toc toc.json --q 卷3

与数据管线的关系:本包是私有工程 rag-build(OCR → 切块 → 向量 → RAG 数据库)的构建依赖。 数据管线的代码不在 socratic-tutor 仓库里,本包可独立使用,也可被任何索引管线复用。

它解决什么问题

点校本、影印本没有文本层,目录页也常常 OCR 不可用。但每一页的页眉都印着卷次("史記卷二")或回目("灵根育孕源流出心性修持大道生")。于是:

输入 输出
每页页眉带的 OCR({"page": n, "vol": 2}) 卷的起止页,连续覆盖全书
每页右侧标题带的 OCR({"page": n, "lines": [...]}) 篇名页与篇页码范围
章回小说每页页眉 OCR({"page": n, "texts": [...]}) 回目分段、附录标记、多部书切分

设计上的三个关键判据

  1. 卷靠"连续 ≥5 页":目录页也会写出"史記卷十三",那种孤页会被丢掉。
  2. 篇靠"行的形态"而不是字号:实测卷眉(48 px 宽)比篇名(46 px)还宽,宽度阈值不可靠;可靠的是"短行 + 序号结尾干净"(目录行末尾是":"或省略号)。
  3. 回靠"页眉标题变化":章回小说每页页眉都印着当前回目,标题一变就是新回;附录("附/录")重复上一回页眉,不能占回号。

数据从哪来

本包不产 OCR,只接受"每页一行的 JSONL"。配套的 OCR 脚本在私有数据工程 rag-build 的 eval/p3/(vertical_header_ocr.py、vertical_title_ocr.py、 novel_hui_ocr.py),它们只是 PaddleOCR 的一层薄封装:

  • 版心带:页面右侧 18%、高度 8%–55%,1.2 s/页;
  • 标题带:右侧 42%、高度 3%–65%,3.5 s/页;
  • 章回页眉:全宽、高度 3%–15%,0.55 s/页。

把任意 OCR 引擎的结果整理成本包要的 JSONL 也行——这正是本包能被别处复用的原因。

边界:哪些属于本包,哪些不属于

属于本包(纯逻辑,无 I/O、无第三方运行时依赖) 不属于(留在数据工程或运行时)
中文数字、卷/篇解析、页区间合并 OCR 引擎、裁切参数、页图渲染
章回切段、附录标记、编号、换书边界 SQLite 存储、RAG 入库、向量
find / at 的查询语义 书库路径、许可判定、产物管理

运行时的 sidecar/app/toc.py 只在本包之上加了个 toc 表;数据工程的入库脚本应当 直接 from classics_index import core, hui,而不是复制一份算法。

已在什么数据上验证

书 规模 结果
《史记》点校本 一 358 页 7 卷 + 7 篇,覆盖 358/358
《三国志》二 140 页 卷10–14 五篇篇名正确
四大名著合订本 2745/5291 页 216 回目段 / 3 部(旧输出 215,第 59/60 回曾被并段;第 60/61 回仍并段,见下)

限制

  • 版心位置是按中华书局版式调的,换版式要调裁切参数;
  • 章回小说的"换书边界"会晚一回(下一部第一回的页眉常没有"第一回");
  • 相似度阈值 0.55 偏低:第 60/61 回标题相似度 0.562,会被并成一段;历史副本还把第 59/60 回(0.452)并了,说明复制逻辑会漂移。改用 0.60 可修掉这一处,但需在 2745 页上全量回归,确认不产生过切;
  • 只处理竖排/横排的中文印刷体,不做手写、不做多栏学术期刊。

许可

MIT(见 LICENSE)。已发布到 PyPI:classics-index(当前 0.1.4)。

Metadata

Release files for classics-index 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for classics-index 0.1.4
File Size Uploaded Provenance Actions
classics_index-0.1.4.tar.gz 18.4 kB With provenance Details for classics_index-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for classics-index 0.1.4
File Interpreter ABI Platform Actions
classics_index-0.1.4-py3-none-any.whl Python 3 none any Details for classics_index-0.1.4-py3-none-any.whl

Total release size: 32.9 kB

Release files / classics_index-0.1.4.tar.gz

Download URL classics_index-0.1.4.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c0769824ab6da19facbe51ffc154c2b0aebf01ac9ee77e3ee8376f799e9d6019
BLAKE2b-256 checksum
How to use checksums
1e1cec632ad5f166df574b1c0cc20b438ad9a7d5b9242614b9d7df2a59f87bde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / classics_index-0.1.4-py3-none-any.whl

Download URL classics_index-0.1.4-py3-none-any.whl
Size 14.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc76f9ebdb84ff3d3fe4cb9cb11c11cd5b27426538f6966af6040d25dc692669
BLAKE2b-256 checksum
How to use checksums
327f73d0dd9c15b62b152019341fdfb37fd68ba436b8a19b7bebee45fad0b488
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for classics-index 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for classics_index-0.1.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page