shamy-arqam 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.
- shamy_arqam-0.2.0/LICENSE +21 -0
- shamy_arqam-0.2.0/PKG-INFO +196 -0
- shamy_arqam-0.2.0/README.md +175 -0
- shamy_arqam-0.2.0/pyproject.toml +37 -0
- shamy_arqam-0.2.0/setup.cfg +4 -0
- shamy_arqam-0.2.0/shamy_arqam/__init__.py +62 -0
- shamy_arqam-0.2.0/shamy_arqam/__main__.py +85 -0
- shamy_arqam-0.2.0/shamy_arqam/_digits.py +196 -0
- shamy_arqam-0.2.0/shamy_arqam/_nd.py +100 -0
- shamy_arqam-0.2.0/shamy_arqam/_numbers.py +103 -0
- shamy_arqam-0.2.0/shamy_arqam/_words.py +151 -0
- shamy_arqam-0.2.0/shamy_arqam.egg-info/PKG-INFO +196 -0
- shamy_arqam-0.2.0/shamy_arqam.egg-info/SOURCES.txt +17 -0
- shamy_arqam-0.2.0/shamy_arqam.egg-info/dependency_links.txt +1 -0
- shamy_arqam-0.2.0/shamy_arqam.egg-info/entry_points.txt +2 -0
- shamy_arqam-0.2.0/shamy_arqam.egg-info/requires.txt +3 -0
- shamy_arqam-0.2.0/shamy_arqam.egg-info/top_level.txt +1 -0
- shamy_arqam-0.2.0/tests/test_arqam.py +290 -0
- shamy_arqam-0.2.0/tests/test_digit_systems.py +263 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Omar Elshamy
|
|
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,196 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: shamy-arqam
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Digits and numbers in any of the world's scripts, with Arabic separators and Egyptian Arabic number words. Pure Python.
|
|
5
|
+
Author: Omar Elshamy
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/omarelshamy25x/shamy-arqam
|
|
8
|
+
Project-URL: Source, https://github.com/omarelshamy25x/shamy-arqam
|
|
9
|
+
Project-URL: Issues, https://github.com/omarelshamy25x/shamy-arqam/issues
|
|
10
|
+
Keywords: arabic,digits,numbers,num2words,arabic-indic,egyptian,i18n,text
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Natural Language :: Arabic
|
|
14
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Provides-Extra: test
|
|
19
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# shamy-arqam
|
|
23
|
+
|
|
24
|
+
Digits and numbers in any of the world's scripts, and numbers written out in Egyptian Arabic.
|
|
25
|
+
|
|
26
|
+
Text mixes digit systems constantly: Arabic-Indic in a Cairo invoice, Devanagari in a Hindi
|
|
27
|
+
form, fullwidth in a Japanese one, and ASCII in the database underneath all of them. Every
|
|
28
|
+
locale also has its own decimal and thousands separators. Getting those wrong turns an amount
|
|
29
|
+
into a different amount, or a CSV into mojibake. This library converts between all 77 decimal
|
|
30
|
+
digit blocks Unicode has, detects which one a string is in, and writes numbers out in Arabic
|
|
31
|
+
words.
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
>>> from shamy_arqam import to_ascii, to_arabic, parse_number, format_number, to_words
|
|
35
|
+
>>> to_ascii("السعر ١٢٣٤٫٥ جنيه")
|
|
36
|
+
'السعر 1234.5 جنيه'
|
|
37
|
+
>>> to_arabic("total 1234.5")
|
|
38
|
+
'total ١٢٣٤٫٥'
|
|
39
|
+
>>> parse_number("١٬٢٣٤٫٥")
|
|
40
|
+
Decimal('1234.5')
|
|
41
|
+
>>> format_number(1234567, style="arabic")
|
|
42
|
+
'١٬٢٣٤٬٥٦٧'
|
|
43
|
+
>>> to_ascii("१२३")
|
|
44
|
+
'123'
|
|
45
|
+
>>> to_digits("1234.5", style="devanagari")
|
|
46
|
+
'१२३४.५'
|
|
47
|
+
>>> digit_style("๑๒๓")
|
|
48
|
+
'thai'
|
|
49
|
+
>>> to_words(1234)
|
|
50
|
+
'ألف وميتين وأربعة وتلاتين'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Pure Python, no dependencies, no network. Python 3.8 and up.
|
|
54
|
+
|
|
55
|
+
## Install
|
|
56
|
+
|
|
57
|
+
Not on PyPI yet. Install it from the repository:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
pip install git+https://github.com/omarelshamy25x/shamy-arqam.git
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Or clone it and `pip install -e .`. The PyPI name `shamy-arqam` is not published yet, so `pip install shamy-arqam` fails until the first release.
|
|
64
|
+
|
|
65
|
+
## What it does
|
|
66
|
+
|
|
67
|
+
`to_ascii(text)` rewrites the digits of any of the world's decimal systems as ASCII: Arabic-Indic
|
|
68
|
+
(`٠١٢٣`), Eastern Arabic-Indic (`۰۱۲۳`), Devanagari, Bengali, Thai, Tibetan, Myanmar, Khmer,
|
|
69
|
+
fullwidth, the mathematical alphabets, all of them. It turns the Arabic decimal separator `٫`
|
|
70
|
+
and thousands separator `٬` into `.` and `,`. Letters and everything else are left alone, so a
|
|
71
|
+
sentence that mixes prose and numbers converts in one pass. Pass `decimal_sep=""` and
|
|
72
|
+
`thousands_sep=""` to drop the separators instead of replacing them.
|
|
73
|
+
|
|
74
|
+
`to_digits(text, style)` goes the other way, and between any two systems: the digits are read in
|
|
75
|
+
whatever system they arrived in, so `to_digits` on a Devanagari number with `style="thai"` gives
|
|
76
|
+
Thai digits. `to_arabic(text)` is the short call for `style="arabic"`, the digits used across the
|
|
77
|
+
Arab world; `style="persian"` gives the Eastern Arabic-Indic digits used in Iran. A period or
|
|
78
|
+
comma between two digits is treated as a number separator; one anywhere else, as at the end of a
|
|
79
|
+
sentence, is left alone.
|
|
80
|
+
|
|
81
|
+
`digit_style(text)` says which system a string is in: `"arabic"`, `"thai"`, `"fullwidth"`, a
|
|
82
|
+
block name, `"mixed"` when two systems appear together, and `""` when there are no digits at all.
|
|
83
|
+
`detect_systems(text)` returns every system present. `digit_systems()` lists the names you can
|
|
84
|
+
pass as `style`, and `has_digits(text)` answers whether there are any digits at all.
|
|
85
|
+
|
|
86
|
+
`parse_number(text)` reads one number and returns a `Decimal`. Arabic or ASCII digits,
|
|
87
|
+
grouping, either separator and a trailing percent sign are accepted. Anything that is not
|
|
88
|
+
cleanly a number raises `ValueError` instead of being half-read.
|
|
89
|
+
|
|
90
|
+
`format_number(value, style="ascii", grouping=True)` writes a number back, grouped in threes,
|
|
91
|
+
in the digit system you ask for, which is any name `digit_systems()` returns. `is_number(text)` answers the same question as `parse_number`
|
|
92
|
+
without raising.
|
|
93
|
+
|
|
94
|
+
`to_words(number)` writes a number out in Egyptian Arabic words, up to a trillion.
|
|
95
|
+
|
|
96
|
+
## Every digit system, and where the separators come from
|
|
97
|
+
|
|
98
|
+
The digit table is generated from the Unicode Character Database (Unicode 18.0.0), not typed by
|
|
99
|
+
hand and not read out of the interpreter, because a table taken from `unicodedata` is only as new
|
|
100
|
+
as the Python it runs on. That is 77 blocks, ASCII included, from Arabic-Indic and Devanagari to
|
|
101
|
+
Kawi, Nag Mundari and the mathematical alphabets.
|
|
102
|
+
|
|
103
|
+
Three tests keep it honest: every row must be a zero followed by nine decimal digits according to
|
|
104
|
+
`unicodedata`, every decimal digit code point the interpreter knows must be in the table, and the
|
|
105
|
+
build fails if the interpreter knows a newer Unicode than the table was generated from, so a
|
|
106
|
+
future Python gets a clear message instead of a silent gap.
|
|
107
|
+
|
|
108
|
+
Two rules decide the separators:
|
|
109
|
+
|
|
110
|
+
- **The Arabic family** (`arabic`, `persian`) is written with its own: `٫` for the decimal and
|
|
111
|
+
`٬` for the thousands, because that is what Arabic typesetting uses.
|
|
112
|
+
- **Every other block** keeps the ASCII `.` and `,`, because those scripts print ASCII
|
|
113
|
+
separators. This library does not invent a separator for a script that does not have one.
|
|
114
|
+
|
|
115
|
+
Command line:
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
$ shamy-arqam --systems # the 77 names, ASCII first
|
|
119
|
+
$ shamy-arqam --to devanagari 1234.5
|
|
120
|
+
१२३४.५
|
|
121
|
+
$ shamy-arqam --detect "๑๒๓"
|
|
122
|
+
thai
|
|
123
|
+
$ shamy-arqam --detect "١ 2"
|
|
124
|
+
mixed (arabic, ascii)
|
|
125
|
+
$ shamy-arqam --format --to thai 1234
|
|
126
|
+
๑,๒๓๔
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## The words are Egyptian, and that is on purpose
|
|
130
|
+
|
|
131
|
+
The forms are the ones people say in Cairo: `اتنين`, `مية`, `تمانين`, `حداشر`. Above a
|
|
132
|
+
thousand the language's own dual and plural are used, not a mechanical suffix:
|
|
133
|
+
|
|
134
|
+
| Number | Words |
|
|
135
|
+
| --- | --- |
|
|
136
|
+
| 1 000 | ألف |
|
|
137
|
+
| 2 000 | ألفين |
|
|
138
|
+
| 3 000 | تلات آلاف |
|
|
139
|
+
| 11 000 | حداشر ألف |
|
|
140
|
+
| 100 000 | مية ألف |
|
|
141
|
+
| 5 000 000 | خمس ملايين |
|
|
142
|
+
|
|
143
|
+
The short combining forms are used in front of a counted noun (`تلات آلاف`, `تمن ملايين`),
|
|
144
|
+
the way the language does. A fraction is read digit by digit after `فاصلة` (`3.14` is
|
|
145
|
+
`تلاتة فاصلة واحد أربعة`), which is how a decimal is read aloud. A negative number is
|
|
146
|
+
prefixed with `سالب`.
|
|
147
|
+
|
|
148
|
+
## What it does not do
|
|
149
|
+
|
|
150
|
+
- **The words are Arabic only.** `to_words()` writes Egyptian Arabic and nothing else. Widening
|
|
151
|
+
the digits to every script did not widen the words: there is no Hindi, no Thai and no
|
|
152
|
+
English number-to-words here, and there is no plan to add one.
|
|
153
|
+
- **It converts decimal digits, not numerals.** Roman numerals, the CJK `一二三`, the Arabic
|
|
154
|
+
abjad letters, and any other counting system that is not a Unicode decimal digit block are
|
|
155
|
+
out of scope.
|
|
156
|
+
- **It does not normalise the letters around the digits.** `۱۲۳` and `١٢٣` convert to the same
|
|
157
|
+
ASCII, but the text stays as written; no Arabic letter normalisation, no Indic shaping.
|
|
158
|
+
- **`to_ascii` treats the Arabic comma as a thousands separator** wherever it appears, not only
|
|
159
|
+
between digits, because in Arabic text it usually is one. A comma that separates two clauses
|
|
160
|
+
becomes an ASCII comma, which is what you wanted anyway, but it is a rewrite, not a check.
|
|
161
|
+
|
|
162
|
+
- **It does not write Modern Standard Arabic.** `اثنان`, `مائة` and `ثمانون` are a different
|
|
163
|
+
register with different agreement rules, and mixing them into one table would produce text
|
|
164
|
+
that reads wrong in both. The formal table is a separate job, not a flag on this one.
|
|
165
|
+
- **It does not guess at malformed numbers.** `1,23` and `12abc` raise rather than being
|
|
166
|
+
repaired, because a wrong amount that looks right is the expensive kind of bug.
|
|
167
|
+
- **It does not handle money, currencies or units.** It writes numbers, not amounts with
|
|
168
|
+
names attached.
|
|
169
|
+
- **A `float` is written from its shortest repr**, so `0.1 + 0.2` comes out as
|
|
170
|
+
`0.30000000000000004`. That is the value the float actually holds. For money, pass a `str`
|
|
171
|
+
or a `Decimal`.
|
|
172
|
+
|
|
173
|
+
## Command line
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
shamy-arqam "السعر ١٢٣٤٫٥" # digits and separators to ASCII
|
|
177
|
+
shamy-arqam --to-arabic 1234.5 # ... and the other way round
|
|
178
|
+
shamy-arqam --to-persian 1234.5 # Eastern Arabic-Indic digits
|
|
179
|
+
shamy-arqam --words 1234 # Egyptian Arabic words
|
|
180
|
+
shamy-arqam --parse ١٬٢٣٤٫٥ # read one number
|
|
181
|
+
shamy-arqam --format --to-arabic 1234567 # grouped, in Arabic digits
|
|
182
|
+
echo "١٢٣" | shamy-arqam # standard input
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Contributing
|
|
186
|
+
|
|
187
|
+
Good first issues are labelled in the tracker. Tests are plain pytest, no network:
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
pip install -e .[test]
|
|
191
|
+
pytest
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
MIT.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# shamy-arqam
|
|
2
|
+
|
|
3
|
+
Digits and numbers in any of the world's scripts, and numbers written out in Egyptian Arabic.
|
|
4
|
+
|
|
5
|
+
Text mixes digit systems constantly: Arabic-Indic in a Cairo invoice, Devanagari in a Hindi
|
|
6
|
+
form, fullwidth in a Japanese one, and ASCII in the database underneath all of them. Every
|
|
7
|
+
locale also has its own decimal and thousands separators. Getting those wrong turns an amount
|
|
8
|
+
into a different amount, or a CSV into mojibake. This library converts between all 77 decimal
|
|
9
|
+
digit blocks Unicode has, detects which one a string is in, and writes numbers out in Arabic
|
|
10
|
+
words.
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
>>> from shamy_arqam import to_ascii, to_arabic, parse_number, format_number, to_words
|
|
14
|
+
>>> to_ascii("السعر ١٢٣٤٫٥ جنيه")
|
|
15
|
+
'السعر 1234.5 جنيه'
|
|
16
|
+
>>> to_arabic("total 1234.5")
|
|
17
|
+
'total ١٢٣٤٫٥'
|
|
18
|
+
>>> parse_number("١٬٢٣٤٫٥")
|
|
19
|
+
Decimal('1234.5')
|
|
20
|
+
>>> format_number(1234567, style="arabic")
|
|
21
|
+
'١٬٢٣٤٬٥٦٧'
|
|
22
|
+
>>> to_ascii("१२३")
|
|
23
|
+
'123'
|
|
24
|
+
>>> to_digits("1234.5", style="devanagari")
|
|
25
|
+
'१२३४.५'
|
|
26
|
+
>>> digit_style("๑๒๓")
|
|
27
|
+
'thai'
|
|
28
|
+
>>> to_words(1234)
|
|
29
|
+
'ألف وميتين وأربعة وتلاتين'
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Pure Python, no dependencies, no network. Python 3.8 and up.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
Not on PyPI yet. Install it from the repository:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
pip install git+https://github.com/omarelshamy25x/shamy-arqam.git
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Or clone it and `pip install -e .`. The PyPI name `shamy-arqam` is not published yet, so `pip install shamy-arqam` fails until the first release.
|
|
43
|
+
|
|
44
|
+
## What it does
|
|
45
|
+
|
|
46
|
+
`to_ascii(text)` rewrites the digits of any of the world's decimal systems as ASCII: Arabic-Indic
|
|
47
|
+
(`٠١٢٣`), Eastern Arabic-Indic (`۰۱۲۳`), Devanagari, Bengali, Thai, Tibetan, Myanmar, Khmer,
|
|
48
|
+
fullwidth, the mathematical alphabets, all of them. It turns the Arabic decimal separator `٫`
|
|
49
|
+
and thousands separator `٬` into `.` and `,`. Letters and everything else are left alone, so a
|
|
50
|
+
sentence that mixes prose and numbers converts in one pass. Pass `decimal_sep=""` and
|
|
51
|
+
`thousands_sep=""` to drop the separators instead of replacing them.
|
|
52
|
+
|
|
53
|
+
`to_digits(text, style)` goes the other way, and between any two systems: the digits are read in
|
|
54
|
+
whatever system they arrived in, so `to_digits` on a Devanagari number with `style="thai"` gives
|
|
55
|
+
Thai digits. `to_arabic(text)` is the short call for `style="arabic"`, the digits used across the
|
|
56
|
+
Arab world; `style="persian"` gives the Eastern Arabic-Indic digits used in Iran. A period or
|
|
57
|
+
comma between two digits is treated as a number separator; one anywhere else, as at the end of a
|
|
58
|
+
sentence, is left alone.
|
|
59
|
+
|
|
60
|
+
`digit_style(text)` says which system a string is in: `"arabic"`, `"thai"`, `"fullwidth"`, a
|
|
61
|
+
block name, `"mixed"` when two systems appear together, and `""` when there are no digits at all.
|
|
62
|
+
`detect_systems(text)` returns every system present. `digit_systems()` lists the names you can
|
|
63
|
+
pass as `style`, and `has_digits(text)` answers whether there are any digits at all.
|
|
64
|
+
|
|
65
|
+
`parse_number(text)` reads one number and returns a `Decimal`. Arabic or ASCII digits,
|
|
66
|
+
grouping, either separator and a trailing percent sign are accepted. Anything that is not
|
|
67
|
+
cleanly a number raises `ValueError` instead of being half-read.
|
|
68
|
+
|
|
69
|
+
`format_number(value, style="ascii", grouping=True)` writes a number back, grouped in threes,
|
|
70
|
+
in the digit system you ask for, which is any name `digit_systems()` returns. `is_number(text)` answers the same question as `parse_number`
|
|
71
|
+
without raising.
|
|
72
|
+
|
|
73
|
+
`to_words(number)` writes a number out in Egyptian Arabic words, up to a trillion.
|
|
74
|
+
|
|
75
|
+
## Every digit system, and where the separators come from
|
|
76
|
+
|
|
77
|
+
The digit table is generated from the Unicode Character Database (Unicode 18.0.0), not typed by
|
|
78
|
+
hand and not read out of the interpreter, because a table taken from `unicodedata` is only as new
|
|
79
|
+
as the Python it runs on. That is 77 blocks, ASCII included, from Arabic-Indic and Devanagari to
|
|
80
|
+
Kawi, Nag Mundari and the mathematical alphabets.
|
|
81
|
+
|
|
82
|
+
Three tests keep it honest: every row must be a zero followed by nine decimal digits according to
|
|
83
|
+
`unicodedata`, every decimal digit code point the interpreter knows must be in the table, and the
|
|
84
|
+
build fails if the interpreter knows a newer Unicode than the table was generated from, so a
|
|
85
|
+
future Python gets a clear message instead of a silent gap.
|
|
86
|
+
|
|
87
|
+
Two rules decide the separators:
|
|
88
|
+
|
|
89
|
+
- **The Arabic family** (`arabic`, `persian`) is written with its own: `٫` for the decimal and
|
|
90
|
+
`٬` for the thousands, because that is what Arabic typesetting uses.
|
|
91
|
+
- **Every other block** keeps the ASCII `.` and `,`, because those scripts print ASCII
|
|
92
|
+
separators. This library does not invent a separator for a script that does not have one.
|
|
93
|
+
|
|
94
|
+
Command line:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
$ shamy-arqam --systems # the 77 names, ASCII first
|
|
98
|
+
$ shamy-arqam --to devanagari 1234.5
|
|
99
|
+
१२३४.५
|
|
100
|
+
$ shamy-arqam --detect "๑๒๓"
|
|
101
|
+
thai
|
|
102
|
+
$ shamy-arqam --detect "١ 2"
|
|
103
|
+
mixed (arabic, ascii)
|
|
104
|
+
$ shamy-arqam --format --to thai 1234
|
|
105
|
+
๑,๒๓๔
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## The words are Egyptian, and that is on purpose
|
|
109
|
+
|
|
110
|
+
The forms are the ones people say in Cairo: `اتنين`, `مية`, `تمانين`, `حداشر`. Above a
|
|
111
|
+
thousand the language's own dual and plural are used, not a mechanical suffix:
|
|
112
|
+
|
|
113
|
+
| Number | Words |
|
|
114
|
+
| --- | --- |
|
|
115
|
+
| 1 000 | ألف |
|
|
116
|
+
| 2 000 | ألفين |
|
|
117
|
+
| 3 000 | تلات آلاف |
|
|
118
|
+
| 11 000 | حداشر ألف |
|
|
119
|
+
| 100 000 | مية ألف |
|
|
120
|
+
| 5 000 000 | خمس ملايين |
|
|
121
|
+
|
|
122
|
+
The short combining forms are used in front of a counted noun (`تلات آلاف`, `تمن ملايين`),
|
|
123
|
+
the way the language does. A fraction is read digit by digit after `فاصلة` (`3.14` is
|
|
124
|
+
`تلاتة فاصلة واحد أربعة`), which is how a decimal is read aloud. A negative number is
|
|
125
|
+
prefixed with `سالب`.
|
|
126
|
+
|
|
127
|
+
## What it does not do
|
|
128
|
+
|
|
129
|
+
- **The words are Arabic only.** `to_words()` writes Egyptian Arabic and nothing else. Widening
|
|
130
|
+
the digits to every script did not widen the words: there is no Hindi, no Thai and no
|
|
131
|
+
English number-to-words here, and there is no plan to add one.
|
|
132
|
+
- **It converts decimal digits, not numerals.** Roman numerals, the CJK `一二三`, the Arabic
|
|
133
|
+
abjad letters, and any other counting system that is not a Unicode decimal digit block are
|
|
134
|
+
out of scope.
|
|
135
|
+
- **It does not normalise the letters around the digits.** `۱۲۳` and `١٢٣` convert to the same
|
|
136
|
+
ASCII, but the text stays as written; no Arabic letter normalisation, no Indic shaping.
|
|
137
|
+
- **`to_ascii` treats the Arabic comma as a thousands separator** wherever it appears, not only
|
|
138
|
+
between digits, because in Arabic text it usually is one. A comma that separates two clauses
|
|
139
|
+
becomes an ASCII comma, which is what you wanted anyway, but it is a rewrite, not a check.
|
|
140
|
+
|
|
141
|
+
- **It does not write Modern Standard Arabic.** `اثنان`, `مائة` and `ثمانون` are a different
|
|
142
|
+
register with different agreement rules, and mixing them into one table would produce text
|
|
143
|
+
that reads wrong in both. The formal table is a separate job, not a flag on this one.
|
|
144
|
+
- **It does not guess at malformed numbers.** `1,23` and `12abc` raise rather than being
|
|
145
|
+
repaired, because a wrong amount that looks right is the expensive kind of bug.
|
|
146
|
+
- **It does not handle money, currencies or units.** It writes numbers, not amounts with
|
|
147
|
+
names attached.
|
|
148
|
+
- **A `float` is written from its shortest repr**, so `0.1 + 0.2` comes out as
|
|
149
|
+
`0.30000000000000004`. That is the value the float actually holds. For money, pass a `str`
|
|
150
|
+
or a `Decimal`.
|
|
151
|
+
|
|
152
|
+
## Command line
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
shamy-arqam "السعر ١٢٣٤٫٥" # digits and separators to ASCII
|
|
156
|
+
shamy-arqam --to-arabic 1234.5 # ... and the other way round
|
|
157
|
+
shamy-arqam --to-persian 1234.5 # Eastern Arabic-Indic digits
|
|
158
|
+
shamy-arqam --words 1234 # Egyptian Arabic words
|
|
159
|
+
shamy-arqam --parse ١٬٢٣٤٫٥ # read one number
|
|
160
|
+
shamy-arqam --format --to-arabic 1234567 # grouped, in Arabic digits
|
|
161
|
+
echo "١٢٣" | shamy-arqam # standard input
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Contributing
|
|
165
|
+
|
|
166
|
+
Good first issues are labelled in the tracker. Tests are plain pytest, no network:
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
pip install -e .[test]
|
|
170
|
+
pytest
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "shamy-arqam"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Digits and numbers in any of the world's scripts, with Arabic separators and Egyptian Arabic number words. Pure Python."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
authors = [{ name = "Omar Elshamy" }]
|
|
12
|
+
requires-python = ">=3.8"
|
|
13
|
+
keywords = ["arabic", "digits", "numbers", "num2words", "arabic-indic", "egyptian", "i18n", "text"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
"Natural Language :: Arabic",
|
|
18
|
+
"Topic :: Text Processing :: Linguistic",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://github.com/omarelshamy25x/shamy-arqam"
|
|
23
|
+
Source = "https://github.com/omarelshamy25x/shamy-arqam"
|
|
24
|
+
Issues = "https://github.com/omarelshamy25x/shamy-arqam/issues"
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
shamy-arqam = "shamy_arqam.__main__:main"
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
test = ["pytest>=7"]
|
|
31
|
+
|
|
32
|
+
[tool.setuptools]
|
|
33
|
+
packages = ["shamy_arqam"]
|
|
34
|
+
|
|
35
|
+
[tool.pytest.ini_options]
|
|
36
|
+
testpaths = ["tests"]
|
|
37
|
+
pythonpath = ["."]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""shamy-arqam: Arabic digits, Arabic separators, and numbers written out in Egyptian Arabic.
|
|
2
|
+
|
|
3
|
+
Three jobs, all of them about numbers in Arabic text:
|
|
4
|
+
|
|
5
|
+
- convert between any of the world's decimal digit systems, ASCII, Arabic-Indic (٠١٢٣),
|
|
6
|
+
Eastern Arabic-Indic (۰۱۲۳), Devanagari, Thai, Tibetan, fullwidth and the rest of Unicode's 65
|
|
7
|
+
decimal blocks, including the Arabic decimal separator ٫ and thousands separator ٬;
|
|
8
|
+
- read a number out of a line of Arabic text, refusing anything that is not cleanly a number;
|
|
9
|
+
- write a number back in the digits you want, or out in words.
|
|
10
|
+
|
|
11
|
+
>>> from shamy_arqam import to_ascii, to_words
|
|
12
|
+
>>> to_ascii("\u0627\u0644\u0633\u0639\u0631 \u0661\u0662\u0663\u0664\u066b\u0665 \u062c\u0646\u064a\u0647")
|
|
13
|
+
'السعر 1234.5 جنيه'
|
|
14
|
+
>>> to_ascii("\u0967\u0968\u0969")
|
|
15
|
+
'123'
|
|
16
|
+
>>> digit_style("\u0967\u0968\u0969")
|
|
17
|
+
'devanagari'
|
|
18
|
+
>>> to_words(1234)
|
|
19
|
+
'ألف وميتين وأربعة وتلاتين'
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
from ._digits import (
|
|
25
|
+
ARABIC_DECIMAL,
|
|
26
|
+
ARABIC_DIGITS,
|
|
27
|
+
ARABIC_THOUSANDS,
|
|
28
|
+
PERSIAN_DIGITS,
|
|
29
|
+
STYLES,
|
|
30
|
+
detect_systems,
|
|
31
|
+
digit_style,
|
|
32
|
+
digit_systems,
|
|
33
|
+
has_arabic_digits,
|
|
34
|
+
has_digits,
|
|
35
|
+
to_arabic,
|
|
36
|
+
to_ascii,
|
|
37
|
+
to_digits,
|
|
38
|
+
)
|
|
39
|
+
from ._numbers import format_number, is_number, parse_number
|
|
40
|
+
from ._words import to_words
|
|
41
|
+
|
|
42
|
+
__version__ = "0.2.0"
|
|
43
|
+
|
|
44
|
+
__all__ = [
|
|
45
|
+
"to_ascii",
|
|
46
|
+
"to_digits",
|
|
47
|
+
"to_arabic",
|
|
48
|
+
"digit_systems",
|
|
49
|
+
"detect_systems",
|
|
50
|
+
"has_digits",
|
|
51
|
+
"has_arabic_digits",
|
|
52
|
+
"digit_style",
|
|
53
|
+
"parse_number",
|
|
54
|
+
"format_number",
|
|
55
|
+
"is_number",
|
|
56
|
+
"to_words",
|
|
57
|
+
"ARABIC_DIGITS",
|
|
58
|
+
"PERSIAN_DIGITS",
|
|
59
|
+
"ARABIC_DECIMAL",
|
|
60
|
+
"ARABIC_THOUSANDS",
|
|
61
|
+
"STYLES",
|
|
62
|
+
]
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Command line entry point.
|
|
2
|
+
|
|
3
|
+
shamy-arqam "السعر ١٢٣٤٫٥" digits and separators to ASCII
|
|
4
|
+
shamy-arqam --to arabic 1234.5 ... and the other way round
|
|
5
|
+
shamy-arqam --to devanagari 1234.5 any of the world's digit systems
|
|
6
|
+
shamy-arqam --systems list them
|
|
7
|
+
shamy-arqam --detect "١٢٣" say which system the text is in
|
|
8
|
+
shamy-arqam --words 1234 numbers as Egyptian Arabic words
|
|
9
|
+
shamy-arqam --parse ١٬٢٣٤٫٥ read one number, print it as a decimal
|
|
10
|
+
shamy-arqam --format 1234567 --to arabic
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import argparse
|
|
16
|
+
import sys
|
|
17
|
+
|
|
18
|
+
from . import (
|
|
19
|
+
__version__,
|
|
20
|
+
detect_systems,
|
|
21
|
+
digit_style,
|
|
22
|
+
digit_systems,
|
|
23
|
+
format_number,
|
|
24
|
+
parse_number,
|
|
25
|
+
to_ascii,
|
|
26
|
+
to_digits,
|
|
27
|
+
to_words,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def main(argv=None) -> int:
|
|
32
|
+
parser = argparse.ArgumentParser(
|
|
33
|
+
prog="shamy_arqam",
|
|
34
|
+
description="Convert digits and separators between any of the world's decimal systems, and write numbers out in Arabic words.",
|
|
35
|
+
)
|
|
36
|
+
parser.add_argument("text", nargs="*", help="text or number to work on; reads standard input when empty")
|
|
37
|
+
parser.add_argument(
|
|
38
|
+
"--to",
|
|
39
|
+
metavar="STYLE",
|
|
40
|
+
help='write the digits in this system: "arabic", "persian", "devanagari", "thai", "fullwidth", ...',
|
|
41
|
+
)
|
|
42
|
+
parser.add_argument("--to-arabic", action="store_true", help="short for --to arabic")
|
|
43
|
+
parser.add_argument("--to-persian", action="store_true", help="short for --to persian")
|
|
44
|
+
parser.add_argument("--systems", action="store_true", help="list the digit systems and exit")
|
|
45
|
+
parser.add_argument("--detect", action="store_true", help="say which digit system the text is in")
|
|
46
|
+
parser.add_argument("--words", action="store_true", help="write the number out in Egyptian Arabic words")
|
|
47
|
+
parser.add_argument("--parse", action="store_true", help="read the number and print it as a decimal")
|
|
48
|
+
parser.add_argument("--format", action="store_true", help="read the number and print it grouped")
|
|
49
|
+
parser.add_argument("--no-grouping", action="store_true", help="do not split the integer part into threes")
|
|
50
|
+
parser.add_argument("--version", action="version", version="shamy-arqam " + __version__)
|
|
51
|
+
args = parser.parse_args(argv)
|
|
52
|
+
|
|
53
|
+
if args.systems:
|
|
54
|
+
sys.stdout.write("\n".join(digit_systems()) + "\n")
|
|
55
|
+
return 0
|
|
56
|
+
|
|
57
|
+
text = " ".join(args.text) if args.text else sys.stdin.read().strip()
|
|
58
|
+
if not text:
|
|
59
|
+
parser.error("nothing to work on: pass text or pipe it in")
|
|
60
|
+
|
|
61
|
+
grouping = not args.no_grouping
|
|
62
|
+
style = args.to or ("persian" if args.to_persian else "arabic" if args.to_arabic else None)
|
|
63
|
+
try:
|
|
64
|
+
if args.detect:
|
|
65
|
+
found = detect_systems(text)
|
|
66
|
+
result = digit_style(text) + (" (%s)" % ", ".join(found) if len(found) > 1 else "")
|
|
67
|
+
elif args.words:
|
|
68
|
+
result = to_words(parse_number(text))
|
|
69
|
+
elif args.parse:
|
|
70
|
+
result = format(parse_number(text), "f")
|
|
71
|
+
elif args.format:
|
|
72
|
+
result = format_number(parse_number(text), style=style or "ascii", grouping=grouping)
|
|
73
|
+
elif style:
|
|
74
|
+
result = to_digits(text, style=style)
|
|
75
|
+
else:
|
|
76
|
+
result = to_ascii(text)
|
|
77
|
+
except (TypeError, ValueError) as error:
|
|
78
|
+
sys.stderr.write("error: %s\n" % error)
|
|
79
|
+
return 1
|
|
80
|
+
sys.stdout.write(result if result.endswith("\n") else result + "\n")
|
|
81
|
+
return 0
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
if __name__ == "__main__":
|
|
85
|
+
raise SystemExit(main())
|