hmaraniam 🇲z
Zero-dependency language identification library for Hmar.
"Hmar a ni am?" — "Is it Hmar?"
hmaraniam is a lightweight, zero-dependency Python library that identifies Hmar text and cleanly distinguishes it from English and related Kuki-Chin / Zo languages (Mizo, Paite, Thadou, Vaiphei, Gangte, Zou).
Maintained by the Hmar Heritage Foundation as part of the Hmar Heritage Archival Project.
Features
- Fast dictionary lookups: Uses $O(1)$ set matching backed by 37,093 verified pure Hmar unigrams with no machine learning dependencies (PyTorch and TensorFlow free).
- Dual diacritic scoring: Reports
casual_hmar_ratio(ASCII-normalized for standard QWERTY typing) andformal_hmar_ratio(exact diacritic matches for formal text). - Specific Sibling Language Resolution: Distinguishes sibling Zo languages (
mizo,paite,thadou,gangte,zou,vaiphei) using dialect-exclusive particles and exclusive vocabulary sets. - Separate confidence scores: Separates overall classification confidence (
detected_language_confidence) from Hmar-specific confidence (hmar_confidence). - Consistent JSON output: Returns the same dictionary structure for every call, including word counts, sibling scores, and diacritic breakdowns.
- Custom unigrams & stopwords: Pass custom unigram sets, extra domain vocabulary, or custom stopword lists.
- Offline & CDN dataset loading: Syncs unigram sets via jsDelivr CDN with local disk caching and bundled offline fallbacks.
Design Principles
- Language ID vs. Spell Correction:
hmaraniammeasures vocabulary identity ("Is this text Hmar?"). It is not a spell checker and does not modify typos, character variants (acuteá, graveà, circumflexâ), or mobile keyboard codepoints (ṭvsţ). - ASCII Normalization (
casual_hmar_ratio): Mobile keyboards produce varying accent codepoints. Stripping diacritics (strip_diacritics) allows consistent vocabulary evaluation across devices. - 1-Token-Per-Row Boundaries: To evaluate hyphenated (
mithiem-hai), spaced (mithiem hai), or compound (mithiemhai) terms directly,hmaraniamaccepts 1-token-per-row inputs (JSON, CSV, TXT, Python lists) without re-tokenizing. - Vocabulary Identity vs. Grammar:
hmaraniammeasures dictionary presence and token overlap, not syntax or semantics. A random sequence of valid Hmar words yields a high vocabulary score regardless of grammatical structure.
Installation
pip install hmaraniam
Output Schema
{
"language": "hmar",
"hmar_confidence": 0.9842,
"detected_language_confidence": 0.9842,
"sibling_heuristic": false,
"mode": "basic",
"scores": {
"casual_hmar_ratio": 0.9524,
"formal_hmar_ratio": 0.8095,
"english_stopword_ratio": 0.0000,
"sibling_zo_stopword_ratio": 0.0000,
"unknown_words_ratio": 0.0476,
"total_words": 21,
"hmar_words_count": 20,
"non_hmar_words_count": 1,
"unknown_words_count": 1,
"english_stopwords_count": 0,
"sibling_zo_stopwords_count": 0,
"sibling_lang_scores": {},
"hmar_diacritic_words_count": 17,
"non_hmar_diacritic_words_count": 0,
"total_diacritic_words_count": 17
}
}
Usage
Quick Start
import hmaraniam
# Authentic text quote from L. Keivom archive (Coleman Factor, 2002)
sample_text = "Khawvel fe dan phung ei en chun, ram le hnam damna thuruk chu lien lema intel le insung khawm, zai khat le trong khata luong khawm a nih."
result = hmaraniam.detect(sample_text)
print(result)
1-Token-Per-Row Inputs
When token boundaries are pre-defined (such as distinguishing "mithiem-hai" vs "mithiem hai" vs "mithiemhai"), hmaraniam evaluates 1-token-per-row inputs without internal re-tokenization:
Expected File Formats & Code Examples
-
JSON Array File (
tokens.json):[ "khawvel", "fe", "dan", "mithiem-hai", "pathien", "hnenah" ]
Usage:
hmaraniam.detect("tokens.json")or CLIhmaraniam tokens.json -
CSV File (
tokens.csv):token khawvel fe dan mithiem-hai pathien hnenah
Usage:
hmaraniam.detect("tokens.csv")or CLIhmaraniam tokens.csv -
Line-Delimited TXT File (
tokens.txt- 1 word per line):khawvel fe dan mithiem-hai pathien hnenah
Usage:
hmaraniam.detect("tokens.txt")or CLIhmaraniam tokens.txt -
Python List (
List[str]):tokens = ["mithiem-hai", "pathien", "hnenah", "khawvel"] result = hmaraniam.detect(tokens)
Un-tokenized Raw Text Documents
For raw text files or strings (article.txt, raw text string, or stdin pipe), hmaraniam extracts word tokens using word-boundary regex matching:
# Raw text string evaluation
result = hmaraniam.detect("Khawvel fe dan phung ei en chun, ram le hnam damna thuruk...")
# Raw text article file evaluation
result = hmaraniam.detect("path/to/article.txt")
Custom Unigrams & Stopwords
from hmaraniam import Detector
# Provide custom unigrams or extra domain vocabulary
detector = Detector(
mode="basic",
extra_unigrams=["customworda", "customwordb"],
custom_stopwords=["and", "the", "with"],
disable_default_stopwords=False
)
result = detector.detect("Khawvel fe dan phung...")
Modes & Advanced Options
from hmaraniam import Detector
# Basic Mode (Default ~30k core unigrams)
basic_detector = Detector(mode="basic")
# High Mode (Loads extended unigram shards, falling back to basic if unavailable)
high_detector = Detector(mode="high")
# Offline-only mode (uses cached or bundled dataset without network calls)
offline_detector = Detector(offline_only=True)
Datasets & Repositories
- Hmar Unigrams Dataset (
unigrams): 58,983 verified Hmar surface words and active loanwords generated viahmaraniam's extraction pipeline. - Corpus Archive (
corpus-archive): Archival text corpus preserving Hmar literature and lexicons.
Error Handling
hmaraniam raises standard Python exceptions:
import hmaraniam
# Raises ValueError for unsupported modes
try:
hmaraniam.detect("Text", mode="ultra")
except ValueError as e:
print(e)
# Raises TypeError for non-string input
try:
hmaraniam.detect(12345)
except TypeError as e:
print(e)
License
Published under the MIT License by the Hmar Heritage Foundation.
Citation & Attribution
If you use this software in your research or tools, please cite:
@software{hmaraniam_2026,
author = {Hmar Heritage Foundation},
title = {hmaraniam: Zero-dependency language identification library for Hmar},
year = {2026},
publisher = {PyPI / GitHub},
iso_code = {hmr},
glottolog = {hmar1241},
clade = {Zo Languages},
howpublished = {\url{https://github.com/hmar-heritage-org/hmaraniam}}
}
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hmaraniam-0.1.7.tar.gz.
File metadata
- Download URL: hmaraniam-0.1.7.tar.gz
- Upload date:
- Size: 402.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b57e9113ba752b75ec21c3dbbbfbdb64b96dea664f89fdc07b38888c7a6d5772
|
|
| MD5 |
afb9a8ec378c12c02e10b14a0bdc49b7
|
|
| BLAKE2b-256 |
3bffe34dce021b1fb8c954a6162ac33a3fc5e4cfda8e9b8488781a26d51a3d61
|
File details
Details for the file hmaraniam-0.1.7-py3-none-any.whl.
File metadata
- Download URL: hmaraniam-0.1.7-py3-none-any.whl
- Upload date:
- Size: 398.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f21bb57349a0665fc0fa7d70578c714bfccdc5f031e9e50b8dac2975030ef4e0
|
|
| MD5 |
23137f40a5b58a1029b5e87ae1834eb8
|
|
| BLAKE2b-256 |
d38b841c2c054f5ddac327be4dba9c14d835e13831a634f6bf6bc0db5dd7f575
|