nepali_unicoder 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nepali_unicoder-0.2.0/LICENSE +21 -0
- nepali_unicoder-0.2.0/MANIFEST.in +2 -0
- nepali_unicoder-0.2.0/PKG-INFO +210 -0
- nepali_unicoder-0.2.0/README.md +188 -0
- nepali_unicoder-0.2.0/pyproject.toml +45 -0
- nepali_unicoder-0.2.0/setup.cfg +4 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder/__init__.py +3 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder/__main__.py +41 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder/convert.py +13 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder/data/preeti_rules.json +226 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder/data/roman_rules.json +112 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder/data/word_maps.json +67 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder/engine.py +107 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder/loader.py +120 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder/rules.py +2 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder/tokenizer.py +93 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder/trie.py +53 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder.egg-info/PKG-INFO +210 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder.egg-info/SOURCES.txt +23 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder.egg-info/dependency_links.txt +1 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder.egg-info/entry_points.txt +2 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder.egg-info/requires.txt +5 -0
- nepali_unicoder-0.2.0/src/nepali_unicoder.egg-info/top_level.txt +1 -0
- nepali_unicoder-0.2.0/tests/test_components.py +141 -0
- nepali_unicoder-0.2.0/tests/test_conversion.py +255 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 RealSanjeev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nepali_unicoder
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A Python package for Roman to Nepali (Devanagari) transliteration
|
|
5
|
+
Author-email: realsanjeev <075bei033.sanjeev@pcampus.edu.np>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/realsanjeev/nepali_unicoder
|
|
8
|
+
Project-URL: Documentation, https://realsanjeev.github.io/nepali_unicoder/
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/realsanjeev/nepali_unicoder/issues
|
|
10
|
+
Keywords: nepali,unicoder,roman to devanagari,nepali transliteration,preeti to unicode
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.7
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
19
|
+
Requires-Dist: mkdocs; extra == "dev"
|
|
20
|
+
Requires-Dist: mkdocs-material; extra == "dev"
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# Nepali Unicoder
|
|
24
|
+
|
|
25
|
+
[](https://realsanjeev.github.io/nepali_unicoder/)
|
|
26
|
+
[](https://pypi.org/project/nepali-unicoder/)
|
|
27
|
+
|
|
28
|
+
A robust Python package for converting Romanized Nepali text and Preeti font text into Unicode Devanagari script. It uses a greedy matching algorithm for Roman transliteration and a two-phase conversion process for Preeti with contextual rules.
|
|
29
|
+
|
|
30
|
+
Read the **[Full Documentation](https://realsanjeev.github.io/nepali_unicoder/)** for detailed usage guides, Preeti mapping references, and API details.
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- **Accurate Transliteration**: Uses a greedy matching algorithm to prioritize longer phonetic matches (e.g., 'kha' is matched before 'k' and 'h').
|
|
35
|
+
- **Preeti Font Support**: Full support for Preeti to Unicode conversion with 30+ contextual rules for accurate transformation.
|
|
36
|
+
- **Smart Vowel Handling**: Distinguishes between independent vowels (e.g., 'aa' -> 'आ') and vowel signs/matras (e.g., 'ka' -> 'क', 'kaa' -> 'का').
|
|
37
|
+
- **Contextual Rules**: Handles complex Devanagari rules like reph positioning, matra reordering, and special character combinations.
|
|
38
|
+
- **Mixed Content Support**: Allows keeping English words or specific text in Roman script using `{}` blocks.
|
|
39
|
+
- **Customizable**: Supports custom word-level overrides via `word_maps.json`.
|
|
40
|
+
- **CLI Support**: Can be used directly from the command line.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
You can install the package locally:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install nepali-unicoder
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
### Command Line Interface (CLI)
|
|
53
|
+
|
|
54
|
+
You can use the converter directly from the terminal:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Using the installed command
|
|
58
|
+
nepali-unicoder "namaste"
|
|
59
|
+
# Output: नमस्ते
|
|
60
|
+
|
|
61
|
+
# Or using python module
|
|
62
|
+
python -m nepali_unicoder "namaste"
|
|
63
|
+
# Output: नमस्ते
|
|
64
|
+
|
|
65
|
+
# Pipe input
|
|
66
|
+
echo "mero naam sanjeev ho" | nepali-unicoder
|
|
67
|
+
# Output: मेरो नाम् सन्जीव् हो
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Python API
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from nepali_unicoder.convert import Converter
|
|
74
|
+
|
|
75
|
+
converter = Converter()
|
|
76
|
+
|
|
77
|
+
# Basic conversion
|
|
78
|
+
text = "namaste nepal"
|
|
79
|
+
print(converter.convert(text))
|
|
80
|
+
# Output: नमस्ते नेपाल
|
|
81
|
+
|
|
82
|
+
# Using 'as-is' blocks for English text
|
|
83
|
+
mixed_text = "mero naam {Sanjeev} ho"
|
|
84
|
+
print(converter.convert(mixed_text))
|
|
85
|
+
# Output: मेरो नाम् Sanjeev हो
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Preeti Mode
|
|
89
|
+
|
|
90
|
+
Convert Preeti font text to Unicode with full support for contextual rules:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from nepali_unicoder.convert import Converter
|
|
94
|
+
|
|
95
|
+
# Create converter in Preeti mode
|
|
96
|
+
preeti_converter = Converter(mode="preeti")
|
|
97
|
+
|
|
98
|
+
# Basic conversion
|
|
99
|
+
preeti_text = "s{sf" # Preeti characters
|
|
100
|
+
print(preeti_converter.convert(preeti_text))
|
|
101
|
+
# Output: र्कका
|
|
102
|
+
|
|
103
|
+
# The converter handles:
|
|
104
|
+
# - Reph positioning: { → र् (moves before consonant)
|
|
105
|
+
# - Matra reordering: l (ि) moves after consonant
|
|
106
|
+
# - Special m transformations
|
|
107
|
+
# - Vowel combinations
|
|
108
|
+
# - Literal brackets: { and } are treated as normal characters in Preeti mode
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Preeti Character Examples
|
|
112
|
+
|
|
113
|
+
| Preeti | Unicode | Description |
|
|
114
|
+
|--------|---------|-------------|
|
|
115
|
+
| `s` | `क` | Consonant ka |
|
|
116
|
+
| `s{` | `र्क` | Reph + ka (contextual) |
|
|
117
|
+
| `sl` | `कि` | ka + short i (reordered) |
|
|
118
|
+
| `qm` | `क्र` | Special m transformation |
|
|
119
|
+
| `!@#` | `१२३` | Nepali numbers |
|
|
120
|
+
| `Ù` / `Ú` | `;` / `:` | Literal punctuation |
|
|
121
|
+
| `«` / `»` | `्र` | Ra-foot (for ट, ठ, ड, ढ) |
|
|
122
|
+
| `¿` | `रू` | Combined ruu |
|
|
123
|
+
| `å` | `द्व` | Combined dva |
|
|
124
|
+
| `ˆ` | `फ्` | Half ph |
|
|
125
|
+
| `ª` | `ङ` | Consonant nga |
|
|
126
|
+
| `æ` / `Æ` | `“` / `”` | Curly quotes |
|
|
127
|
+
| `¥` | `र्` | Half ra |
|
|
128
|
+
| `¶` | `ठ्ठ` | Combined thth |
|
|
129
|
+
| `§` | `ट्ट` | Combined tt |
|
|
130
|
+
| `£` | `घ्` | Half gh |
|
|
131
|
+
| `Ë` / `Í` | `ङ्ग` / `ङ्क` | Combined nga-ga / nga-ka |
|
|
132
|
+
| `‰` | `झ्` | Half jh |
|
|
133
|
+
|
|
134
|
+
#### CLI for Preeti
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
python -m nepali_unicoder --preeti "s{sf"
|
|
138
|
+
# Output: र्कका
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
## Transliteration Rules
|
|
143
|
+
|
|
144
|
+
- **Consonants**: `k` -> `क्`, `ka` -> `क`, `kh` -> `ख्`, `kha` -> `ख`
|
|
145
|
+
- **Vowels**: `a` -> `अ`, `aa` -> `आ`, `i` -> `इ`, `u` -> `उ`
|
|
146
|
+
- **Matras**: `ki` -> `कि`, `ko` -> `को`
|
|
147
|
+
- **Special**: `.` -> `।`, `..` -> `॥`
|
|
148
|
+
- **Numbers**: `0-9` -> `०-९` (Decimal points are preserved: `1.5` -> `१.५`)
|
|
149
|
+
|
|
150
|
+
## Advanced Usage
|
|
151
|
+
|
|
152
|
+
### Handling Complex Text
|
|
153
|
+
|
|
154
|
+
The converter handles mixed content gracefully. You can use `{}` to keep text as-is (e.g., for English words or code snippets).
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
text = "mero naam {Sanjeev} ho ra ma 12.5 barsa ko bhaye."
|
|
158
|
+
print(converter.convert(text))
|
|
159
|
+
# Output: मेरो नाम् Sanjeev हो र म १२.५ बर्स को भये।
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Configuration
|
|
163
|
+
|
|
164
|
+
The package uses `word_maps.json` for custom word-level overrides, located in the `src/nepali_unicoder` directory.
|
|
165
|
+
|
|
166
|
+
1. **`word_maps.json`**: Defines custom word-level overrides. Use this for words that don't follow standard phonetic rules.
|
|
167
|
+
|
|
168
|
+
Example `word_maps.json`:
|
|
169
|
+
```json
|
|
170
|
+
{
|
|
171
|
+
"nepal": "नेपाल",
|
|
172
|
+
"kathamandu": "काठमाडौँ"
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Contribution
|
|
177
|
+
|
|
178
|
+
We welcome contributions! Here's how you can help:
|
|
179
|
+
|
|
180
|
+
1. **Clone the repository**:
|
|
181
|
+
```bash
|
|
182
|
+
git clone https://github.com/realsanjeev/nepali_unicoder.git
|
|
183
|
+
cd nepali_unicoder
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
2. **Set up a virtual environment**:
|
|
187
|
+
```bash
|
|
188
|
+
python3 -m venv .venv
|
|
189
|
+
source .venv/bin/activate
|
|
190
|
+
pip install -e .
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
3. **Run tests**:
|
|
194
|
+
```bash
|
|
195
|
+
python -m unittest discover tests
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
4. **Submit a Pull Request**: Create a new branch, make your changes, and submit a PR.
|
|
199
|
+
|
|
200
|
+
## Development
|
|
201
|
+
|
|
202
|
+
To run tests:
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
python -m unittest discover tests
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# Nepali Unicoder
|
|
2
|
+
|
|
3
|
+
[](https://realsanjeev.github.io/nepali_unicoder/)
|
|
4
|
+
[](https://pypi.org/project/nepali-unicoder/)
|
|
5
|
+
|
|
6
|
+
A robust Python package for converting Romanized Nepali text and Preeti font text into Unicode Devanagari script. It uses a greedy matching algorithm for Roman transliteration and a two-phase conversion process for Preeti with contextual rules.
|
|
7
|
+
|
|
8
|
+
Read the **[Full Documentation](https://realsanjeev.github.io/nepali_unicoder/)** for detailed usage guides, Preeti mapping references, and API details.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Accurate Transliteration**: Uses a greedy matching algorithm to prioritize longer phonetic matches (e.g., 'kha' is matched before 'k' and 'h').
|
|
13
|
+
- **Preeti Font Support**: Full support for Preeti to Unicode conversion with 30+ contextual rules for accurate transformation.
|
|
14
|
+
- **Smart Vowel Handling**: Distinguishes between independent vowels (e.g., 'aa' -> 'आ') and vowel signs/matras (e.g., 'ka' -> 'क', 'kaa' -> 'का').
|
|
15
|
+
- **Contextual Rules**: Handles complex Devanagari rules like reph positioning, matra reordering, and special character combinations.
|
|
16
|
+
- **Mixed Content Support**: Allows keeping English words or specific text in Roman script using `{}` blocks.
|
|
17
|
+
- **Customizable**: Supports custom word-level overrides via `word_maps.json`.
|
|
18
|
+
- **CLI Support**: Can be used directly from the command line.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
You can install the package locally:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install nepali-unicoder
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### Command Line Interface (CLI)
|
|
31
|
+
|
|
32
|
+
You can use the converter directly from the terminal:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Using the installed command
|
|
36
|
+
nepali-unicoder "namaste"
|
|
37
|
+
# Output: नमस्ते
|
|
38
|
+
|
|
39
|
+
# Or using python module
|
|
40
|
+
python -m nepali_unicoder "namaste"
|
|
41
|
+
# Output: नमस्ते
|
|
42
|
+
|
|
43
|
+
# Pipe input
|
|
44
|
+
echo "mero naam sanjeev ho" | nepali-unicoder
|
|
45
|
+
# Output: मेरो नाम् सन्जीव् हो
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Python API
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from nepali_unicoder.convert import Converter
|
|
52
|
+
|
|
53
|
+
converter = Converter()
|
|
54
|
+
|
|
55
|
+
# Basic conversion
|
|
56
|
+
text = "namaste nepal"
|
|
57
|
+
print(converter.convert(text))
|
|
58
|
+
# Output: नमस्ते नेपाल
|
|
59
|
+
|
|
60
|
+
# Using 'as-is' blocks for English text
|
|
61
|
+
mixed_text = "mero naam {Sanjeev} ho"
|
|
62
|
+
print(converter.convert(mixed_text))
|
|
63
|
+
# Output: मेरो नाम् Sanjeev हो
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Preeti Mode
|
|
67
|
+
|
|
68
|
+
Convert Preeti font text to Unicode with full support for contextual rules:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from nepali_unicoder.convert import Converter
|
|
72
|
+
|
|
73
|
+
# Create converter in Preeti mode
|
|
74
|
+
preeti_converter = Converter(mode="preeti")
|
|
75
|
+
|
|
76
|
+
# Basic conversion
|
|
77
|
+
preeti_text = "s{sf" # Preeti characters
|
|
78
|
+
print(preeti_converter.convert(preeti_text))
|
|
79
|
+
# Output: र्कका
|
|
80
|
+
|
|
81
|
+
# The converter handles:
|
|
82
|
+
# - Reph positioning: { → र् (moves before consonant)
|
|
83
|
+
# - Matra reordering: l (ि) moves after consonant
|
|
84
|
+
# - Special m transformations
|
|
85
|
+
# - Vowel combinations
|
|
86
|
+
# - Literal brackets: { and } are treated as normal characters in Preeti mode
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Preeti Character Examples
|
|
90
|
+
|
|
91
|
+
| Preeti | Unicode | Description |
|
|
92
|
+
|--------|---------|-------------|
|
|
93
|
+
| `s` | `क` | Consonant ka |
|
|
94
|
+
| `s{` | `र्क` | Reph + ka (contextual) |
|
|
95
|
+
| `sl` | `कि` | ka + short i (reordered) |
|
|
96
|
+
| `qm` | `क्र` | Special m transformation |
|
|
97
|
+
| `!@#` | `१२३` | Nepali numbers |
|
|
98
|
+
| `Ù` / `Ú` | `;` / `:` | Literal punctuation |
|
|
99
|
+
| `«` / `»` | `्र` | Ra-foot (for ट, ठ, ड, ढ) |
|
|
100
|
+
| `¿` | `रू` | Combined ruu |
|
|
101
|
+
| `å` | `द्व` | Combined dva |
|
|
102
|
+
| `ˆ` | `फ्` | Half ph |
|
|
103
|
+
| `ª` | `ङ` | Consonant nga |
|
|
104
|
+
| `æ` / `Æ` | `“` / `”` | Curly quotes |
|
|
105
|
+
| `¥` | `र्` | Half ra |
|
|
106
|
+
| `¶` | `ठ्ठ` | Combined thth |
|
|
107
|
+
| `§` | `ट्ट` | Combined tt |
|
|
108
|
+
| `£` | `घ्` | Half gh |
|
|
109
|
+
| `Ë` / `Í` | `ङ्ग` / `ङ्क` | Combined nga-ga / nga-ka |
|
|
110
|
+
| `‰` | `झ्` | Half jh |
|
|
111
|
+
|
|
112
|
+
#### CLI for Preeti
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
python -m nepali_unicoder --preeti "s{sf"
|
|
116
|
+
# Output: र्कका
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
## Transliteration Rules
|
|
121
|
+
|
|
122
|
+
- **Consonants**: `k` -> `क्`, `ka` -> `क`, `kh` -> `ख्`, `kha` -> `ख`
|
|
123
|
+
- **Vowels**: `a` -> `अ`, `aa` -> `आ`, `i` -> `इ`, `u` -> `उ`
|
|
124
|
+
- **Matras**: `ki` -> `कि`, `ko` -> `को`
|
|
125
|
+
- **Special**: `.` -> `।`, `..` -> `॥`
|
|
126
|
+
- **Numbers**: `0-9` -> `०-९` (Decimal points are preserved: `1.5` -> `१.५`)
|
|
127
|
+
|
|
128
|
+
## Advanced Usage
|
|
129
|
+
|
|
130
|
+
### Handling Complex Text
|
|
131
|
+
|
|
132
|
+
The converter handles mixed content gracefully. You can use `{}` to keep text as-is (e.g., for English words or code snippets).
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
text = "mero naam {Sanjeev} ho ra ma 12.5 barsa ko bhaye."
|
|
136
|
+
print(converter.convert(text))
|
|
137
|
+
# Output: मेरो नाम् Sanjeev हो र म १२.५ बर्स को भये।
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Configuration
|
|
141
|
+
|
|
142
|
+
The package uses `word_maps.json` for custom word-level overrides, located in the `src/nepali_unicoder` directory.
|
|
143
|
+
|
|
144
|
+
1. **`word_maps.json`**: Defines custom word-level overrides. Use this for words that don't follow standard phonetic rules.
|
|
145
|
+
|
|
146
|
+
Example `word_maps.json`:
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"nepal": "नेपाल",
|
|
150
|
+
"kathamandu": "काठमाडौँ"
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Contribution
|
|
155
|
+
|
|
156
|
+
We welcome contributions! Here's how you can help:
|
|
157
|
+
|
|
158
|
+
1. **Clone the repository**:
|
|
159
|
+
```bash
|
|
160
|
+
git clone https://github.com/realsanjeev/nepali_unicoder.git
|
|
161
|
+
cd nepali_unicoder
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
2. **Set up a virtual environment**:
|
|
165
|
+
```bash
|
|
166
|
+
python3 -m venv .venv
|
|
167
|
+
source .venv/bin/activate
|
|
168
|
+
pip install -e .
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
3. **Run tests**:
|
|
172
|
+
```bash
|
|
173
|
+
python -m unittest discover tests
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
4. **Submit a Pull Request**: Create a new branch, make your changes, and submit a PR.
|
|
177
|
+
|
|
178
|
+
## Development
|
|
179
|
+
|
|
180
|
+
To run tests:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
python -m unittest discover tests
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## License
|
|
187
|
+
|
|
188
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "nepali_unicoder"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "A Python package for Roman to Nepali (Devanagari) transliteration"
|
|
9
|
+
authors = [
|
|
10
|
+
{ name="realsanjeev", email="075bei033.sanjeev@pcampus.edu.np" },
|
|
11
|
+
]
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = { text = "MIT" }
|
|
14
|
+
requires-python = ">=3.7"
|
|
15
|
+
dependencies = []
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
]
|
|
21
|
+
keywords = ["nepali", "unicoder", "roman to devanagari", "nepali transliteration", "preeti to unicode"]
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
nepali-unicoder = "nepali_unicoder.__main__:main"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
"Homepage" = "https://github.com/realsanjeev/nepali_unicoder"
|
|
29
|
+
"Documentation" = "https://realsanjeev.github.io/nepali_unicoder/"
|
|
30
|
+
"Bug Tracker" = "https://github.com/realsanjeev/nepali_unicoder/issues"
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = [
|
|
34
|
+
"pre-commit",
|
|
35
|
+
"mkdocs",
|
|
36
|
+
"mkdocs-material"
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[tool.pytest.ini_options]
|
|
40
|
+
pythonpath = [
|
|
41
|
+
"src"
|
|
42
|
+
]
|
|
43
|
+
testpaths = [
|
|
44
|
+
"tests",
|
|
45
|
+
]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from nepali_unicoder.convert import Converter
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def main():
|
|
8
|
+
parser = argparse.ArgumentParser(
|
|
9
|
+
prog="python -m nepali_unicoder",
|
|
10
|
+
description="Convert Romanized Nepali or Preeti font text to Unicode Devanagari.",
|
|
11
|
+
)
|
|
12
|
+
parser.add_argument(
|
|
13
|
+
"text",
|
|
14
|
+
nargs="*",
|
|
15
|
+
help="The text to convert. If omitted, reads from stdin.",
|
|
16
|
+
)
|
|
17
|
+
parser.add_argument(
|
|
18
|
+
"--preeti",
|
|
19
|
+
action="store_true",
|
|
20
|
+
help="Enable Preeti to Unicode conversion mode.",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
args = parser.parse_args()
|
|
24
|
+
|
|
25
|
+
# Determine input text
|
|
26
|
+
if args.text:
|
|
27
|
+
input_text = " ".join(args.text)
|
|
28
|
+
elif not sys.stdin.isatty():
|
|
29
|
+
input_text = sys.stdin.read().strip()
|
|
30
|
+
else:
|
|
31
|
+
parser.print_help()
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
mode = "preeti" if args.preeti else "roman"
|
|
35
|
+
converter = Converter(mode=mode)
|
|
36
|
+
result = converter.convert(input_text)
|
|
37
|
+
print(result)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
main()
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from nepali_unicoder.engine import Engine
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Converter:
|
|
5
|
+
"""
|
|
6
|
+
Wrapper around Engine for backward compatibility.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
def __init__(self, mode: str = "roman"):
|
|
10
|
+
self.engine = Engine(mode=mode)
|
|
11
|
+
|
|
12
|
+
def convert(self, text: str) -> str:
|
|
13
|
+
return self.engine.transliterate(text)
|