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 is not yet in the form people usually type: it is an FVS-pinned spelling of the written units (e.g. ᠮᠣᠩᠭᠣᠯ → ᠮᠣᠠᠭ᠌ᠨ᠋ᠨ᠋ᠣᠯ), and it may change in a later release. 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 的输出目前不符合常见的字符序列: 它是按书写单元钉死 FVS 的拼法(例如 ᠮᠣᠩᠭᠣᠯ → ᠮᠣᠠᠭ᠌ᠨ᠋ᠨ᠋ᠣᠯ),后续版本有可能修改。如果要持久化规范化后的 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.2

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.2
File Size Uploaded
mongol_norm-0.2.2.tar.gz 98.1 kB Details

Built distributions (wheels)

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

Download URL mongol_norm-0.2.2.tar.gz
Size 98.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fd6f6bf02d094efd1dac2cdc3075333e459a777889de701cd73fde22c95b90fb
BLAKE2b-256 checksum
How to use checksums
4074d15cad3fb3d193791e4983b9ac047a97fed15811735e64bf6b68355ac6cd
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.2-cp39-abi3-win_amd64.whl

Download URL mongol_norm-0.2.2-cp39-abi3-win_amd64.whl
Size 271.5 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
03b478e91474b16b27373bb23c4616450f8d0da09def4d146ec940a20738f72c
BLAKE2b-256 checksum
How to use checksums
d2624f44826cb1a1bb3cd710fe61a0691cd36ecd958c560a53422c1b0fb3049d
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.2-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL mongol_norm-0.2.2-cp39-abi3-musllinux_1_2_x86_64.whl
Size 637.8 kB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
9d1bbf254fc02569efdacc0abf4065b94f93cef9ed73c4b87873cf50d786f5cf
BLAKE2b-256 checksum
How to use checksums
637685a60ed23fcba1a7531cb86d59ead9cf549b8936ff3acfa2a45ef00551b7
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.2-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL mongol_norm-0.2.2-cp39-abi3-musllinux_1_2_aarch64.whl
Size 601.1 kB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
f426dc8791dc77524ffc1693136df6c48e38089e5c6e12b829680a0f6b6601c5
BLAKE2b-256 checksum
How to use checksums
e05a9196ed0831b95d31564826c74858d45268fcdd2c896316058e422c25b666
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.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mongol_norm-0.2.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 428.0 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
8cf4af8b806ed347979b6e3d8082714e36884475a3e5d4c2ac0ca1051c622d91
BLAKE2b-256 checksum
How to use checksums
bb152def07910e85a6f30f688132a4c8080f69629b0377d54f92b45a8c1ec574
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.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL mongol_norm-0.2.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 423.4 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
5f6fa406e7bd8229812a6fadd66e2c103f660e21effdd14e0c235fe70463122b
BLAKE2b-256 checksum
How to use checksums
078cf292502472f16759cb77b9f4f38bf8155260b723f3d5e14f8fff15178ef8
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.2-cp39-abi3-macosx_11_0_arm64.whl

Download URL mongol_norm-0.2.2-cp39-abi3-macosx_11_0_arm64.whl
Size 385.1 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ed91c7daa7cff91ff2426fc8fe25c3cf82994f1f8ec669a38059fb34c57bf576
BLAKE2b-256 checksum
How to use checksums
f22a228631064d60f831c1951d1a0bd9d4e82cb9f10f8a594d470faa2d41ced9
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.2-cp39-abi3-macosx_10_12_x86_64.whl

Download URL mongol_norm-0.2.2-cp39-abi3-macosx_10_12_x86_64.whl
Size 388.0 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c0c65102bc09a69819904816fcdba5b113d541be19f171ae8f3befd2010c1bc2
BLAKE2b-256 checksum
How to use checksums
f405e1003b634f0c005afe775d7823f1cc988a1e8badfa730dc4b0a55761db7e
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

0.2.3

8 release files

This release

0.2.2 This release

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