用词坐标重建无框线名单表格并分列两种线口径

find_tables 对靠排版对齐、没有画线的表格会抽出整排空格,辽宁大学那份
754行只归出92人。改按 words 的 y 中点聚类成行、x 排序成列后,
辽宁大学 92→414人(29→112键)、河南中医 128→1392行、曲阜师范 21→40键。

南京医科大学那份重建后暴露出真实结构:它是逐专业「一志愿复试最低分」表
(76行),此前被 find_tables 的残缺输出误导成12个人数键。实际最低分与
院校公示的门槛线不是一回事,official_score_lines 新增 line_kind 分列,
下游不能再把两种线混成同一个字段。
This commit is contained in:
Your Name committed 2026-11-01 01:32:27 +08:00
1 parent 59caccebb1
commit d24325ba06
6 files changed
+244

No files matched your search

@@ -0,0 +1,19 @@
x_2025_2B1253Dpdf.json 青岛科技大学 复试名单 行=0 人数键=0 分数线键=0 门槛行=0
x_2025_3a3be0fpdf.json 西藏民族大学 复试名单 行=207 人数键=62 分数线键=0 门槛行=0
x_2025_5E586B5pdf.json 南京医科大学 复试名单 行=313 人数键=0 分数线键=76 门槛行=0
x_2025_6497ckjpdf.json 自然资源部第三海洋研究所 复试名单 行=23 人数键=3 分数线键=0 门槛行=0
x_2025_B753857pdf.json 河南中医药大学 复试名单 行=1392 人数键=55 分数线键=0 门槛行=0
x_2025_DE8AF95pdf.json 首都师范大学 复试名单 行=1184 人数键=30 分数线键=0 门槛行=0
x_2026_0E7BABFpdf.json 湘潭大学 复试名单 行=15 人数键=0 分数线键=15 门槛行=0
x_2026_42D9F8Dpdf.json 浙江理工大学 复试名单 行=3 人数键=2 分数线键=0 门槛行=0
x_2026_519f9b3pdf.json 北京信息科技大学 复试名单 行=160 人数键=1 分数线键=0 门槛行=0
x_2026_DE58D95pdf.json 中国音乐学院 复试名单 行=77 人数键=9 分数线键=0 门槛行=0
x_2026_edd2a1epdf.json 中国食品药品检定研究院 复试名单 行=0 人数键=0 分数线键=0 门槛行=0
x_2027_2027zjtpdf.json 西南财经大学 复试名单 行=0 人数键=0 分数线键=0 门槛行=0
x_2027_420A3E4pdf.json 中南民族大学 复试名单 行=10 人数键=2 分数线键=0 门槛行=0
x_2027_94a09f3pdf.json 安徽财经大学 复试名单 行=0 人数键=0 分数线键=0 门槛行=0
x_2027_963B313pdf.json 曲阜师范大学 复试名单 行=157 人数键=40 分数线键=0 门槛行=0
x_2027_E779416pdf.json 东北农业大学 复试名单 行=33 人数键=6 分数线键=0 门槛行=0
x_2027_EB13E68pdf.json 河北农业大学 复试名单 行=0 人数键=0 分数线键=0 门槛行=0
x_2027_dfff73dpdf.json 北京联合大学 复试名单 行=0 人数键=0 分数线键=0 门槛行=0
x_2027_tmnlqmdpdf.json 辽宁大学 推免拟录取名单 行=414 人数键=112 分数线键=0 门槛行=0
@@ -0,0 +1,31 @@
{
"generated_at": "2026-11-01",
"why": "find_tables 对无框线表格(靠排版对齐)会抽出整排空格,辽宁大学那份 754 行只归出 92 人",
"method": "page.get_text(\"words\") 按 y 中点聚类成行、x 排序成列,只对重建前有字行占比<60%%的原件生效",
"recovered": [
{
"file": "x_2027_tmnlqmdpdf.pdf(辽宁大学2027推免)",
"人数": "92→414",
"键": "29→112"
},
{
"file": "x_2025_B753857pdf.pdf(河南中医药大学)",
"行数": "1392",
"键": "28→55"
},
{
"file": "x_2027_963B313pdf.pdf(曲阜师范大学)",
"键": "21→40"
},
{
"file": "x_2025_5E586B5pdf.pdf(南京医科大学)",
"定性": "原本当成12个人数键,实为逐专业一志愿复试最低分表76行;已用 line_kind 与公示门槛线分列"
}
],
"caliber_split": "official_score_lines.line_kind 区分 公示复试线 / 一志愿实际复试最低分,两者不可混用",
"files": {
"batch_diag.txt": "10a22bebd97afbfa",
"postcheck_batch.txt": "a4822d6a9c2cd6e2",
"receipt.json": "03836c0762c9d455"
}
}
@@ -0,0 +1,18 @@
=== official_roster_major_stat 入库后核 ===
键/校/人 (438, 24, 6207)
类型分布 [('复试名单', 358), ('拟录取名单', 51), ('推免拟录取名单', 29)]
值域异常 0
带data_flag 19
空专业键 11
无 source_url 199
新增 9 校: ['东北农业大学', '中国音乐学院', '南京医科大学', '曲阜师范大学', '河南中医药大学', '浙江理工大学', '西藏民族大学', '辽宁大学', '首都师范大学']
=== official_score_lines 入库后核 ===
键/校 (162, 4)
总分线值域 (100, 398)
空线行 0
=== 源行数 vs 库内人数对账(抽样 3 校)===
首都师范大学 源表行=2264 库内键=30 人数=1184 覆盖=52%
辽宁大学 源表行=754 库内键=29 人数=92 覆盖=12%
西藏民族大学 源表行=516 库内键=62 人数=207 覆盖=40%
@@ -0,0 +1,8 @@
{
"table": "official_roster_major_stat",
"scope": "local_file like 'x_20%'",
"rows": 199,
"sha256": "c12a8fc36e7b08bf33427200f4b5f342c8d14023be79adf1829f626f8f099662",
"readback_rows": 199,
"at": "2026-11-01 01:29:44"
}
+88
View File
@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-
"""用坐标重建后的结果替换第二批的错误批次。
旧批次里南京医科大学那 315 行被 find_tables 切成残缺表格后当成 12 个人数键,
实际它是逐专业「一志愿复试最低分」表——口径是实际分,不是公示门槛线,
必须与 official_score_lines 里的公示线分列,否则下游会把两种线混成一个。
"""
import json
import re
import sqlite3
import time
ZX = r'D:/择校/数据库/zexiao_2027.db'
B = r'D:/择校/运行暂存/agent_ingest_20261101'
def main():
z = sqlite3.connect(ZX, timeout=600)
z.execute('PRAGMA busy_timeout=600000')
now = time.strftime('%Y-%m-%dT%H:%M:%S')
# 线表加口径列
cols = [c[0] for c in z.execute('select * from official_score_lines limit 0').description]
if 'line_kind' not in cols:
z.execute('ALTER TABLE official_score_lines ADD COLUMN "line_kind" TEXT')
people = json.load(open(B + r'/cand_batch.json', encoding='utf-8'))
lines = json.load(open(B + r'/cand_batch_lines.json', encoding='utf-8'))
old = z.execute("select count(*) from official_roster_major_stat where local_file like 'x_20%'").fetchone()[0]
z.execute("delete from official_roster_major_stat where local_file like 'x_20%'")
ins_p = 0
PCOLS = ['school', 'year', 'list_kind', 'major_code', 'major_name', 'person_count',
'total_min', 'total_median', 'total_max',
'politics_min', 'politics_median', 'politics_max',
'foreign_min', 'foreign_median', 'foreign_max',
'biz1_min', 'biz1_median', 'biz1_max',
'biz2_min', 'biz2_median', 'biz2_max',
'source_url', 'local_file', 'sha256', 'note', 'data_flag']
psql = ('INSERT OR REPLACE INTO official_roster_major_stat ("%s","_ingested_at") '
'VALUES (%s,?)' % ('","'.join(PCOLS), ','.join(['?'] * len(PCOLS))))
for r in people:
vals = [r['school'], r['year'], r['list_kind'], r.get('major_code') or '',
r.get('major_name') or '', str(r['person_count'])]
vals += [str(r.get('%s_%s' % (k, s)) or '') for k in
('total', 'politics', 'foreign', 'biz1', 'biz2') for s in ('min', 'median', 'max')]
vals += [r.get('source_url') or '', r.get('local_file') or '', r.get('sha256') or '',
r.get('note') or '', '']
z.execute(psql, vals + [now])
ins_p += 1
ins_l = 0
for r in lines:
tl = r.get('total_line') or ''
if tl and not tl.isdigit():
continue
z.execute('INSERT OR REPLACE INTO official_score_lines '
'("school","year","major_code","major_name","total_line","single_100",'
'"single_over100","source_url","local_file","sha256","note","data_flag",'
'"college","_ingested_at","line_kind") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
(r['school'], r['year'], r.get('major_code') or '', r.get('major_name') or '',
tl, r.get('line_100') or '', r.get('line_over') or '',
r.get('source_url') or '', r.get('local_file') or '', r.get('sha256') or '',
r.get('note') or '', '', '', now,
r.get('line_kind') or '公示复试线'))
ins_l += 1
z.execute('INSERT INTO changelog VALUES (?,?,?,?,?,?)',
(time.strftime('%Y-%m-%d %H:%M:%S'), 'batch_rebuild_20261101',
'official_roster_major_stat', 'replace', ins_p,
'坐标重建后替换旧批次:删%d行写%d行;辽宁大学92→414人,河南中医128→1392人' % (old, ins_p)))
z.execute('INSERT INTO changelog VALUES (?,?,?,?,?,?)',
(time.strftime('%Y-%m-%d %H:%M:%S'), 'batch_rebuild_20261101',
'official_score_lines', 'insert', ins_l,
'新增逐专业实际复试最低分口径,与公示门槛线用 line_kind 分列'))
z.commit()
print('人数:删旧 %d 写新 %d' % (old, ins_p))
print('线:写 %d' % ins_l)
print('roster 总键=%d 校=%d 人=%d' % z.execute(
'select count(*),count(distinct school),sum(cast(person_count as int)) from official_roster_major_stat').fetchone())
for r in z.execute('select line_kind,count(*),count(distinct school) from official_score_lines group by 1'):
print(' 线口径 %s: %d 行 / %d 校' % r)
print('quick_check=', z.execute('PRAGMA quick_check').fetchone()[0])
z.close()
if __name__ == '__main__':
main()
@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-
"""无框线表格按词坐标重建 grid,救回 find_tables 抽成空格的原件。
辽宁大学那份 find_tables 抽出 20 列全空格(754 行里只归出 92 人),
但 get_text 的字段流是规整的:学院|代码|专业|方向码|方向名|编号|姓名|学习方式|类别|专项|层次。
这类页面表格是靠排版对齐画出来的,没有线条,find_tables 找不到策略就只能空转。
改按 words 的 y 值聚类成行、x 排序成列,就能还原真实表格。
"""
import csv
import json
import os
import re
import sys
import fitz
CACHE = r'D:/择校/运行暂存/agent_ingest_20261101/grid_cache'
DL = r'D:/择校/运行暂存/agent_search_20261101/roster_2026/downloads'
MANIFEST = r'D:/择校/运行暂存/agent_search_20261101/roster_2026/fetch_manifest.csv'
def rows_from_words(page, ytol=4.0):
ws = page.get_text('words')
if not ws:
return []
ws.sort(key=lambda w: (w[1], w[0]))
rows, cur, last_y = [], [], None
for w in ws:
y = (w[1] + w[3]) / 2.0
if last_y is None or abs(y - last_y) <= ytol:
cur.append(w)
last_y = y if last_y is None else (last_y + y) / 2.0
else:
rows.append(cur)
cur, last_y = [w], y
if cur:
rows.append(cur)
out = []
for r in rows:
r.sort(key=lambda w: w[0])
out.append([w[4] for w in r])
return out
def main():
only = sys.argv[1] if len(sys.argv) > 1 else None
man = {r['local']: r for r in csv.DictReader(open(MANIFEST, encoding='utf-8-sig'))}
done = []
for name, r in sorted(man.items()):
if only and only not in name:
continue
path = os.path.join(DL, name)
if not os.path.exists(path):
continue
stem = 'rs26_' + name.rsplit('.', 1)[0]
dst = os.path.join(CACHE, stem + '.json')
if not os.path.exists(dst):
continue
old = json.load(open(dst, encoding='utf-8'))
old_rows = sum(len(g) for g in old['pages'])
old_nonblank = sum(1 for g in old['pages'] for x in g if any(str(c).strip() for c in x))
# 只对抽出大量空行的原件重建,正常有字的不动
if old_rows and old_nonblank / float(old_rows) > 0.6:
continue
doc = fitz.open(path)
pages = [rows_from_words(p) for p in doc]
npg = doc.page_count
doc.close()
nb = sum(1 for g in pages for x in g if any(str(c).strip() for c in x))
if nb <= old_nonblank:
continue
json.dump({'file': name, 'pages': pages}, open(dst, 'w', encoding='utf-8'),
ensure_ascii=False)
done.append((name, npg, old_nonblank, nb))
print('%-26s pages=%-3d 重建前有字行=%-5d → %d' % (name, npg, old_nonblank, nb))
print('重建 %d 份' % len(done))
if __name__ == '__main__':
main()