Skip to main content

mongol-norm

PyPI Python versions crates.io Test

Shape-aware normalizer for Traditional Mongolian (Hudum) script. 传统蒙古文(回鹘式)形态感知规范化器。中文见下半部分。


English

Beta. shape / same_shape should be stable. The normalize output 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, store shaper.canonical_version with 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/2'

# Deduplicate
{shaper.normalize(w) for w in ["ᠰᠡᠢᠨ", "ᠰᠠᠢᠨ", "ᠰᠠᠶ᠋ᠢᠨ"]}   # → {'ᠰᠠᠢ᠍ᠢ᠍ᠠ᠌'}
  • shape / normalize take one word and raise ValueError on non-Mongolian characters; use normalize_text for sentences and mixed-script text.
  • A shape the built-in table cannot encode raises NormalizationFallbackError (a ValueError, with .text and .written_units). Pass strict=False to get the input back unchanged instead.
  • Locales: "MNG" (Hudum), "TOD", "SIB", "MCH". Only MNG normalizes; the others shape only.

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.


中文

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"(回鹘式)、"TOD"、"SIB"、"MCH",只有 MNG 支持规范化。

书写单元输入、调试接口和命令行见上方英文部分,用法相同。

Metadata

Release files for mongol-norm 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mongol-norm 0.2.3
File Size Uploaded
mongol_norm-0.2.3.tar.gz 98.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for mongol-norm 0.2.3
File
mongol_norm-0.2.3-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
mongol_norm-0.2.3-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details
mongol_norm-0.2.3-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details
mongol_norm-0.2.3-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.2.3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
mongol_norm-0.2.3-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
mongol_norm-0.2.3-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.2.3.tar.gz

Download URL mongol_norm-0.2.3.tar.gz
Size 98.2 kB
Tags Source
SHA-256 checksum
How to use checksums
aeee6e066101a12faf653426ed883ff169af0cf6cc705a3e3386695013c2c232
BLAKE2b-256 checksum
How to use checksums
4bde2f418d5b8084b89d75b619b0ca8640f640c633ddf80b7035125da1feab64
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 Sep 21, 2026.

Transparency log

Release files / mongol_norm-0.2.3-cp39-abi3-win_amd64.whl

Download URL mongol_norm-0.2.3-cp39-abi3-win_amd64.whl
Size 271.6 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
785b43443d19246286be17730bd8f0f05699b939cc794f1c022f8f2aee661af4
BLAKE2b-256 checksum
How to use checksums
18e70d018d2c671c1b1b5a419657609c534e0a04956ac5902c3fea61d037e1a9
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 Sep 21, 2026.

Transparency log

Release files / mongol_norm-0.2.3-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL mongol_norm-0.2.3-cp39-abi3-musllinux_1_2_x86_64.whl
Size 636.5 kB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
5553828f095421757ce8f04c27c9a003cde842b416a1462674cdd7108c30ed77
BLAKE2b-256 checksum
How to use checksums
f0c9f94a4abb91f00d53c39252883f90eb9751d68e80ff1fa7e728f14418da64
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 Sep 21, 2026.

Transparency log

Release files / mongol_norm-0.2.3-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL mongol_norm-0.2.3-cp39-abi3-musllinux_1_2_aarch64.whl
Size 600.8 kB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
a2c9150a878e41cfa1daef4379beb79f74dbc211cfc1424dff51354799251f0f
BLAKE2b-256 checksum
How to use checksums
d0b67c5a8a74919e0c76bd244a72d41c4467115cef0ec57d263b2e6db9ae0d2e
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 Sep 21, 2026.

Transparency log

Release files / mongol_norm-0.2.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mongol_norm-0.2.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 429.3 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
f60cd39b899bab155bc95a9f334f0de604de454902145bf6953b46f44f4fa57d
BLAKE2b-256 checksum
How to use checksums
fbf53357f7295e370c24a5312ddf5c5fb28ebb032ce2b8116cf266b8d99bb1be
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 Sep 21, 2026.

Transparency log

Release files / mongol_norm-0.2.3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL mongol_norm-0.2.3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 423.7 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
f0d7cc15f2675e0a2942c7b92da6f26c7ccd2a7a87124000487f64fbc024488a
BLAKE2b-256 checksum
How to use checksums
53640a867fdf2f0be18f109a2c5a3e4a65056b6dd229dace6f1605f7ae55f8fe
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 Sep 21, 2026.

Transparency log

Release files / mongol_norm-0.2.3-cp39-abi3-macosx_11_0_arm64.whl

Download URL mongol_norm-0.2.3-cp39-abi3-macosx_11_0_arm64.whl
Size 385.2 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
00523bcd55ebc399ab0b6c4f122985d48ee2c3a19a8d7b31e9f1fdbb177a34b7
BLAKE2b-256 checksum
How to use checksums
de67f1bd8892ee81441d78349afd9bbb4515e4c139405a9300d77fb57531c4e7
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 Sep 21, 2026.

Transparency log

Release files / mongol_norm-0.2.3-cp39-abi3-macosx_10_12_x86_64.whl

Download URL mongol_norm-0.2.3-cp39-abi3-macosx_10_12_x86_64.whl
Size 388.8 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
925cd4d39a937de25318ff31b600500797599a2bca1209fe80d1b73b20489ab8
BLAKE2b-256 checksum
How to use checksums
07d151630b0d7117f2f73fcd9e2af3cc4da1a68bb2e9c76ecade6be203fd9e1a
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 Sep 21, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.1

8 release files

This release

0.2.3 This release

8 release files

0.2.2

8 release files

0.2.1

8 release files

0.2.0

8 release files

0.1.1

8 release files

0.1.0

7 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page