mongol-norm 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ """
2
+ mongol-norm — shape-aware normalizer for Traditional Mongolian script.
3
+ """
4
+ from .shaper import MongolianShaper
5
+
6
+ __version__ = "0.0.1"
7
+ __all__ = ["MongolianShaper"]
mongol_norm/_data.py ADDED
@@ -0,0 +1,59 @@
1
+ """
2
+ Bundled shaping data for mongol-norm (internal).
3
+
4
+ The JSON in `mongol_norm/data/` is the runtime data the shaper consumes:
5
+
6
+ * `<LOCALE>.json` — flat, language-agnostic shaping rules,
7
+ generated from mongfontbuilder + UTN #57.
8
+ * `<LOCALE>.normalize.json` — the normalize table (per-(position,
9
+ written-unit) FVS-pinned encodings),
10
+ generated from this package's own shaper.
11
+
12
+ Both are produced by the dev-only scripts in `scripts/` and committed here, so
13
+ the runtime needs no extra dependency and other-language ports can read the raw
14
+ files directly (see docs/data-format.md).
15
+
16
+ These loaders are internal — import `MongolianShaper`, not this module.
17
+ """
18
+ import json
19
+ from pathlib import Path
20
+ from typing import Any, Dict
21
+
22
+ # Bump on incompatible changes to the shaping-rules JSON schema.
23
+ SCHEMA_VERSION = 1
24
+ SUPPORTED_LOCALES = ("MNG", "MNGx", "TOD", "TODx", "SIB", "MCH", "MCHx")
25
+
26
+ # Plain filesystem path (not importlib.resources) so the package runs on
27
+ # Python 3.6+; wheel/sdist installs unpack to a real directory anyway.
28
+ # 用普通文件路径而非 importlib.resources,兼容 Python 3.6+。
29
+ _DATA = Path(__file__).parent / "data"
30
+
31
+
32
+ def _base(locale: str) -> str:
33
+ return locale[:-1] if locale.endswith("x") else locale
34
+
35
+
36
+ def load_rules(locale: str) -> Dict[str, Any]:
37
+ """Load the flat shaping-rules JSON for `locale`."""
38
+ with (_DATA / f"{_base(locale)}.json").open(encoding="utf-8") as f:
39
+ return json.load(f)
40
+
41
+
42
+ def rules_path(locale: str):
43
+ """Filesystem path to the shaping-rules JSON for `locale`."""
44
+ return _DATA / f"{_base(locale)}.json"
45
+
46
+
47
+ def load_normalize_table(locale: str) -> Dict[str, Any]:
48
+ """
49
+ Load the precomputed normalize table for `locale`. Raises FileNotFoundError
50
+ if it has not been generated yet (the shaper then falls back to running the
51
+ context-independence battery in-process).
52
+ """
53
+ with (_DATA / f"{_base(locale)}.normalize.json").open(encoding="utf-8") as f:
54
+ return json.load(f)
55
+
56
+
57
+ def normalize_table_path(locale: str):
58
+ """Filesystem path to the normalize-table JSON for `locale`."""
59
+ return _DATA / f"{_base(locale)}.normalize.json"