scriptconv 0.0.1__py3-none-any.whl
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/__init__.py +95 -0
- scriptconv/__main__.py +109 -0
- scriptconv/notation.py +950 -0
- scriptconv/py.typed +0 -0
- scriptconv/scripts.py +818 -0
- scriptconv/translit.py +154 -0
- scriptconv/version.py +10 -0
- scriptconv-0.0.1.dist-info/METADATA +210 -0
- scriptconv-0.0.1.dist-info/RECORD +12 -0
- scriptconv-0.0.1.dist-info/WHEEL +5 -0
- scriptconv-0.0.1.dist-info/licenses/LICENSE +202 -0
- scriptconv-0.0.1.dist-info/top_level.txt +1 -0
scriptconv/__init__.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""scriptconv — a zero-dependency core for written-script operations.
|
|
2
|
+
|
|
3
|
+
Script identification and metadata, phoneme-notation transcoding, and
|
|
4
|
+
orthographic decomposition — no phonemization.
|
|
5
|
+
|
|
6
|
+
Modules
|
|
7
|
+
-------
|
|
8
|
+
scripts:
|
|
9
|
+
Writing-system identification and metadata. ISO-15924 script codes,
|
|
10
|
+
character-range detection, ``lang_to_script``, ``normalize_script_tag``,
|
|
11
|
+
``script_distribution``, ``script_runs``, ``base_direction``,
|
|
12
|
+
``script_to_langs``.
|
|
13
|
+
notation:
|
|
14
|
+
Phoneme-notation transcoding. IPA ↔ ARPABET, IPA ↔ X-SAMPA,
|
|
15
|
+
IPA ↔ Lexique, IPA ↔ Kirshenbaum, Buckwalter ↔ Arabic script.
|
|
16
|
+
``Notation`` enum, ``convert`` facade, ``NOTATION_INFO`` fidelity registry.
|
|
17
|
+
translit:
|
|
18
|
+
Script-level decomposition and transliteration (Hangul → jamo,
|
|
19
|
+
Hiragana ↔ Katakana).
|
|
20
|
+
|
|
21
|
+
Zero runtime dependencies (stdlib only).
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from scriptconv.scripts import (
|
|
25
|
+
Script,
|
|
26
|
+
SCRIPT_REGISTRY,
|
|
27
|
+
char_script,
|
|
28
|
+
detect_script,
|
|
29
|
+
script_distribution,
|
|
30
|
+
script_runs,
|
|
31
|
+
base_direction,
|
|
32
|
+
lang_to_script,
|
|
33
|
+
script_to_langs,
|
|
34
|
+
normalize_script_tag,
|
|
35
|
+
)
|
|
36
|
+
from scriptconv.notation import (
|
|
37
|
+
Notation,
|
|
38
|
+
NotationInfo,
|
|
39
|
+
NOTATION_INFO,
|
|
40
|
+
convert,
|
|
41
|
+
can_convert,
|
|
42
|
+
convert_batch,
|
|
43
|
+
arpa_to_ipa,
|
|
44
|
+
ipa_to_arpa,
|
|
45
|
+
xsampa_to_ipa,
|
|
46
|
+
ipa_to_xsampa,
|
|
47
|
+
buckwalter_to_arabic,
|
|
48
|
+
arabic_to_buckwalter,
|
|
49
|
+
lexique_to_ipa,
|
|
50
|
+
ipa_to_lexique,
|
|
51
|
+
kirshenbaum_to_ipa,
|
|
52
|
+
ipa_to_kirshenbaum,
|
|
53
|
+
looks_like_ipa,
|
|
54
|
+
)
|
|
55
|
+
from scriptconv.translit import (
|
|
56
|
+
decompose_hangul,
|
|
57
|
+
hira_to_kana,
|
|
58
|
+
kana_to_hira,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
__all__ = [
|
|
62
|
+
# scripts
|
|
63
|
+
"Script",
|
|
64
|
+
"SCRIPT_REGISTRY",
|
|
65
|
+
"char_script",
|
|
66
|
+
"detect_script",
|
|
67
|
+
"script_distribution",
|
|
68
|
+
"script_runs",
|
|
69
|
+
"base_direction",
|
|
70
|
+
"lang_to_script",
|
|
71
|
+
"script_to_langs",
|
|
72
|
+
"normalize_script_tag",
|
|
73
|
+
# notation
|
|
74
|
+
"Notation",
|
|
75
|
+
"NotationInfo",
|
|
76
|
+
"NOTATION_INFO",
|
|
77
|
+
"convert",
|
|
78
|
+
"can_convert",
|
|
79
|
+
"convert_batch",
|
|
80
|
+
"arpa_to_ipa",
|
|
81
|
+
"ipa_to_arpa",
|
|
82
|
+
"xsampa_to_ipa",
|
|
83
|
+
"ipa_to_xsampa",
|
|
84
|
+
"buckwalter_to_arabic",
|
|
85
|
+
"arabic_to_buckwalter",
|
|
86
|
+
"lexique_to_ipa",
|
|
87
|
+
"ipa_to_lexique",
|
|
88
|
+
"kirshenbaum_to_ipa",
|
|
89
|
+
"ipa_to_kirshenbaum",
|
|
90
|
+
"looks_like_ipa",
|
|
91
|
+
# translit
|
|
92
|
+
"decompose_hangul",
|
|
93
|
+
"hira_to_kana",
|
|
94
|
+
"kana_to_hira",
|
|
95
|
+
]
|
scriptconv/__main__.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""CLI interface for scriptconv.
|
|
2
|
+
|
|
3
|
+
Usage
|
|
4
|
+
-----
|
|
5
|
+
python -m scriptconv convert <src> <dst> <text>
|
|
6
|
+
python -m scriptconv detect <text>
|
|
7
|
+
python -m scriptconv distribution <text>
|
|
8
|
+
python -m scriptconv direction <text>
|
|
9
|
+
python -m scriptconv decompose <text>
|
|
10
|
+
python -m scriptconv lang <code>
|
|
11
|
+
|
|
12
|
+
Examples
|
|
13
|
+
--------
|
|
14
|
+
python -m scriptconv convert arpa ipa "HH AH0 L OW1"
|
|
15
|
+
python -m scriptconv detect "안녕하세요"
|
|
16
|
+
python -m scriptconv decompose "국민"
|
|
17
|
+
"""
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import argparse
|
|
21
|
+
import sys
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def main(argv: list[str] | None = None) -> int:
|
|
25
|
+
p = argparse.ArgumentParser(
|
|
26
|
+
prog="scriptconv",
|
|
27
|
+
description="Script and phoneme notation conversion tools.",
|
|
28
|
+
)
|
|
29
|
+
sub = p.add_subparsers(dest="command")
|
|
30
|
+
|
|
31
|
+
conv = sub.add_parser("convert", help="Convert text between notations")
|
|
32
|
+
conv.add_argument("src", help="Source notation")
|
|
33
|
+
conv.add_argument("dst", help="Destination notation")
|
|
34
|
+
conv.add_argument("text", help="Text to convert")
|
|
35
|
+
|
|
36
|
+
det = sub.add_parser("detect", help="Detect dominant script")
|
|
37
|
+
det.add_argument("text", help="Text to analyse")
|
|
38
|
+
|
|
39
|
+
dist = sub.add_parser("distribution", help="Show script character counts")
|
|
40
|
+
dist.add_argument("text", help="Text to analyse")
|
|
41
|
+
|
|
42
|
+
dirc = sub.add_parser("direction", help="Detect base text direction")
|
|
43
|
+
dirc.add_argument("text", help="Text to analyse")
|
|
44
|
+
|
|
45
|
+
decomp = sub.add_parser("decompose", help="Decompose Hangul into jamo")
|
|
46
|
+
decomp.add_argument("text", help="Text to decompose")
|
|
47
|
+
|
|
48
|
+
lang = sub.add_parser("lang", help="Map language code to script")
|
|
49
|
+
lang.add_argument("code", help="BCP-47 or ISO 639 language code")
|
|
50
|
+
|
|
51
|
+
args = p.parse_args(argv)
|
|
52
|
+
|
|
53
|
+
if args.command is None:
|
|
54
|
+
p.print_help()
|
|
55
|
+
return 1
|
|
56
|
+
|
|
57
|
+
dispatch = {
|
|
58
|
+
"convert": lambda: _do_convert(args),
|
|
59
|
+
"detect": lambda: _do_detect(args),
|
|
60
|
+
"distribution": lambda: _do_distribution(args),
|
|
61
|
+
"direction": lambda: _do_direction(args),
|
|
62
|
+
"decompose": lambda: _do_decompose(args),
|
|
63
|
+
"lang": lambda: _do_lang(args),
|
|
64
|
+
}
|
|
65
|
+
dispatch[args.command]()
|
|
66
|
+
return 0
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _do_convert(args: argparse.Namespace) -> None:
|
|
70
|
+
from scriptconv.notation import Notation, convert
|
|
71
|
+
try:
|
|
72
|
+
print(convert(args.text, args.src, args.dst))
|
|
73
|
+
except ValueError as e:
|
|
74
|
+
valid = ", ".join(n.value for n in Notation)
|
|
75
|
+
raise SystemExit(f"error: {e} (valid notations: {valid})")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _do_detect(args: argparse.Namespace) -> None:
|
|
79
|
+
from scriptconv.scripts import detect_script
|
|
80
|
+
print(detect_script(args.text) or "(none)")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _do_distribution(args: argparse.Namespace) -> None:
|
|
84
|
+
from scriptconv.scripts import script_distribution
|
|
85
|
+
dist = script_distribution(args.text)
|
|
86
|
+
if not dist:
|
|
87
|
+
print("(no script-bearing characters)")
|
|
88
|
+
else:
|
|
89
|
+
for code, count in dist.items():
|
|
90
|
+
print(f" {code}: {count}")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _do_direction(args: argparse.Namespace) -> None:
|
|
94
|
+
from scriptconv.scripts import base_direction
|
|
95
|
+
print(base_direction(args.text))
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _do_decompose(args: argparse.Namespace) -> None:
|
|
99
|
+
from scriptconv.translit import decompose_hangul
|
|
100
|
+
print(decompose_hangul(args.text))
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _do_lang(args: argparse.Namespace) -> None:
|
|
104
|
+
from scriptconv.scripts import lang_to_script
|
|
105
|
+
print(lang_to_script(args.code) or "(unknown)")
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
if __name__ == "__main__":
|
|
109
|
+
sys.exit(main())
|