Files
note_sync/大模型/deepseek/_scripts/final_check.py
T

82 lines
2.8 KiB
Python

"""Strict final check of the DeepSeek paper collection.
Usage: python final_check.py <plan.json> <base_dir>
"""
import json
import os
import re
import sys
plan = json.load(open(sys.argv[1], encoding='utf-8'))
base = sys.argv[2]
problems = []
tot_cjk = 0
tot_pdf = 0
for p in plan:
tag = p['id']
pdf = os.path.join(base, p['pdf_path'])
md = os.path.join(base, p['md_path'])
# PDF
if not os.path.exists(pdf):
problems.append((tag, 'PDF missing'))
else:
with open(pdf, 'rb') as f:
head = f.read(5)
size = os.path.getsize(pdf)
tot_pdf += size
if head[:4] != b'%PDF':
problems.append((tag, 'PDF header invalid: %r' % head))
if size < 20000:
problems.append((tag, 'PDF too small: %d' % size))
# MD
if not os.path.exists(md):
problems.append((tag, 'MD missing'))
continue
t = open(md, encoding='utf-8').read()
cjk = len(re.findall(r'[\u4e00-\u9fff]', t))
tot_cjk += cjk
if not t.lstrip().startswith('# '):
problems.append((tag, 'no H1 heading'))
for sec in ['## 一、', '## 二、', '## 三、', '## 四、', '## 五、', '## 六、']:
if sec not in t:
problems.append((tag, 'missing section %s' % sec))
if cjk < 1200:
problems.append((tag, 'too little Chinese text: %d' % cjk))
if p['id'] not in t:
problems.append((tag, 'arXiv id not referenced in MD'))
if 'arxiv.org/abs/' + p['id'] not in t:
problems.append((tag, 'abs link missing in MD'))
# relative pdf link resolves
m = re.search(r'\]\(\./([^)]+\.pdf)\)', t)
if not m:
problems.append((tag, 'no relative PDF link'))
else:
target = os.path.join(os.path.dirname(md), m.group(1))
if not os.path.exists(target):
problems.append((tag, 'relative PDF link broken: %s' % m.group(1)))
elif target != pdf.replace('/', os.sep) and os.path.basename(target) != os.path.basename(pdf):
problems.append((tag, 'PDF link points elsewhere: %s' % m.group(1)))
# README
rd = os.path.join(base, 'README.md')
if not os.path.exists(rd):
problems.append(('README', 'missing'))
else:
rt = open(rd, encoding='utf-8').read()
if '(待生成)' in rt:
problems.append(('README', 'still contains 待生成 placeholder'))
listed = len(re.findall(r'\| \d+ \| \[', rt))
if listed != len(plan):
problems.append(('README', 'overview rows %d != %d' % (listed, len(plan))))
for p in plan:
if p['stem'] not in rt:
problems.append(('README', 'missing entry ' + p['stem']))
print('papers checked :', len(plan))
print('total PDF bytes : %.1f MB' % (tot_pdf / 1024 / 1024))
print('total Chinese chars :', tot_cjk)
print('problems :', len(problems))
for t, m in problems:
print(' !', t, m)