Skip to main content

mongol-norm

PyPI Python versions crates.io Test

mongol-norm is a Traditional Mongolian (Hudum) same-shape comparison and normalization tool. 传统蒙古文(回鹘式)同形比较与规范化工具。中文见下半部分。


English

mongol-norm is a Traditional Mongolian (Hudum) same-shape comparison and normalization tool. It is implemented according to the Mongolian shaping rules of UTN #57 (GB/T 25914—2023). It converts Mongolian text that has the same written form but different Unicode encodings into a unified encoding, making search, deduplication, and corpus processing easier.

This package is a thin binding over the Rust crate mongol-norm; both give byte-identical results.

Input requirements

This library is intended for Mongolian text under the UTN #57 (GB/T 25914—2023) rules. Text that uses other standards or encodings — for example Delehi, Oyun, and Menk related to GB/T 25914—2010, as well as Menk old shape codes, ZCode, Zvvnmod, and the like — must first be converted to UTN #57 (GB/T 25914—2023) before this library can be used. For encoding conversion, you may consider mongol-convert; that library is also currently in Beta, so use it with care and verify the conversion results.

An example

The following spellings look the same, but their Unicode encodings differ, so a direct string comparison treats them as different text. mongol-norm can tell that they have the same shape and produce the same normalized result.

Five encodings of sain all normalizing to the same canonical form

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

Beta. normalize output is a unified encoding by glyph shape, not standard spelling, and may change in a later release. Keep the original text; when storing normalized keys, also record shaper.canonical_version and rebuild after a version change.

from mongol_norm import MongolianShaper

shaper = MongolianShaper(locale="MNG")

shaper.shape("ᠰᠠᠢᠨ")          # U+1830 (SA) U+1820 (A) U+1822 (I) U+1828 (NA) → ['S', 'A', 'I', 'I', 'A']
shaper.shape("ᠰᠡᠢᠨ")          # U+1830 (SA) U+1821 (E) U+1822 (I) U+1828 (NA) → ['S', 'A', 'I', 'I', 'A']
shaper.shape("ᠰᠨ᠌ᠢᠢᠨ")        # U+1830 (SA) U+1828 (NA) U+180C (FVS2) U+1822 (I) U+1822 (I) U+1828 (NA) → ['S', 'A', 'I', 'I', 'A']
shaper.shape("ᠰᠠᠶ᠋ᠢᠨ")        # U+1830 (SA) U+1820 (A) U+1836 (YA) U+180B (FVS1) U+1822 (I) U+1828 (NA) → ['S', 'A', 'I', 'I', 'A']
shaper.shape("ᠰᠠᠶ᠋ᠶ᠋ᠨ")      # U+1830 (SA) U+1820 (A) U+1836 (YA) U+180B (FVS1) U+1836 (YA) U+180B (FVS1) U+1828 (NA) → ['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/6'

# 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.
  • Locale: "MNG" (Hudum), the only one. Todo, Sibe and Manchu are not supported.

Written-unit input, if you already have a shape (see docs/written-units.md for the complete vocabulary of all 42 WrittenUnit names):

shaper.canonical_units(["A", "B2"])                    # → ['A', 'O', 'Aa']
shaper.canonical_positioned_units([
    {"unit": "B", "position": "init"},
    {"unit": "Aa", "position": "isol"},
])                                                     # → ['B', 'Mvs', 'Aa']
shaper.normalize_written_units(["B", "A", "Aa"])       # → 'ᠪᠠ᠋' [b, a, fvs1] (["B", "Aa"] folds to the same)
shaper.normalize_positioned_written_units([
    {"unit": "B", "position": "init"},
    {"unit": "Aa", "position": "fina"},
])                                                     # → 'ᠪᠠ᠋' [b, a, fvs1]
shaper.parse_written_units("B+A+Aa")                   # → ['B', 'A', 'Aa']

