Spaces:
Running
Running
Download scripts/11_ebsi_eqmap.py from lilyjeongwon/math-tutor: direct link, hf CLI and curl.
- Browser
- Download file 2.43 kB
-
https://huggingface.co/spaces/lilyjeongwon/math-tutor/resolve/main/scripts/11_ebsi_eqmap.py
- Command line
-
hf download hf://spaces/lilyjeongwon/math-tutor/scripts/11_ebsi_eqmap.py
-
curl -L -o 11_ebsi_eqmap.py https://huggingface.co/spaces/lilyjeongwon/math-tutor/resolve/main/scripts/11_ebsi_eqmap.py
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() | |