Canonicalization and Darija Representation - Bidirectional transliteration for Darija
Project description
CaDaR: Canonicalization and Darija Representation
Overview
CaDaR is a robust, FST-style (Finite State Transducer) transliteration library designed specifically for Darija (Moroccan Arabic). It provides bidirectional conversion between Arabic script and Latin (Romanized/Bizi) script, along with standardization capabilities for both scripts.
Key Features
- Bidirectional Transliteration: Convert seamlessly between Arabic and Latin scripts
- Intelligent Normalization: Handles noise, diacritics, and common variations
- Darija-Aware Processing: Respects Darija-specific linguistic patterns
- Intermediate Canonical Representation (ICR): Unified internal representation for accurate conversion
- High Performance: Written in Rust with Python bindings for optimal speed
- Extensible: Designed to support multiple Darija dialects (currently Moroccan)
Architecture
CaDaR uses a 6-stage pipeline with an Intermediate Canonical Representation (ICR):
Raw Input
↓
Stage 1: Script Detection
↓
Stage 2: Noise Cleaning & Normalization
↓
Stage 3: Tokenization (Darija-aware)
↓
Stage 4: Canonical Darija Representation (ICR)
↓
Stage 5: Target Script Generation
↓
Stage 6: Post-validation & Fixes
↓
Clean Standard Output
What is ICR?
The Intermediate Canonical Representation (ICR) is the core innovation of CaDaR. It's a script-independent, phonologically-grounded representation that:
- Abstracts away script-specific quirks
- Preserves Darija phonological distinctions
- Enables lossless round-trip conversions
- Allows for consistent normalization across scripts
Installation
From PyPI (Coming Soon)
pip install cadar
From Source
Prerequisites
- Python 3.8 or higher
- Rust toolchain (for building from source)
- Maturin (for Python packaging)
Build and Install
# Clone the repository
git clone https://github.com/Oit-Technologies/CaDaR.git
cd CaDaR
# Install Maturin
pip install maturin
# Build and install in development mode
maturin develop
# Or build a wheel for distribution
maturin build --release
Usage
Python API
CaDaR provides four main functions that match the requested API:
1. ara2bizi() - Arabic to Latin/Bizi
import cadar
# Convert Arabic script to Latin (Bizi)
result = cadar.ara2bizi("كيفاش داير؟", darija="Ma")
print(result) # Output: "kifash dayer?"
2. bizi2ara() - Latin/Bizi to Arabic
import cadar
# Convert Latin script to Arabic
result = cadar.bizi2ara("salam 3likom", darija="Ma")
print(result) # Output: "سلام عليكم"
3. ara2ara() - Arabic Standardization
import cadar
# Standardize Arabic text (remove diacritics, normalize characters)
result = cadar.ara2ara("أنَا مِنْ المَغْرِب", darija="Ma")
print(result) # Output: "انا من المغرب"
4. bizi2bizi() - Latin Standardization
import cadar
# Standardize Latin text (fix repeated chars, normalize spelling)
result = cadar.bizi2bizi("salaaaam kifaaash", darija="Ma")
print(result) # Output: "salam kifash"
Using the CaDaR Class
For processing multiple texts with the same dialect, create a CaDaR instance:
import cadar
# Create a processor for Moroccan Darija
processor = cadar.CaDaR(darija="Ma")
# Use the methods
arabic_text = processor.bizi2ara("wakha ghir shwiya")
latin_text = processor.ara2bizi("واخا غير شوية")
standardized = processor.ara2ara("أنَا كَنْتْكَلَّم دَارِيجَة")
print(f"Dialect: {processor.get_dialect()}")
Convenience Functions
import cadar
# Auto-detect and transliterate
result = cadar.transliterate("سلام", target="latin", darija="Ma")
# Auto-detect and standardize
result = cadar.standardize("salaaaam", script="auto", darija="Ma")
Examples
Common Darija Phrases
import cadar
phrases = [
"كيفاش داير؟", # How are you?
"بخير الحمد لله", # Fine, thank God
"شنو كدير؟", # What are you doing?
"غير كنقرا", # Just studying
"واخا نمشيو", # Let's go
]
for phrase in phrases:
latin = cadar.ara2bizi(phrase, darija="Ma")
print(f"{phrase} → {latin}")
Working with Mixed Text
import cadar
# CaDaR handles mixed scripts gracefully
text = "ana men Morocco و نتكلم darija bzaf"
# Process each part appropriately
standardized = cadar.standardize(text, script="auto")
Batch Processing
import cadar
processor = cadar.CaDaR(darija="Ma")
texts = ["سلام", "بسلامة", "شكرا", "بزاف"]
results = [processor.ara2bizi(text) for text in texts]
print(results) # ['slam', 'bslama', 'shokran', 'bzaf']
Supported Dialects
Currently supported:
- Ma (Moroccan Darija) - Default
Planned for future releases:
- Algerian Darija
- Tunisian Darija
- Libyan Darija
- Egyptian Darija
Technical Details
Script Detection
CaDaR automatically detects the input script (Arabic, Latin, Mixed) and processes accordingly.
Normalization
- Arabic: Removes diacritics, normalizes Alef variants, handles Teh Marbuta
- Latin: Normalizes common Darija Latin representations (3 → ع, 7 → ح, 9 → ق)
Darija-Specific Features
- Recognition of Darija function words (من، في، ديال)
- Handling of Darija-specific constructs (بزاف، غير، واخا)
- Clitic splitting (prefixes like و، ف، ب، ل)
ICR Phoneme Mapping
The ICR uses a standardized set of symbols:
| Arabic | Latin | ICR | Description |
|---|---|---|---|
| ا | a | A | Alef |
| ب | b | B | Ba |
| ت | t | T | Ta |
| ع | 3 | ε | Ain |
| ح | 7 | Ḥ | Strong H |
| خ | kh | X | Kha |
| ش | sh | Š | Shin |
| غ | gh | Ġ | Ghain |
Development
Running Tests
# Rust tests
cargo test
# Python tests (after installation)
pytest tests/
Building Documentation
# Rust documentation
cargo doc --open
# Python documentation
cd docs && make html
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Performance
CaDaR is built in Rust for high performance:
- Transliteration: ~1-2ms per sentence
- Batch processing: Scales linearly
- Memory efficient: Minimal allocations
Roadmap
- Add support for more Darija dialects
- Implement advanced morphological analysis
- Create web API
- Add CLI tool
- Improve ICR with machine learning enhancements
- Build browser-based demo
License
This project is licensed under the MIT License - see the LICENSE file for details.
Citation
If you use CaDaR in your research, please cite:
@software{cadar2024,
title={CaDaR: Canonicalization and Darija Representation},
author={Oit Technologies},
year={2024},
url={https://github.com/Oit-Technologies/CaDaR}
}
Acknowledgments
Contact
- Organization: Oit Technologies
- Repository: https://github.com/Oit-Technologies/CaDaR
- Issues: https://github.com/Oit-Technologies/CaDaR/issues
Made with ❤️ for the Darija community
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 Distributions
Built Distributions
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 cadar-0.1.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: cadar-0.1.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 842.5 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7260e2b3a37619f29f21ddb78ccfc6edf413b07219f76bea84dbd46fc87a325
|
|
| MD5 |
7f1a9b13a40a9674f27bc2afb3a602ab
|
|
| BLAKE2b-256 |
d63af25d49b73d3b0898b817e353feb5cfc21da94d64aabdff5ad826b088f4a2
|
File details
Details for the file cadar-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: cadar-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 830.3 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e661ad8bd9e9e35068833282436b851cfceb7c6a943505992ba2d848c7ef6ad5
|
|
| MD5 |
77b2f871901e893711d66d11b107d74d
|
|
| BLAKE2b-256 |
a522c518f51daa2a4c0bb727126a69386e129d5e8380fea4cf02fcc3a4dcf97c
|
File details
Details for the file cadar-0.1.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: cadar-0.1.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 842.9 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3344b4c98c7571e280eae00cf18e7c5428db38c15da5c65c9e56aa0695451e9a
|
|
| MD5 |
579700120d059af52bf7be83b36bbabd
|
|
| BLAKE2b-256 |
4bc34636a02e155da525b29ee82f41d277d2528db4d89d284d21d94cd997c302
|
File details
Details for the file cadar-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: cadar-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 830.8 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6aa907056267debf8afce70ceee9c371a914ad5762b59b37693d17a4f374e725
|
|
| MD5 |
716836d4e4ea812b64ed491b83db96fa
|
|
| BLAKE2b-256 |
ccfbe0a943b3515b1b7f1af6aadd4e8606cca99b92777aa3aa1f75c2a512f12c
|
File details
Details for the file cadar-0.1.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: cadar-0.1.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 842.9 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4331bf1260dee9b2ff65f2047f6b65d21195a291d108dd776c3194e21314eea
|
|
| MD5 |
5033f4cefccfd6a681f2e0d452cdd13b
|
|
| BLAKE2b-256 |
53c5bd14bd171e56a55aceded96d22977c8cd56b118c87e4dbddd5f28636dab9
|
File details
Details for the file cadar-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: cadar-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 830.6 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6742771d5e8a2f26b735f5396d9d3585d2f86efed51b9a41c47adbf9429d763e
|
|
| MD5 |
28b5792127a1e9817a9cb8f1070b2e90
|
|
| BLAKE2b-256 |
75295710341c999698f303f5991826084d62635cff7fe96edecdb51ce04e2944
|
File details
Details for the file cadar-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: cadar-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 972.5 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4552481b359bc14a195758d44e78222737b18633ba84fc07dd7e7714fd05cc8d
|
|
| MD5 |
beb3fda104f65bf1d06610332631e1ef
|
|
| BLAKE2b-256 |
4744f96bf58623d814c08a53e1bbb8376ce4e2b713865708da4637fff3020f87
|