Skip to main content

Dictionary based predictive Roman Urdu transliterator

Project description

RomanAlfaz (رومن الفاظ)

RomanAlfaz is a dictionary-based, predictive transliterator that converts roman-script Urdu words into their arabic-script equivalents. It automatically ranks and prioritizes matching suggestions based on their real-world usage frequency.

How it Works

The tool processes text using a specialized two-layer transformation workflow:

  1. Intermediate Representation: It leverages the rule-based transliteration algorithm proposed by Tafseer Ahmed. This converts the user's Roman Urdu input into an intermediate format designed to bridge the phonetic and structural spelling gaps between the two scripts.
  2. Dictionary Lookup: The engine passes this intermediate form to SymSpellPy to execute an optimized dictionary search against a precompiled vocabulary list.

Baseline Vocabulary

The baseline included dictionary is built upon the CLE Urdu 5000 words dataset, which captures the most frequently used words in the Urdu language.

Core Workflow

Using RomanAlfaz follows a simple three-step process:

  1. Load: Load a preconfigured arabic-script Urdu vocabulary and corresponding usage frequency.
  2. Input: Provide a roman-script Urdu word.
  3. Output: Receive a ranked list of predicted arabic-script suggestions.
RomanAlfaz Core Workflow

Documentation

The latest full documentation, installation guide, and API reference is available online.

Installation

You can install romanalfaz directly from PyPI using pip.

Standard Installation

Run the following command in your terminal:

pip install romanalfaz

Recommended: Using a Virtual Environment

It is highly recommended to install Python packages inside a virtual environment to prevent dependency conflicts with your global system packages.

On macOS/Linux:

# Create a virtual environment
python3 -m venv venv

# Activate the virtual environment
source venv/bin/activate

# Install the package
pip install romanalfaz

On Windows:

# Create a virtual environment
python -m venv venv

# Activate the virtual environment
venv\Scripts\activate

# Install the package
pip install romanalfaz

Adding to Project Dependencies

If you are using romanalfaz as part of a larger project, you can add it to your dependency tracking files:

  • requirements.txt: Add romanalfaz to your file, then install using:
    pip install -r requirements.txt
    
  • Poetry:
    poetry add romanalfaz
    
  • uv:
    uv add romanalfaz
    

Usage

The romanalfaz package provides the RomanAlfaz class as a centralized, easy-to-use interface for text transliterations.

Initialization and Input

  • Built-in Vocabulary: Instantiating the class automatically loads the include baseline, 5000-word vocabulary.
  • Word-Level Inputs: The RomanAlfaz.suggest() function processes single words only. It is your responsibility to tokenize sentences or larger paragraphs into individual words before passing them to the function.

Outputs and Edit Distance

The RomanAlfaz.suggest() function always returns a 3-tuple representing three matching tiers:

  1. Exact Matches,
  2. One-Edit Distance Matches, and
  3. Two-Edit Distance Matches

The distance parameter determines the maximum search depth. The function will always include the lowest tiers as well and return results across all matching levels up to your configured limit.

Interactive Examples

You can test the core functions interactively inside a Python shell. Open your terminal, run python, and follow the examples below:

>>> from romanalfaz import RomanAlfaz

>>> ra = RomanAlfaz()

>>> rmWord = "kitab"
>>> # As distance is 0, received empty one and two-edit tier lists can be discarded.
>>> suggestions, _, _ = ra.suggest(rmWord, distance=0)
>>> # Take the first suggestion (if any) and use its arabic scripted word
>>> arWord = suggestions[0].arabic if suggestions else ''
>>> arWord
'کتاب'

>>> for w in 'kya haal he'.split():
...    d0, d1, d2 = ra.suggest(w, distance=2)
...    # Formated dump of the suggestions 
...    print(f"'{w}' ->")
...    print('  Exact matches:')
...    for item in d0:
...        print(f"    {item!r}")
...    print('  One-Edit matches:')
...    for item in d1:
...        print(f"    {item!r}")
...    print('  Two-Edit matches:')
...    for item in d2:
...        print(f"    {item!r}")
...
'kya' ->
  Exact matches:
    Suggestion(arabic='کیا', encodedRoman='KYA', frequency=108414)
  One-Edit matches:
    Suggestion(arabic='کی', encodedRoman='KY', frequency=575545)
    Suggestion(arabic='کہ', encodedRoman='KH', frequency=237419)
    Suggestion(arabic='یہ', encodedRoman='YH', frequency=128103)
    Suggestion(arabic='کیا', encodedRoman='KYA', frequency=108414)
    Suggestion(arabic='کئے', encodedRoman='KYE', frequency=14970)
    Suggestion(arabic='کیے', encodedRoman='KYE', frequency=4976)
  Two-Edit matches:
'haal' ->
  Exact matches:
    Suggestion(arabic='حال', encodedRoman='HAL', frequency=4893)
    Suggestion(arabic='ہال', encodedRoman='HAL', frequency=936)
    Suggestion(arabic='حائل', encodedRoman='HAYL', frequency=316)
  One-Edit matches:
    Suggestion(arabic='حاصل', encodedRoman='HASL', frequency=25881)
    Suggestion(arabic='حال', encodedRoman='HAL', frequency=4893)
    Suggestion(arabic='حامل', encodedRoman='HAML', frequency=2227)
    Suggestion(arabic='آل', encodedRoman='AAL', frequency=1014)
    Suggestion(arabic='ہال', encodedRoman='HAL', frequency=936)
    Suggestion(arabic='فعال', encodedRoman='FAAL', frequency=718)
  Two-Edit matches:
    Suggestion(arabic='حاصل', encodedRoman='HASL', frequency=25881)
    Suggestion(arabic='حالات', encodedRoman='HALAT', frequency=6537)
    Suggestion(arabic='حال', encodedRoman='HAL', frequency=4893)
    Suggestion(arabic='حامل', encodedRoman='HAML', frequency=2227)
    Suggestion(arabic='آل', encodedRoman='AAL', frequency=1014)
    Suggestion(arabic='ہال', encodedRoman='HAL', frequency=936)
'he' ->
  Exact matches:
    Suggestion(arabic='ہے', encodedRoman='HE', frequency=466908)
  One-Edit matches:
  Two-Edit matches:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

romanalfaz-0.1.0a2.tar.gz (62.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

romanalfaz-0.1.0a2-py3-none-any.whl (62.8 kB view details)

Uploaded Python 3

File details

Details for the file romanalfaz-0.1.0a2.tar.gz.

File metadata

  • Download URL: romanalfaz-0.1.0a2.tar.gz
  • Upload date:
  • Size: 62.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for romanalfaz-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 21b220b79e88dadf3e7c71e2fa780cd743ea59fc3734f7882e14e32256d8cefe
MD5 31b7f56d73a1e3be6825e309b1dc0fba
BLAKE2b-256 9c03a1658e05884e7577d8571a647b872975e4c4a0ab9cfb8571828e1bc97aa8

See more details on using hashes here.

File details

Details for the file romanalfaz-0.1.0a2-py3-none-any.whl.

File metadata

  • Download URL: romanalfaz-0.1.0a2-py3-none-any.whl
  • Upload date:
  • Size: 62.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for romanalfaz-0.1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 12097946871cebe687af1739ae0d092c1f0316dba646f838a1587da6d291b797
MD5 07dc3db7e92502f8801de1e63ee2a027
BLAKE2b-256 0bcf7b1cdc6cc6f9b73b3c5046a5406bdfff162fd3314cb52dc85562f64d2e11

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page