Spaces:
Running

math-tutor / scripts /11_ebsi_eqmap.py
seongui2030
deploy 2026-12-03 20:26
b146445
Raw History Blame Contribute Delete
2.43 kB
r"""μˆ˜μ‹ κΈ€κΌ΄ μ „μš© μ½”λ“œ -> LaTeX 1μ°¨ λ³€ν™˜ (1단계: κΈ€μž λ‹¨μœ„ μΉ˜ν™˜).
κ±°λ“­μ œκ³±Β·λΆ„μˆ˜Β·κ·Όν˜ΈΒ·ν° μ€‘κ΄„ν˜Έμ²˜λŸΌ 'μœ„μΉ˜'κ°€ ν•„μš”ν•œ κ΅¬μ‘°λŠ” 2λ‹¨κ³„μ—μ„œ μ²˜λ¦¬ν•˜λ―€λ‘œ,
이 λ‹¨κ³„μ—μ„œλŠ” ꡬ쑰 기호(BAR, \sqrt, BRACE1~4, \dot, \frown)λ₯Ό λˆˆμ— λ„λŠ” ν‘œμ‹œλ‘œλ§Œ λ‚¨κΉλ‹ˆλ‹€.
μ‚¬μš© 예 (PowerShell)
python scripts\11_ebsi_eqmap.py --chunks data\ebsi\chunks # λ³€ν™˜ν‘œμ— μ—†λŠ” μ½”λ“œκ°€ μžˆλŠ”μ§€ 점검
python scripts\11_ebsi_eqmap.py --chunks data\ebsi\chunks --show 2022_09 5 22
"""
from __future__ import annotations
import argparse, collections, json
from pathlib import Path
MAP_PATH = Path(__file__).resolve().parent.parent / "configs" / "ebsi_eq_map.json"
def load_map(path: Path = MAP_PATH):
m = json.loads(path.read_text(encoding="utf-8"))
return m["pua"], m["unicode"]
def decode_basic(text: str, pua=None, uni=None):
"""returns (λ³€ν™˜λœ κΈ€, λ³€ν™˜ν‘œμ— μ—†λŠ” μ½”λ“œ λͺ©λ‘)"""
if pua is None:
pua, uni = load_map()
out, unknown = [], []
for ch in text:
o = ord(ch)
if 0xE000 <= o <= 0xF8FF:
e = pua.get(f"{o:04X}")
if e is None:
unknown.append(f"{o:04X}")
out.append(f"<?{o:04X}>")
elif e["kind"] == "struct":
out.append(f"⟦{e['latex']}⟧")
else:
out.append(e["latex"])
else:
out.append(uni.get(ch, ch))
return "".join(out), unknown
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--chunks", type=Path, required=True, help="10_ebsi_chunk.py κ²°κ³Ό 폴더")
ap.add_argument("--show", nargs="+", help="회차(예: 2022_09) 와 λ¬Έν•­ λ²ˆν˜Έλ“€")
a = ap.parse_args()
pua, uni = load_map()
miss = collections.Counter()
total = 0
for f in sorted(a.chunks.glob("*.jsonl")):
for line in f.read_text(encoding="utf-8").splitlines():
q = json.loads(line)
total += 1
_, unk = decode_basic(q["raw_text"], pua, uni)
miss.update(unk)
if a.show and q["exam"].startswith(a.show[0]) and str(q["number"]) in a.show[1:]:
print(f"[{q['exam']} {q['number']}번]\n{decode_basic(q['raw_text'], pua, uni)[0]}\n")
print(f"λ¬Έν•­ {total}개 점검 / λ³€ν™˜ν‘œμ— μ—†λŠ” μ½”λ“œ: {dict(miss) if miss else 'μ—†μŒ'}")
if __name__ == "__main__":
main()