Language-aware text normalisation for 22 Indian and several foreign languages
Project description
JT_script_normaliser
Language-aware text normalisation for the 22 scheduled Indian languages plus several foreign languages (English, Romanian, Portuguese, Vietnamese, Arabic).
It is built for ASR / speech pipelines: it canonicalises Unicode, strips or preserves punctuation and symbols depending on the mode, normalises digit scripts, and flags text that contains characters foreign to the chosen language.
Install
pip install JT_script_normaliser
Optional mojibake / encoding repair via ftfy:
pip install "JT_script_normaliser[ftfy]"
Quick start
from JT_script_normaliser import verbatim, verbatim_with_numbers, display
verbatim("नमस्ते, दुनिया!", "hindi")
# 'नमस्ते दुनिया'
verbatim_with_numbers("मेरे पास 5 आम", "hindi", number_script="native")
# 'मेरे पास ५ आम'
display("कीमत ₹1,00,000.50 है।", "hindi")
# 'कीमत ₹100000.50 है'
Modes
All modes apply a shared base: Unicode NFC, whitespace collapsing, removal of invisible formatting characters (BOM, bidi marks, ...), language-specific canonicalisation (e.g. Malayalam chillu folding), and a foreign-character gate (see below).
| Mode | Punctuation | Symbols (₹ % °) | Numbers |
|---|---|---|---|
verbatim |
removed | removed | removed (presence redacts) |
verbatim_with_numbers |
removed | removed | kept, normalised |
display |
removed | kept | kept, normalised |
verbatim(text, language, *, remove_zero_width=True, use_ftfy=False)
Spoken text only — punctuation, symbols and numbers are stripped, meaning preserved. If any number or foreign character remains, the whole input is redacted (see below).
verbatim_with_numbers(text, language, *, number_script="latin", remove_zero_width=True, use_ftfy=False)
Like verbatim, but numbers are kept and unified to one digit script.
A decimal point between two digits is kept (3.14); a grouping comma between
two digits is removed (1,00,000 -> 100000).
display(text, language, *, number_script="latin", remove_zero_width=True, use_ftfy=False)
Readable output for downstream/ASR consumers. Keeps numbers, decimals and essential symbols while removing ordinary punctuation:
- Always kept: currency (
$ ₹ €),° © ™ ®, and% ‰ ‱ @ # &. - Kept only next to a digit: math symbols (
+ − × ÷ = ± < > | ~) and the affixes: - / * ^(so5:30,-9,3/4,2*3are kept, buta-b,and/or,x = yare not). - Vulgar fractions are folded to ASCII:
½->1/2.
display("meet at 5:30, pay $5 + €3 = ¥8 - well-known", "english")
# 'meet at 5:30 pay $5 + €3 = ¥8 well known'
Options
| Option | Default | Values | Applies to |
|---|---|---|---|
language |
— (required) | name or alias / ISO code ("hindi", "hi") |
all |
number_script |
"latin" |
"latin", "native" |
numbers, display |
remove_zero_width |
True |
True, False |
all |
use_ftfy |
False |
True, False (needs [ftfy] extra) |
all |
number_script—"latin"renders all digits as0-9;"native"renders them in the language's script (e.g. Devanagari५, Tamil௫, Urdu۵). Both Latin and native input digits are unified to the target.remove_zero_width— ZWJ/ZWNJ are removed by default. SetFalseto preserve them (e.g. to keep Telugu vibhakti rendering). Lexically meaningful sequences (Malayalam chillu, Bengali khanda-ta) are folded to their atomic forms first, so they survive either way.use_ftfy— whenTrue, runsftfy.fix_textfirst to repair mojibake (e.g.हि...->हि...).
Foreign-character gate
After normalisation, any surviving character that is not a letter/mark of the
chosen language — a foreign letter, or any digit in verbatim mode — causes the
whole input to be returned as a redaction marker:
verbatim("नमस्ते hello", "hindi")
# 'REDACTED_FOREIGN_CHAR (h)'
verbatim_with_numbers("मेरे पास ৫ आम", "hindi") # Bengali digit in Hindi
# 'REDACTED_FOREIGN_CHAR (৫)'
Supported languages
from JT_script_normaliser import available_languages
available_languages()
Indian: assamese, bengali, bodo, bhojpuri, chhattisgarhi, dogri, gujarati, hindi, kannada, kashmiri, konkani, maithili, malayalam, manipuri (Meetei Mayek), marathi, nepali, odia, punjabi, sanskrit, santali, sindhi, tamil, telugu, urdu.
Foreign: english, romanian, portuguese, vietnamese, arabic.
Common aliases and ISO codes are accepted (hi, bn, ta, ur, en, ...).
Per-language canonicalisation
Beyond the base pipeline, some languages get script-specific fixes:
- Malayalam — legacy chillu (consonant + virama + ZWJ) folded to atomic
chillu (
ൻ ർ ൽ ...), so ZWJ removal doesn't corrupt them. - Bengali / Assamese — legacy khanda-ta folded to atomic
ৎ. - Urdu / Sindhi / Kashmiri / Arabic — presentation forms folded to base letters; tatweel (kashida) removed.
- Romanian — cedilla
ş ţfolded to comma-belowș ț.
License
MIT
Project details
Release history Release notifications | RSS feed
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 jt_script_normaliser-0.1.0.tar.gz.
File metadata
- Download URL: jt_script_normaliser-0.1.0.tar.gz
- Upload date:
- Size: 25.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57aa60ec42e7b4353f6e6fc1c7131f866d32741f71f450542f6a1e9f118f72ad
|
|
| MD5 |
accd091694e64fa6390da5209866619d
|
|
| BLAKE2b-256 |
7a510d1b965614cbf5a6b4702db76ee14698739401bfaeaf3f76d5c07f42263e
|
File details
Details for the file jt_script_normaliser-0.1.0-py3-none-any.whl.
File metadata
- Download URL: jt_script_normaliser-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
039852363ecaf3a057464f089a61f912d835702e6ce2d0d26a4263c76d8c72a3
|
|
| MD5 |
55cd5fc44b74d4a9704ded0359fcd732
|
|
| BLAKE2b-256 |
a763a0a7a89c834273f9097db5ea60ddc23ed1546f2f413788c9fcbfc11f6a8f
|