mongol-norm
Shape-aware normalizer for Traditional Mongolian (Hudum) script. 传统蒙古文(回鹘式)形态感知规范化器。中文见下半部分。
English
Beta.
shape/same_shapeshould be stable. Thenormalizeoutput currently encodes by glyph shape, not the standard phonetic (nominal-character) spelling, and may change in a later release. For example ᠮᠣᠩᠭᠣᠯ (MA+O+ANG+GA+O+LA) normalizes to ᠮᠣᠠᠭ᠌ᠨ᠋ᠨ᠋ᠣᠯ (MA+O+A+GA+FVS2+NA+FVS1+NA+FVS1+O+LA). If you store normalized keys, storeshaper.canonical_versionwith them and rebuild when it changes.
Why
The same visible Mongolian word can be typed as many different Unicode sequences (A/E look alike,
O/U share forms, FVS and joiners give the same glyph several ways), so search, deduplication and
indexing break. mongol-norm runs the UTN #57 v4
shaping rules — no font needed — to compare words by what they look like and map every encoding
of a word to one key.
This package is a thin binding over the Rust crate
mongol-norm; both give byte-identical results.
Install
pip install mongol-norm
CPython ≥ 3.9. The engine is compiled into the extension, so there are no runtime dependencies and
no Rust toolchain to install. Prebuilt cp39-abi3 wheels:
| Platform | Wheels |
|---|---|
| Linux x86_64 / aarch64 | glibc (manylinux2014) and musl (musllinux_1_2) |
| macOS | x86_64 and Apple silicon (arm64) |
| Windows | x64 |
On any other platform pip falls back to the source distribution, which compiles the extension
locally and needs Rust ≥ 1.83. The install also puts the mongol-norm command on PATH.
Usage
from mongol_norm import MongolianShaper
shaper = MongolianShaper(locale="MNG")
shaper.shape("ᠰᠠᠢᠨ") # → ['S', 'A', 'I', 'I', 'A']
shaper.shape_str("ᠰᠠᠢᠨ") # → 'S+A+I+I+A'
shaper.same_shape("ᠰᠠᠢᠨ", "ᠰᠡᠢᠨ") # → True
shaper.normalize("ᠰᠡᠢᠨ") # → 'ᠰᠠᠢ᠍ᠢ᠍ᠠ᠌'
shaper.normalize_text("Hello ᠰᠡᠢᠨ world") # → 'Hello ᠰᠠᠢ᠍ᠢ᠍ᠠ᠌ world'
shaper.canonical_version # → 'mng-canonical/3'
# Deduplicate
{shaper.normalize(w) for w in ["ᠰᠡᠢᠨ", "ᠰᠠᠢᠨ", "ᠰᠠᠶ᠋ᠢᠨ"]} # → {'ᠰᠠᠢ᠍ᠢ᠍ᠠ᠌'}
shape/normalizetake one word and raiseValueErroron non-Mongolian characters; usenormalize_textfor sentences and mixed-script text.- A shape the built-in table cannot encode raises
NormalizationFallbackError(aValueError, with.textand.written_units). Passstrict=Falseto get the input back unchanged instead. - Locale:
"MNG"(Hudum), the only one. Todo, Sibe and Manchu are not supported.
Written-unit input, if you already have a shape:
shaper.normalize_written_units(["B", "Aa"]) # → 'ᠪᠠ᠋'
shaper.normalize_positioned_written_units([
{"unit": "B", "position": "init"},
{"unit": "Aa", "position": "fina"},
]) # → 'ᠪᠠ᠋'
shaper.parse_written_units("B+Aa") # → ['B', 'Aa']
Debugging: shape_detailed(text) (per-letter breakdown), trace(text) (rule-by-rule trace),
rule_names().
Command line
mongol-norm shape 'ᠰᠠᠢᠨ' # → S+A+I+I+A
mongol-norm same 'ᠰᠠᠢᠨ' 'ᠰᠡᠢᠨ' # exit 0 if identical, 1 if not
mongol-norm normalize 'ᠰᠡᠢᠨ'
mongol-norm normalize-text -i in.txt -o out.txt
mongol-norm normalize --batch -i words.txt -o keys.txt # one word per line
mongol-norm --help lists every option.
Links
- Source, issues, docs: https://github.com/Satsrag/mongol-norm
- How it works:
docs/internals.md - License: MIT. Rules and data derived from UTN #57 and mongfontbuilder (MIT); see NOTICE.
中文
Beta 版。
shape/same_shape应该是稳定的。normalize的输出目前是按字形编码的,不是按读音 书写的标准名义字符序列,后续版本有可能修改。例如 ᠮᠣᠩᠭᠣᠯ(MA+O+ANG+GA+O+LA)规范化后是 ᠮᠣᠠᠭ᠌ᠨ᠋ᠨ᠋ᠣᠯ (MA+O+A+GA+FVS2+NA+FVS1+NA+FVS1+O+LA)。如果要持久化规范化后的 key,请同时保存shaper.canonical_version,版本变化时重建。
为什么
同一个看起来一样的蒙古文词可以用很多种 Unicode 序列输入(A/E 同形、O/U 共享字形、FVS 和连接符能用不同
方式得到同一字形),导致搜索、去重、索引失效。mongol-norm 按
UTN #57 v4 整形规则(不需要字体)按外形比较词,并把同一个
词的所有编码映射成同一个 key。
本包是 Rust crate mongol-norm 的薄绑定,结果与 crate 逐字节相同。
安装
pip install mongol-norm
CPython ≥ 3.9。引擎已编译进扩展模块,无运行时依赖,也不需要安装 Rust 工具链。预编译 cp39-abi3 wheel:
| 平台 | wheel |
|---|---|
| Linux x86_64 / aarch64 | glibc(manylinux2014)与 musl(musllinux_1_2) |
| macOS | x86_64 与 Apple silicon(arm64) |
| Windows | x64 |
其他平台 pip 会回退到源码包,在本地编译扩展,需要 Rust ≥ 1.83。安装后同时会有 mongol-norm 命令。
用法
from mongol_norm import MongolianShaper
shaper = MongolianShaper(locale="MNG")
shaper.shape("ᠰᠠᠢᠨ") # → ['S', 'A', 'I', 'I', 'A']
shaper.same_shape("ᠰᠠᠢᠨ", "ᠰᠡᠢᠨ") # → True
shaper.normalize("ᠰᠡᠢᠨ") # → 'ᠰᠠᠢ᠍ᠢ᠍ᠠ᠌'
shaper.normalize_text("Hello ᠰᠡᠢᠨ world") # → 'Hello ᠰᠠᠢ᠍ᠢ᠍ᠠ᠌ world'
# 去重
{shaper.normalize(w) for w in ["ᠰᠡᠢᠨ", "ᠰᠠᠢᠨ", "ᠰᠠᠶ᠋ᠢᠨ"]} # → {'ᠰᠠᠢ᠍ᠢ᠍ᠠ᠌'}
shape/normalize只处理单个词,遇到非蒙古文字符抛ValueError;句子或混合文本用normalize_text。- 内置表无法编码的 shape 抛
NormalizationFallbackError(ValueError子类,带.text、.written_units); 传strict=False则原样返回。 - locale:只有
"MNG"(回鹘式),不支持托忒文、锡伯文、满文。
书写单元输入、调试接口和命令行见上方英文部分,用法相同。
Metadata
Release files for mongol-norm 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mongol_norm-0.3.1.tar.gz | 144.4 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| mongol_norm-0.3.1-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details |
| mongol_norm-0.3.1-cp39-abi3-musllinux_1_2_x86_64.whl | CPython 3.9 | abi3 | Linux musl 1.2+ x86-64 | Details |
| mongol_norm-0.3.1-cp39-abi3-musllinux_1_2_aarch64.whl | CPython 3.9 | abi3 | Linux musl 1.2+ ARM64 | Details |
| mongol_norm-0.3.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| mongol_norm-0.3.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| mongol_norm-0.3.1-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details |
| mongol_norm-0.3.1-cp39-abi3-macosx_10_12_x86_64.whl | CPython 3.9 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 3.2 MB
Release files / mongol_norm-0.3.1.tar.gz
| Download URL | mongol_norm-0.3.1.tar.gz |
|---|---|
| Size | 144.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c1f96f34c0046178300870d83e5fbfa35d6a2ff031fae1cd3bdf343a8d09aa5a
|
|
BLAKE2b-256 checksum How to use checksums |
92af6e6a320e3bdea3d18dc8ed4545e3ba104cec14fa358e997ff412a53043ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logRelease files / mongol_norm-0.3.1-cp39-abi3-win_amd64.whl
| Download URL | mongol_norm-0.3.1-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 264.8 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
9ff28d41ead5964701d2fc1f5388025db6b029750801bbdd7f43b647d2e02086
|
|
BLAKE2b-256 checksum How to use checksums |
12b5948ea0dab6e7c98df88e3fd2c08af6c7734080c173ef130e0276ed2d58b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logRelease files / mongol_norm-0.3.1-cp39-abi3-musllinux_1_2_x86_64.whl
| Download URL | mongol_norm-0.3.1-cp39-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 627.2 kB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
52ac4aa169211e80b6ee9e60073a69eda7a260f7872cb08cda7ac8f5eaa752fe
|
|
BLAKE2b-256 checksum How to use checksums |
c68be5d8e7d5e2447f33c897b375120f3533fcd22cc28aa7227e6f535ef9eae5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logRelease files / mongol_norm-0.3.1-cp39-abi3-musllinux_1_2_aarch64.whl
| Download URL | mongol_norm-0.3.1-cp39-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 592.3 kB |
| Tags | CPython 3.9 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
dc9413b9be912e64ad2ab692236f1e9889ec9048612f4972b8830f4108d89f96
|
|
BLAKE2b-256 checksum How to use checksums |
666c04de516000ed6dffc604ce7cffd635aa207d54f985dbc81f82db5327fba4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logRelease files / mongol_norm-0.3.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | mongol_norm-0.3.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 418.5 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
c4035e0185d2e5981e33ca701405c34e9830ff261fde8579f9edf5e595a24075
|
|
BLAKE2b-256 checksum How to use checksums |
c05dc1cd861220b385173094fc4f6a6eecd7eb7a6c505675671f47510c2a2806
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logRelease files / mongol_norm-0.3.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | mongol_norm-0.3.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 414.6 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
3f448af66c39c4d173ddb372a76732162d32c38a7d6ae8786dec126bf16c6b02
|
|
BLAKE2b-256 checksum How to use checksums |
1f63e8f2d2d735a5a4c8a41d8883087ad3f81159d39863feb8d65def33feb202
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logRelease files / mongol_norm-0.3.1-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | mongol_norm-0.3.1-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 378.6 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b132b3c49d878b98f51c53fd4e67164a56e159f3556faaf3e8cb0a3fcc9906ff
|
|
BLAKE2b-256 checksum How to use checksums |
75de32d314ae888b171460115464059fbc899f6585eb2aca0422084842976bf9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logRelease files / mongol_norm-0.3.1-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | mongol_norm-0.3.1-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 379.7 kB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
8b41ab256f13af2faaaf715330a870e9392aa38d403186b184cee3964a86b0d9
|
|
BLAKE2b-256 checksum How to use checksums |
e1dbbee93f862667126517b8acc9be56fa0abd70ae41386c8099f00ad5ad4f77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency log