scriptconv 0.0.1__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.
- scriptconv-0.0.1/LICENSE +202 -0
- scriptconv-0.0.1/PKG-INFO +210 -0
- scriptconv-0.0.1/README.md +183 -0
- scriptconv-0.0.1/pyproject.toml +45 -0
- scriptconv-0.0.1/requirements.txt +0 -0
- scriptconv-0.0.1/scriptconv/__init__.py +95 -0
- scriptconv-0.0.1/scriptconv/__main__.py +109 -0
- scriptconv-0.0.1/scriptconv/notation.py +950 -0
- scriptconv-0.0.1/scriptconv/py.typed +0 -0
- scriptconv-0.0.1/scriptconv/scripts.py +818 -0
- scriptconv-0.0.1/scriptconv/translit.py +154 -0
- scriptconv-0.0.1/scriptconv/version.py +10 -0
- scriptconv-0.0.1/scriptconv.egg-info/PKG-INFO +210 -0
- scriptconv-0.0.1/scriptconv.egg-info/SOURCES.txt +21 -0
- scriptconv-0.0.1/scriptconv.egg-info/dependency_links.txt +1 -0
- scriptconv-0.0.1/scriptconv.egg-info/requires.txt +4 -0
- scriptconv-0.0.1/scriptconv.egg-info/top_level.txt +1 -0
- scriptconv-0.0.1/setup.cfg +4 -0
- scriptconv-0.0.1/tests/test_cli.py +88 -0
- scriptconv-0.0.1/tests/test_examples.py +107 -0
- scriptconv-0.0.1/tests/test_notation.py +1059 -0
- scriptconv-0.0.1/tests/test_scripts.py +744 -0
- scriptconv-0.0.1/tests/test_translit.py +98 -0
scriptconv-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scriptconv
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Shared script-conversion core — ISO-15924 detection, IPA↔ARPA/X-SAMPA/Lexique, Buckwalter, Hangul→jamo
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/TigreGotico/scriptconv
|
|
7
|
+
Project-URL: Issues, https://github.com/TigreGotico/scriptconv/issues
|
|
8
|
+
Keywords: ipa,arpabet,x-sampa,lexique,buckwalter,hangul,script,iso15924,tts,g2p,phoneme
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pytest; extra == "test"
|
|
25
|
+
Requires-Dist: pytest-timeout; extra == "test"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# scriptconv
|
|
29
|
+
|
|
30
|
+
[](LICENSE)
|
|
31
|
+
[](https://github.com/TigreGotico/scriptconv/actions/workflows/build-tests.yml)
|
|
32
|
+
[](https://pypi.org/project/scriptconv/)
|
|
33
|
+
|
|
34
|
+
**scriptconv** is a zero-dependency Python library for written-script operations:
|
|
35
|
+
ISO-15924 script identification and metadata, character-range detection, language-to-script
|
|
36
|
+
mapping, phoneme-notation transcoding (IPA ↔ ARPABET ↔ X-SAMPA, IPA ↔ Lexique,
|
|
37
|
+
Buckwalter ↔ Arabic script), and orthographic decomposition of Hangul syllable blocks into
|
|
38
|
+
jamo letters. Every conversion is a pure data table or arithmetic operation; no linguistic
|
|
39
|
+
rules, no external files, no runtime dependencies beyond the Python standard library.
|
|
40
|
+
|
|
41
|
+
Transcoding is reversible where the target inventory permits — see
|
|
42
|
+
[Fidelity guarantees](#fidelity-guarantees) for the exact per-notation guarantees.
|
|
43
|
+
|
|
44
|
+
## Scope
|
|
45
|
+
|
|
46
|
+
scriptconv is exclusively about **written scripts**: identification and metadata,
|
|
47
|
+
transliteration between script representations, re-encoding of phoneme symbols
|
|
48
|
+
between notation systems, and orthographic decomposition. It never phonemizes — anything
|
|
49
|
+
that requires knowing how a language *sounds* (grapheme-to-phoneme rules, allophony,
|
|
50
|
+
coarticulation, sandhi) is outside this library's scope.
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install scriptconv
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Development
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
uv pip install -e '.[test]'
|
|
62
|
+
pytest tests/
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`tests/test_examples.py` runs the scripts under `examples/`, which import the installed
|
|
66
|
+
package — install with `-e` first.
|
|
67
|
+
|
|
68
|
+
## Quick start
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from scriptconv import (
|
|
72
|
+
detect_script, char_script, script_distribution, script_runs, base_direction,
|
|
73
|
+
lang_to_script, script_to_langs, normalize_script_tag, SCRIPT_REGISTRY,
|
|
74
|
+
arpa_to_ipa, ipa_to_arpa,
|
|
75
|
+
xsampa_to_ipa, ipa_to_xsampa,
|
|
76
|
+
buckwalter_to_arabic, arabic_to_buckwalter,
|
|
77
|
+
lexique_to_ipa, ipa_to_lexique,
|
|
78
|
+
kirshenbaum_to_ipa, ipa_to_kirshenbaum, looks_like_ipa,
|
|
79
|
+
decompose_hangul, hira_to_kana, kana_to_hira,
|
|
80
|
+
convert, can_convert, convert_batch, Notation, NOTATION_INFO,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
detect_script("안녕하세요") # "Hang"
|
|
84
|
+
char_script("ɑ") # "Latn" (IPA Extensions)
|
|
85
|
+
script_distribution("Hello مرحبا") # {'Latn': 5, 'Arab': 5}
|
|
86
|
+
script_runs("привет hello") # [('Cyrl', 'привет '), ('Latn', 'hello')]
|
|
87
|
+
base_direction("مرحبا بالعالم") # "rtl"
|
|
88
|
+
SCRIPT_REGISTRY["Arab"].script_type # "abjad" (typological class)
|
|
89
|
+
|
|
90
|
+
lang_to_script("pt-BR") # "Latn"
|
|
91
|
+
script_to_langs("Cyrl") # ['av', 'ba', 'be', 'bg', ...]
|
|
92
|
+
normalize_script_tag("syllabics") # "Cans"
|
|
93
|
+
normalize_script_tag("japanese") # "Hira"
|
|
94
|
+
|
|
95
|
+
arpa_to_ipa("HH AH0 L OW1") # "həloʊ"
|
|
96
|
+
ipa_to_arpa("həloʊ") # "HH AX L OW"
|
|
97
|
+
|
|
98
|
+
xsampa_to_ipa("tS") # "tʃ"
|
|
99
|
+
ipa_to_xsampa("ɹ") # "r\\"
|
|
100
|
+
|
|
101
|
+
buckwalter_to_arabic("mrHbA") # "مرحبا"
|
|
102
|
+
arabic_to_buckwalter("مرحبا") # "mrHbA"
|
|
103
|
+
|
|
104
|
+
lexique_to_ipa("b§ZuR") # "bɔ̃ʒuʁ" (bonjour)
|
|
105
|
+
ipa_to_lexique("vɛ̃") # "v5" (vin)
|
|
106
|
+
|
|
107
|
+
kirshenbaum_to_ipa("S") # "ʃ" (espeak-ng ASCII-IPA)
|
|
108
|
+
ipa_to_kirshenbaum("ŋ") # "N"
|
|
109
|
+
|
|
110
|
+
looks_like_ipa("pʰɑtʃ") # True (heuristic: has IPA-distinctive symbols)
|
|
111
|
+
looks_like_ipa("hello") # False
|
|
112
|
+
|
|
113
|
+
decompose_hangul("국민") # "ㄱㅜㄱㅁㅣㄴ" (orthographic jamo, no assimilation)
|
|
114
|
+
hira_to_kana("ひらがな") # "ヒラガナ"
|
|
115
|
+
kana_to_hira("カタカナ") # "かたかな"
|
|
116
|
+
|
|
117
|
+
convert("NG", Notation.ARPA, Notation.XSAMPA) # "N"
|
|
118
|
+
convert("HH AH0 L OW1", "arpa", "kirshenbaum") # "h@loU"
|
|
119
|
+
can_convert("arpa", "x-sampa") # True
|
|
120
|
+
can_convert("buckwalter", "ipa") # False
|
|
121
|
+
list(convert_batch(["HH AH0", "AY1"], "arpa", "ipa")) # ['hə', 'aɪ']
|
|
122
|
+
|
|
123
|
+
NOTATION_INFO[Notation.ARPA].lossless_from_ipa # False (restricted inventory)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### CLI
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
python -m scriptconv convert arpa ipa "HH AH0 L OW1"
|
|
130
|
+
python -m scriptconv detect "안녕하세요"
|
|
131
|
+
python -m scriptconv distribution "Hello مرحبا"
|
|
132
|
+
python -m scriptconv direction "مرحبا بالعالم"
|
|
133
|
+
python -m scriptconv decompose "국민"
|
|
134
|
+
python -m scriptconv lang ko
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Modules
|
|
138
|
+
|
|
139
|
+
| Module | Contents |
|
|
140
|
+
|--------|----------|
|
|
141
|
+
| `scriptconv.scripts` | `Script` dataclass (with `script_type`), `SCRIPT_REGISTRY` (34 scripts), `detect_script`, `char_script`, `script_distribution`, `script_runs`, `base_direction`, `lang_to_script`, `script_to_langs`, `normalize_script_tag` |
|
|
142
|
+
| `scriptconv.notation` | `Notation` enum, `NotationInfo`/`NOTATION_INFO` fidelity registry, `convert` facade, `can_convert` predicate, `convert_batch` generator, pair-wise converters (ARPABET ↔ IPA, X-SAMPA ↔ IPA, Buckwalter ↔ Arabic, Lexique ↔ IPA, Kirshenbaum ↔ IPA), `looks_like_ipa` detector |
|
|
143
|
+
| `scriptconv.translit` | `decompose_hangul` (Hangul blocks → jamo, compatibility or conjoining), `hira_to_kana`/`kana_to_hira` — all orthographic only |
|
|
144
|
+
|
|
145
|
+
## Documentation
|
|
146
|
+
|
|
147
|
+
- [docs/scripts.md](docs/scripts.md) — Script registry, detection, language mapping, label normalisation
|
|
148
|
+
- [docs/notation.md](docs/notation.md) — Notation enum, per-pair converter reference, round-trip guarantees
|
|
149
|
+
- [docs/translit.md](docs/translit.md) — Hangul decomposition arithmetic and scope boundary
|
|
150
|
+
|
|
151
|
+
## Examples
|
|
152
|
+
|
|
153
|
+
Runnable scripts in [examples/](examples/):
|
|
154
|
+
|
|
155
|
+
| File | Demonstrates |
|
|
156
|
+
|------|-------------|
|
|
157
|
+
| `01_detect_script.py` | Mixed-script text triage |
|
|
158
|
+
| `02_lang_to_script.py` | Language tag → ISO-15924 mapping |
|
|
159
|
+
| `03_arpabet_roundtrip.py` | CMUdict-style line → IPA and back |
|
|
160
|
+
| `04_xsampa.py` | X-SAMPA ↔ IPA, multi-char longest-first cases |
|
|
161
|
+
| `05_buckwalter.py` | Arabic ↔ Buckwalter both directions |
|
|
162
|
+
| `06_lexique.py` | French Lexique codes → IPA |
|
|
163
|
+
| `07_hangul_decompose.py` | Hangul syllable blocks → jamo letters |
|
|
164
|
+
| `08_script_distribution.py` | Character counts per script + base direction |
|
|
165
|
+
| `09_script_to_langs.py` | Reverse lookup: script → languages |
|
|
166
|
+
| `10_new_labels.py` | New normalize_script_tag labels (japanese, jamo, cjk…) |
|
|
167
|
+
| `11_cli.py` | CLI interface: detect, distribution, direction, decompose, lang |
|
|
168
|
+
| `12_kirshenbaum.py` | Kirshenbaum (ASCII-IPA) ↔ IPA, and ARPABET → Kirshenbaum routing |
|
|
169
|
+
| `13_script_runs.py` | Per-script segmentation of mixed-script text |
|
|
170
|
+
| `14_kana_transliteration.py` | Hiragana ↔ Katakana |
|
|
171
|
+
|
|
172
|
+
## Fidelity guarantees
|
|
173
|
+
|
|
174
|
+
Transcoding faithfulness depends on the target notation's inventory. IPA is the hub;
|
|
175
|
+
notation↔notation goes through IPA. The table below states, for each notation, whether a
|
|
176
|
+
round-trip is exact and what happens to a symbol the table does not know.
|
|
177
|
+
|
|
178
|
+
| Notation | `to_ipa` → `from_ipa` round-trip | `from_ipa` → `to_ipa` round-trip | Unknown-token behaviour |
|
|
179
|
+
|----------|----------------------------------|----------------------------------|-------------------------|
|
|
180
|
+
| **ARPABET** | Exact for base symbols; **stress digits are dropped** and `AH0`↔`AX` (schwa) is not distinguished | **Lossy** — ARPABET is an English-only inventory, so any IPA symbol outside it becomes the *unknown* placeholder | `arpa_to_ipa`: passed through unchanged. `ipa_to_arpa`: diacritics and suprasegmentals (combining marks, length/stress modifiers) are dropped; other out-of-inventory symbols are replaced with `?` by default (`unknown=` param; `unknown=""` drops) |
|
|
181
|
+
| **X-SAMPA** | Exact for all canonical symbols | Exact except aliases (`f\`→ɸ, `&`→æ) normalise to their canonical spelling | Passed through unchanged |
|
|
182
|
+
| **Buckwalter ↔ Arabic** | Exact (the `^` shadda alias normalises to canonical `~`; precomposed lam-alef ligatures decompose to two chars, visually identical) | Exact | Passed through unchanged |
|
|
183
|
+
| **Lexique ↔ IPA** | Exact except the `°`/`3` schwa pair (both → `ə`; reverse always → `°`) | Exact | Passed through unchanged |
|
|
184
|
+
| **Kirshenbaum ↔ IPA** | Exact | **Lossy** — restricted ASCII inventory; IPA outside it passes through | Passed through unchanged |
|
|
185
|
+
|
|
186
|
+
This table is also available programmatically via `NOTATION_INFO`
|
|
187
|
+
(`NotationInfo` records with `lossless_to_ipa`, `lossless_from_ipa`,
|
|
188
|
+
`token_separated`, and a `reference` citation per notation).
|
|
189
|
+
|
|
190
|
+
Notes:
|
|
191
|
+
|
|
192
|
+
- The voiced velar stop is stored as script `ɡ` (U+0261) across all tables; `ipa_to_arpa`
|
|
193
|
+
also accepts ASCII `g` (U+0067) on input.
|
|
194
|
+
- Only `ipa_to_arpa` substitutes for unknowns today (because ARPABET is a restricted
|
|
195
|
+
inventory); every other converter passes unknowns through. See
|
|
196
|
+
[docs/notation.md](docs/notation.md) for the per-symbol detail.
|
|
197
|
+
|
|
198
|
+
## License and attribution
|
|
199
|
+
|
|
200
|
+
scriptconv is released under the **Apache-2.0** license.
|
|
201
|
+
|
|
202
|
+
Derived tables used internally:
|
|
203
|
+
|
|
204
|
+
| Table | Source | License |
|
|
205
|
+
|-------|--------|---------|
|
|
206
|
+
| ARPABET ↔ IPA | [chorusai/arpa2ipa](https://github.com/chorusai/arpa2ipa) | Apache-2.0 |
|
|
207
|
+
| Buckwalter ↔ Arabic | Tim Buckwalter's Arabic transliteration scheme | — (factual 1:1 mapping) |
|
|
208
|
+
| Lexique phoneme codes | New, B. & Pallier, C. — *Manuel de Lexique 3* v3.11, Tableau 2; [chrplr/openlexicon](https://github.com/chrplr/openlexicon) | CC BY-SA 4.0 |
|
|
209
|
+
| Kirshenbaum ↔ IPA | Kirshenbaum 1993 ASCII-IPA standard (comp.speech), cross-checked against espeak-ng | — (factual symbol mapping) |
|
|
210
|
+
| Hangul jamo tables | [stannam/hangul_to_ipa](https://github.com/stannam/hangul_to_ipa) | — |
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# scriptconv
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
[](https://github.com/TigreGotico/scriptconv/actions/workflows/build-tests.yml)
|
|
5
|
+
[](https://pypi.org/project/scriptconv/)
|
|
6
|
+
|
|
7
|
+
**scriptconv** is a zero-dependency Python library for written-script operations:
|
|
8
|
+
ISO-15924 script identification and metadata, character-range detection, language-to-script
|
|
9
|
+
mapping, phoneme-notation transcoding (IPA ↔ ARPABET ↔ X-SAMPA, IPA ↔ Lexique,
|
|
10
|
+
Buckwalter ↔ Arabic script), and orthographic decomposition of Hangul syllable blocks into
|
|
11
|
+
jamo letters. Every conversion is a pure data table or arithmetic operation; no linguistic
|
|
12
|
+
rules, no external files, no runtime dependencies beyond the Python standard library.
|
|
13
|
+
|
|
14
|
+
Transcoding is reversible where the target inventory permits — see
|
|
15
|
+
[Fidelity guarantees](#fidelity-guarantees) for the exact per-notation guarantees.
|
|
16
|
+
|
|
17
|
+
## Scope
|
|
18
|
+
|
|
19
|
+
scriptconv is exclusively about **written scripts**: identification and metadata,
|
|
20
|
+
transliteration between script representations, re-encoding of phoneme symbols
|
|
21
|
+
between notation systems, and orthographic decomposition. It never phonemizes — anything
|
|
22
|
+
that requires knowing how a language *sounds* (grapheme-to-phoneme rules, allophony,
|
|
23
|
+
coarticulation, sandhi) is outside this library's scope.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install scriptconv
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Development
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
uv pip install -e '.[test]'
|
|
35
|
+
pytest tests/
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`tests/test_examples.py` runs the scripts under `examples/`, which import the installed
|
|
39
|
+
package — install with `-e` first.
|
|
40
|
+
|
|
41
|
+
## Quick start
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from scriptconv import (
|
|
45
|
+
detect_script, char_script, script_distribution, script_runs, base_direction,
|
|
46
|
+
lang_to_script, script_to_langs, normalize_script_tag, SCRIPT_REGISTRY,
|
|
47
|
+
arpa_to_ipa, ipa_to_arpa,
|
|
48
|
+
xsampa_to_ipa, ipa_to_xsampa,
|
|
49
|
+
buckwalter_to_arabic, arabic_to_buckwalter,
|
|
50
|
+
lexique_to_ipa, ipa_to_lexique,
|
|
51
|
+
kirshenbaum_to_ipa, ipa_to_kirshenbaum, looks_like_ipa,
|
|
52
|
+
decompose_hangul, hira_to_kana, kana_to_hira,
|
|
53
|
+
convert, can_convert, convert_batch, Notation, NOTATION_INFO,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
detect_script("안녕하세요") # "Hang"
|
|
57
|
+
char_script("ɑ") # "Latn" (IPA Extensions)
|
|
58
|
+
script_distribution("Hello مرحبا") # {'Latn': 5, 'Arab': 5}
|
|
59
|
+
script_runs("привет hello") # [('Cyrl', 'привет '), ('Latn', 'hello')]
|
|
60
|
+
base_direction("مرحبا بالعالم") # "rtl"
|
|
61
|
+
SCRIPT_REGISTRY["Arab"].script_type # "abjad" (typological class)
|
|
62
|
+
|
|
63
|
+
lang_to_script("pt-BR") # "Latn"
|
|
64
|
+
script_to_langs("Cyrl") # ['av', 'ba', 'be', 'bg', ...]
|
|
65
|
+
normalize_script_tag("syllabics") # "Cans"
|
|
66
|
+
normalize_script_tag("japanese") # "Hira"
|
|
67
|
+
|
|
68
|
+
arpa_to_ipa("HH AH0 L OW1") # "həloʊ"
|
|
69
|
+
ipa_to_arpa("həloʊ") # "HH AX L OW"
|
|
70
|
+
|
|
71
|
+
xsampa_to_ipa("tS") # "tʃ"
|
|
72
|
+
ipa_to_xsampa("ɹ") # "r\\"
|
|
73
|
+
|
|
74
|
+
buckwalter_to_arabic("mrHbA") # "مرحبا"
|
|
75
|
+
arabic_to_buckwalter("مرحبا") # "mrHbA"
|
|
76
|
+
|
|
77
|
+
lexique_to_ipa("b§ZuR") # "bɔ̃ʒuʁ" (bonjour)
|
|
78
|
+
ipa_to_lexique("vɛ̃") # "v5" (vin)
|
|
79
|
+
|
|
80
|
+
kirshenbaum_to_ipa("S") # "ʃ" (espeak-ng ASCII-IPA)
|
|
81
|
+
ipa_to_kirshenbaum("ŋ") # "N"
|
|
82
|
+
|
|
83
|
+
looks_like_ipa("pʰɑtʃ") # True (heuristic: has IPA-distinctive symbols)
|
|
84
|
+
looks_like_ipa("hello") # False
|
|
85
|
+
|
|
86
|
+
decompose_hangul("국민") # "ㄱㅜㄱㅁㅣㄴ" (orthographic jamo, no assimilation)
|
|
87
|
+
hira_to_kana("ひらがな") # "ヒラガナ"
|
|
88
|
+
kana_to_hira("カタカナ") # "かたかな"
|
|
89
|
+
|
|
90
|
+
convert("NG", Notation.ARPA, Notation.XSAMPA) # "N"
|
|
91
|
+
convert("HH AH0 L OW1", "arpa", "kirshenbaum") # "h@loU"
|
|
92
|
+
can_convert("arpa", "x-sampa") # True
|
|
93
|
+
can_convert("buckwalter", "ipa") # False
|
|
94
|
+
list(convert_batch(["HH AH0", "AY1"], "arpa", "ipa")) # ['hə', 'aɪ']
|
|
95
|
+
|
|
96
|
+
NOTATION_INFO[Notation.ARPA].lossless_from_ipa # False (restricted inventory)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### CLI
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
python -m scriptconv convert arpa ipa "HH AH0 L OW1"
|
|
103
|
+
python -m scriptconv detect "안녕하세요"
|
|
104
|
+
python -m scriptconv distribution "Hello مرحبا"
|
|
105
|
+
python -m scriptconv direction "مرحبا بالعالم"
|
|
106
|
+
python -m scriptconv decompose "국민"
|
|
107
|
+
python -m scriptconv lang ko
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Modules
|
|
111
|
+
|
|
112
|
+
| Module | Contents |
|
|
113
|
+
|--------|----------|
|
|
114
|
+
| `scriptconv.scripts` | `Script` dataclass (with `script_type`), `SCRIPT_REGISTRY` (34 scripts), `detect_script`, `char_script`, `script_distribution`, `script_runs`, `base_direction`, `lang_to_script`, `script_to_langs`, `normalize_script_tag` |
|
|
115
|
+
| `scriptconv.notation` | `Notation` enum, `NotationInfo`/`NOTATION_INFO` fidelity registry, `convert` facade, `can_convert` predicate, `convert_batch` generator, pair-wise converters (ARPABET ↔ IPA, X-SAMPA ↔ IPA, Buckwalter ↔ Arabic, Lexique ↔ IPA, Kirshenbaum ↔ IPA), `looks_like_ipa` detector |
|
|
116
|
+
| `scriptconv.translit` | `decompose_hangul` (Hangul blocks → jamo, compatibility or conjoining), `hira_to_kana`/`kana_to_hira` — all orthographic only |
|
|
117
|
+
|
|
118
|
+
## Documentation
|
|
119
|
+
|
|
120
|
+
- [docs/scripts.md](docs/scripts.md) — Script registry, detection, language mapping, label normalisation
|
|
121
|
+
- [docs/notation.md](docs/notation.md) — Notation enum, per-pair converter reference, round-trip guarantees
|
|
122
|
+
- [docs/translit.md](docs/translit.md) — Hangul decomposition arithmetic and scope boundary
|
|
123
|
+
|
|
124
|
+
## Examples
|
|
125
|
+
|
|
126
|
+
Runnable scripts in [examples/](examples/):
|
|
127
|
+
|
|
128
|
+
| File | Demonstrates |
|
|
129
|
+
|------|-------------|
|
|
130
|
+
| `01_detect_script.py` | Mixed-script text triage |
|
|
131
|
+
| `02_lang_to_script.py` | Language tag → ISO-15924 mapping |
|
|
132
|
+
| `03_arpabet_roundtrip.py` | CMUdict-style line → IPA and back |
|
|
133
|
+
| `04_xsampa.py` | X-SAMPA ↔ IPA, multi-char longest-first cases |
|
|
134
|
+
| `05_buckwalter.py` | Arabic ↔ Buckwalter both directions |
|
|
135
|
+
| `06_lexique.py` | French Lexique codes → IPA |
|
|
136
|
+
| `07_hangul_decompose.py` | Hangul syllable blocks → jamo letters |
|
|
137
|
+
| `08_script_distribution.py` | Character counts per script + base direction |
|
|
138
|
+
| `09_script_to_langs.py` | Reverse lookup: script → languages |
|
|
139
|
+
| `10_new_labels.py` | New normalize_script_tag labels (japanese, jamo, cjk…) |
|
|
140
|
+
| `11_cli.py` | CLI interface: detect, distribution, direction, decompose, lang |
|
|
141
|
+
| `12_kirshenbaum.py` | Kirshenbaum (ASCII-IPA) ↔ IPA, and ARPABET → Kirshenbaum routing |
|
|
142
|
+
| `13_script_runs.py` | Per-script segmentation of mixed-script text |
|
|
143
|
+
| `14_kana_transliteration.py` | Hiragana ↔ Katakana |
|
|
144
|
+
|
|
145
|
+
## Fidelity guarantees
|
|
146
|
+
|
|
147
|
+
Transcoding faithfulness depends on the target notation's inventory. IPA is the hub;
|
|
148
|
+
notation↔notation goes through IPA. The table below states, for each notation, whether a
|
|
149
|
+
round-trip is exact and what happens to a symbol the table does not know.
|
|
150
|
+
|
|
151
|
+
| Notation | `to_ipa` → `from_ipa` round-trip | `from_ipa` → `to_ipa` round-trip | Unknown-token behaviour |
|
|
152
|
+
|----------|----------------------------------|----------------------------------|-------------------------|
|
|
153
|
+
| **ARPABET** | Exact for base symbols; **stress digits are dropped** and `AH0`↔`AX` (schwa) is not distinguished | **Lossy** — ARPABET is an English-only inventory, so any IPA symbol outside it becomes the *unknown* placeholder | `arpa_to_ipa`: passed through unchanged. `ipa_to_arpa`: diacritics and suprasegmentals (combining marks, length/stress modifiers) are dropped; other out-of-inventory symbols are replaced with `?` by default (`unknown=` param; `unknown=""` drops) |
|
|
154
|
+
| **X-SAMPA** | Exact for all canonical symbols | Exact except aliases (`f\`→ɸ, `&`→æ) normalise to their canonical spelling | Passed through unchanged |
|
|
155
|
+
| **Buckwalter ↔ Arabic** | Exact (the `^` shadda alias normalises to canonical `~`; precomposed lam-alef ligatures decompose to two chars, visually identical) | Exact | Passed through unchanged |
|
|
156
|
+
| **Lexique ↔ IPA** | Exact except the `°`/`3` schwa pair (both → `ə`; reverse always → `°`) | Exact | Passed through unchanged |
|
|
157
|
+
| **Kirshenbaum ↔ IPA** | Exact | **Lossy** — restricted ASCII inventory; IPA outside it passes through | Passed through unchanged |
|
|
158
|
+
|
|
159
|
+
This table is also available programmatically via `NOTATION_INFO`
|
|
160
|
+
(`NotationInfo` records with `lossless_to_ipa`, `lossless_from_ipa`,
|
|
161
|
+
`token_separated`, and a `reference` citation per notation).
|
|
162
|
+
|
|
163
|
+
Notes:
|
|
164
|
+
|
|
165
|
+
- The voiced velar stop is stored as script `ɡ` (U+0261) across all tables; `ipa_to_arpa`
|
|
166
|
+
also accepts ASCII `g` (U+0067) on input.
|
|
167
|
+
- Only `ipa_to_arpa` substitutes for unknowns today (because ARPABET is a restricted
|
|
168
|
+
inventory); every other converter passes unknowns through. See
|
|
169
|
+
[docs/notation.md](docs/notation.md) for the per-symbol detail.
|
|
170
|
+
|
|
171
|
+
## License and attribution
|
|
172
|
+
|
|
173
|
+
scriptconv is released under the **Apache-2.0** license.
|
|
174
|
+
|
|
175
|
+
Derived tables used internally:
|
|
176
|
+
|
|
177
|
+
| Table | Source | License |
|
|
178
|
+
|-------|--------|---------|
|
|
179
|
+
| ARPABET ↔ IPA | [chorusai/arpa2ipa](https://github.com/chorusai/arpa2ipa) | Apache-2.0 |
|
|
180
|
+
| Buckwalter ↔ Arabic | Tim Buckwalter's Arabic transliteration scheme | — (factual 1:1 mapping) |
|
|
181
|
+
| Lexique phoneme codes | New, B. & Pallier, C. — *Manuel de Lexique 3* v3.11, Tableau 2; [chrplr/openlexicon](https://github.com/chrplr/openlexicon) | CC BY-SA 4.0 |
|
|
182
|
+
| Kirshenbaum ↔ IPA | Kirshenbaum 1993 ASCII-IPA standard (comp.speech), cross-checked against espeak-ng | — (factual symbol mapping) |
|
|
183
|
+
| Hangul jamo tables | [stannam/hangul_to_ipa](https://github.com/stannam/hangul_to_ipa) | — |
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "scriptconv"
|
|
7
|
+
dynamic = ["version", "dependencies"]
|
|
8
|
+
description = "Shared script-conversion core — ISO-15924 detection, IPA↔ARPA/X-SAMPA/Lexique, Buckwalter, Hangul→jamo"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "Apache-2.0"}
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 3 - Alpha",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"Intended Audience :: Science/Research",
|
|
16
|
+
"Topic :: Text Processing :: Linguistic",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"License :: OSI Approved :: Apache Software License",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
]
|
|
25
|
+
keywords = ["ipa", "arpabet", "x-sampa", "lexique", "buckwalter", "hangul", "script", "iso15924", "tts", "g2p", "phoneme"]
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.dynamic]
|
|
28
|
+
version = {attr = "scriptconv.version.VERSION_STR"}
|
|
29
|
+
dependencies = {file = ["requirements.txt"]}
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
test = ["pytest", "pytest-timeout"]
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://github.com/TigreGotico/scriptconv"
|
|
36
|
+
Issues = "https://github.com/TigreGotico/scriptconv/issues"
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.packages.find]
|
|
39
|
+
include = ["scriptconv*"]
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.package-data]
|
|
42
|
+
scriptconv = ["py.typed"]
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
testpaths = ["tests"]
|
|
File without changes
|