Debugging: shape_detailed(text) (per-token breakdown whose written units align with shape(), while internal _shape_raw(text) / _shape_detailed_raw(text) expose pre-expansion UTN #57 units), 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.


中文

mongol-norm 是一个传统蒙古文(回鹘式)的同形比较与规范化工具,依据 UTN #57(GB/T 25914—2023)的蒙古文整形规则实现。它将书写形态相同、Unicode 编码不同的蒙古文转换为统一编码,方便搜索、去重和语料处理。

本包是 Rust crate mongol-norm 的薄绑定,结果与 crate 逐字节相同。

输入要求

本库面向 UTN #57(GB/T 25914—2023)规则下的蒙古文文本。采用其他标准或编码的文本,例如 GB/T 25914—2010 相关的 Delehi、Oyun、Menk,以及 Menk 旧形码、ZCode、Zvvnmod 等,需要先转换为 UTN #57(GB/T 25914—2023),才能使用本库。编码转换可考虑使用 mongol-convert,该库目前也处于 Beta 阶段,请谨慎使用,并核对转换结果。

一个例子

下面几种写法看起来相同,但 Unicode 编码不同,直接比较字符串会被当作不同文本。mongol-norm 可以判断它们同形,并生成相同的规范化结果。

五种 sain 编码全部规范化为同一个形式

安装

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 命令。

用法

Beta 提醒: normalize 输出的是按字形统一的编码,不是标准拼写,后续版本可能变化。建议保留原文;保存规范化键时,同时记录 shaper.canonical_version,版本变化后重建。

from mongol_norm import MongolianShaper

shaper = MongolianShaper(locale="MNG")

shaper.shape("ᠰᠠᠢᠨ")          # U+1830 (SA) U+1820 (A) U+1822 (I) U+1828 (NA) → ['S', 'A', 'I', 'I', 'A']
shaper.shape("ᠰᠡᠢᠨ")          # U+1830 (SA) U+1821 (E) U+1822 (I) U+1828 (NA) → ['S', 'A', 'I', 'I', 'A']
shaper.shape("ᠰᠨ᠌ᠢᠢᠨ")        # U+1830 (SA) U+1828 (NA) U+180C (FVS2) U+1822 (I) U+1822 (I) U+1828 (NA) → ['S', 'A', 'I', 'I', 'A']
shaper.shape("ᠰᠠᠶ᠋ᠢᠨ")        # U+1830 (SA) U+1820 (A) U+1836 (YA) U+180B (FVS1) U+1822 (I) U+1828 (NA) → ['S', 'A', 'I', 'I', 'A']
shaper.shape("ᠰᠠᠶ᠋ᠶ᠋ᠨ")      # U+1830 (SA) U+1820 (A) U+1836 (YA) U+180B (FVS1) U+1836 (YA) U+180B (FVS1) U+1828 (NA) → ['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/6'

# 去重
{shaper.normalize(w) for w in ["ᠰᠠᠢᠨ", "ᠰᠡᠢᠨ", "ᠰᠨ᠌ᠢᠢᠨ", "ᠰᠠᠶ᠋ᠢᠨ", "ᠰᠠᠶ᠋ᠶ᠋ᠨ"]}   # → {'ᠰᠠᠢ᠍ᠢ᠍ᠠ᠌'}
  • shape / normalize 只处理单个词,遇到非蒙古文字符抛 ValueError;句子或混合文本用 normalize_text。
  • 内置表无法编码的 shape 抛 NormalizationFallbackError(ValueError 子类,带 .text、.written_units); 传 strict=False 则原样返回。
  • locale:只有 "MNG"(回鹘式),不支持托忒文、锡伯文、满文。

书写单元输入、调试接口和命令行见上方英文部分,用法相同。完整的 shape() 输出书写单元参考见 docs/written-units.md。

Metadata

Release files for mongol-norm 0.5.0

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.5.0
File Size Uploaded Provenance Actions
mongol_norm-0.5.0.tar.gz 171.5 kB With provenance Details for mongol_norm-0.5.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for mongol-norm 0.5.0
File Actions
mongol_norm-0.5.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for mongol_norm-0.5.0-cp39-abi3-win_amd64.whl
mongol_norm-0.5.0-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details for mongol_norm-0.5.0-cp39-abi3-musllinux_1_2_x86_64.whl
mongol_norm-0.5.0-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details for mongol_norm-0.5.0-cp39-abi3-musllinux_1_2_aarch64.whl
mongol_norm-0.5.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for mongol_norm-0.5.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
mongol_norm-0.5.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for mongol_norm-0.5.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
mongol_norm-0.5.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for mongol_norm-0.5.0-cp39-abi3-macosx_11_0_arm64.whl
mongol_norm-0.5.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for mongol_norm-0.5.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 3.4 MB

Release files / mongol_norm-0.5.0.tar.gz

Download URL mongol_norm-0.5.0.tar.gz
Size 171.5 kB
Tags Source
SHA-256 checksum
How to use checksums
37c2c6be825b7372e184cce0ad93e22ecdc4b6191ebe2fc0aba38493a821ef46
BLAKE2b-256 checksum
How to use checksums
403f0130cb95264885375d8ad250b323a16b998d7dc8076b6f39d557ddeeaf02
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 Nov 30, 2026.

Transparency log

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

Download URL mongol_norm-0.5.0-cp39-abi3-win_amd64.whl
Size 281.3 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
87f908586d09bc6ab27c1cba68adc65a8fadac3ec151da607e81ee43c1c7400d
BLAKE2b-256 checksum
How to use checksums
d24083dfb10bf8098990bb6754f44345f0d9330734650d6923ceb35e70b23980
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 Nov 30, 2026.

Transparency log

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

Download URL mongol_norm-0.5.0-cp39-abi3-musllinux_1_2_x86_64.whl
Size 646.1 kB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
a10758a9172be8069ec02be6e28740d7960dd0c22199b46cfdb6ddcb0d9672b9
BLAKE2b-256 checksum
How to use checksums
a890930977a9fa9bb3a5a09ad7dba5ae03c688f16237bfacd3fe2421066cdd7b
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 Nov 30, 2026.

Transparency log

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

Download URL mongol_norm-0.5.0-cp39-abi3-musllinux_1_2_aarch64.whl
Size 610.8 kB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
c983e2f1d0922af38cc14eba1ec811c275a84e75fb85f7e6a0cc1b5dbf3fd0a7
BLAKE2b-256 checksum
How to use checksums
03da325aa2150df8fced57744ca9d1906aa7fd92e9c4f668e739d38b825ad15f
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 Nov 30, 2026.

Transparency log

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

Download URL mongol_norm-0.5.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 436.9 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
a975d8cffdf3a23809669894363f55d7e3d09d887b964bbcdc43506849b908c1
BLAKE2b-256 checksum
How to use checksums
45ce21d5e86109e620c88a45513bcedaac31726bdb9f87eae23283a60fc1bd24
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 Nov 30, 2026.

Transparency log

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

Download URL mongol_norm-0.5.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 433.6 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
8f62fc658ee9becf513ca786ed2df9554b0f6cf4e4d06f4a002195453f612be8
BLAKE2b-256 checksum
How to use checksums
f1455f8049b8f6bcddd30159c0f0de5ceb49c65583fa98d57158c44c6d6de3bb
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 Nov 30, 2026.

Transparency log

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

Download URL mongol_norm-0.5.0-cp39-abi3-macosx_11_0_arm64.whl
Size 398.3 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f70776f17f48aedd4668ce82bcba9679c0d955ce47969efcaf07dc74694ce6e9
BLAKE2b-256 checksum
How to use checksums
15592954491740a7964eb9b0d7776423d8f06fb20558c64fbbf4c0bcb66f8847
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 Nov 30, 2026.

Transparency log

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

Download URL mongol_norm-0.5.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 399.5 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
01f16fcd6522974d8a5064715dc21abffacffcbf65757a47049453d8ed5852bc
BLAKE2b-256 checksum
How to use checksums
db9694cdd844404b29de4ff4a22670b35c3c1eef9658d5e0b80fbcd0e654ba23
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 Nov 30, 2026.

Transparency log

Security for mongol-norm 0.5.0

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.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for mongol_norm-0.5.0.tar.gz

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 Nov 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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