背诵版01 扩展段逐条标源 + 防幻觉校验器

- 扩展段 76 条加来源角标:〔张宇〕40 条(tex 有据)、〔补〕36 条(我补的),参考占比 52.6%
- 修正 §7.2 事实错误:e^{1/x} 在 0 处左 0 右 +∞,属第二类无穷间断点,不是跳跃
- 「教材原文 / 教材例」措辞改为「张宇三十讲整理稿 / 张宇例」——该 tex 是张宇三十讲整理稿,非同济教材
- 新增 .workbuddy/tools/check_source_tags.py:扩展条目缺角标即 FAIL,〔张宇〕占比<20% 也 FAIL
- README 增「背诵版三段式标准 v2」硬规则;MEMORY 增防幻觉硬约束五条
This commit is contained in:
2026-11-22 23:36:08 +08:00
parent fad9320731
commit 1fe52bc6c0
5 changed files with 290 additions and 98 deletions
+130
View File
@@ -0,0 +1,130 @@
# -*- coding: utf-8 -*-
"""背诵版「扩展」段来源角标校验器。
规则(2026-11-22 用户定,见 知识点构建/README.md §五):
每个知识点的 **扩展** 段,每条列表项末尾必须带来源角标:
〔张宇〕 = 该条主体能在 参考仓库/Math/advanced-math 原文找到
〔补〕 = 参考仓库没有,是我补的(通用知识 / 真题归纳 / 陷阱 / 流程)
混血条目一律标〔补〕——〔补〕的含义是「这句要你自己判断对错」。
用法:
python check_source_tags.py # 扫 知识点构建 全目录
python check_source_tags.py --file x.md # 只查一个文件
python check_source_tags.py --min-ref 20 # 〔张宇〕占比下限,默认 20%
退出码:0 通过;1 有缺标或占比异常。
只检查含「**教材**」标记的文件(即已按三段式重构的);旧结构文件跳过并列出。
"""
import io
import os
import re
import sys
TAG_ZY = '〔张宇〕'
TAG_BU = '〔补〕'
BASE = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
DEFAULT_DIR = os.path.join(BASE, '基于考研的学习', '数学一', '知识点构建')
def check_file(path, min_ref=20):
txt = io.open(path, encoding='utf-8').read()
name = os.path.basename(path)
if '**教材**' not in txt:
return None # 旧结构,未重构
lines = txt.split('\n')
# 切小节:### 开头到下一个 ### 或 ## 之前
secs = []
cur = None
for i, ln in enumerate(lines, 1):
if re.match(r'^#{2,3} ', ln):
if cur:
secs.append(cur)
cur = {'title': ln.strip('# ').strip(), 'line': i, 'body': []} if ln.startswith('### ') else None
if cur is None:
if secs and False:
pass
elif cur is not None:
cur['body'].append((i, ln))
if cur:
secs.append(cur)
problems = []
n_zy = n_bu = n_untag = 0
for s in secs:
# 找扩展块
in_ext = False
ext_items = []
for i, ln in s['body']:
if ln.startswith('**扩展**'):
in_ext = True
continue
if ln.startswith('**') and in_ext:
in_ext = False
if in_ext and ln.startswith('- '):
ext_items.append((i, ln))
if not ext_items:
problems.append((s['line'], s['title'], '缺少「**扩展**」段或段内无条目'))
continue
for i, ln in ext_items:
if TAG_ZY in ln:
n_zy += 1
elif TAG_BU in ln:
n_bu += 1
else:
n_untag += 1
problems.append((i, s['title'], '扩展条目未标来源:' + ln.strip()[:36] + '…'))
total = n_zy + n_bu + n_untag
ref_pct = (100.0 * n_zy / total) if total else 0.0
ok = (not problems) and total > 0 and ref_pct >= min_ref
return {
'file': name, 'total': total, 'zy': n_zy, 'bu': n_bu,
'untag': n_untag, 'ref_pct': ref_pct, 'problems': problems, 'ok': ok,
}
def main():
args = sys.argv[1:]
min_ref = 20
target = None
for a in args:
if a.startswith('--min-ref='):
min_ref = float(a.split('=', 1)[1])
elif a == '--file':
pass
if '--file' in args:
target = args[args.index('--file') + 1]
files = [target] if target else sorted(
os.path.join(DEFAULT_DIR, f) for f in os.listdir(DEFAULT_DIR)
if f.endswith('.md') and '背诵版' in f)
if target:
files = [target]
done, skipped, bad = 0, [], []
for p in files:
r = check_file(p, min_ref)
if r is None:
skipped.append(os.path.basename(p))
continue
done += 1
flag = 'OK ' if r['ok'] else 'FAIL'
print('%s %-46s 条目%3d 〔张宇〕%3d 〔补〕%3d 参考占比%5.1f%%'
% (flag, r['file'], r['total'], r['zy'], r['bu'], r['ref_pct']))
if r['problems']:
for line, sec, msg in r['problems']:
print(' L%-5d %-22s %s' % (line, sec[:22], msg))
if not r['ok']:
bad.append(r['file'])
print('\n已重构 %d 篇;未重构(旧结构)%d 篇:%s'
% (done, len(skipped), '、'.join(x[:8] for x in skipped) if skipped else '无'))
if bad:
print('不合格:%s' % '、'.join(bad))
sys.exit(1)
print('全部通过。')
if __name__ == '__main__':
main()