scriptconv 0.0.3a13__tar.gz → 0.0.3a15__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.
Files changed (80) hide show
  1. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/PKG-INFO +1 -1
  2. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/__main__.py +18 -0
  3. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/__init__.py +4 -0
  4. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/base.py +7 -4
  5. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/registry.py +39 -0
  6. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/version.py +1 -1
  7. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv.egg-info/PKG-INFO +1 -1
  8. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_phonemizers_base.py +44 -0
  9. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/LICENSE +0 -0
  10. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/README.md +0 -0
  11. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/pyproject.toml +0 -0
  12. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/requirements.txt +0 -0
  13. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/__init__.py +0 -0
  14. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/cangjie.py +0 -0
  15. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/conventions.py +0 -0
  16. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/data/__init__.py +0 -0
  17. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/data/cangjie5_tc.tsv.gz +0 -0
  18. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/graph.py +0 -0
  19. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/notation.py +0 -0
  20. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/__init__.py +0 -0
  21. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/bw2ipa.py +0 -0
  22. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/hangul2ipa.py +0 -0
  23. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/ko_tables/aspiration.csv +0 -0
  24. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/ko_tables/assimilation.csv +0 -0
  25. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/ko_tables/double_coda.csv +0 -0
  26. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/ko_tables/hanja.tsv +0 -0
  27. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/ko_tables/ipa.csv +0 -0
  28. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/ko_tables/neutralization.csv +0 -0
  29. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/ko_tables/tensification.csv +0 -0
  30. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/ko_tables/yale.csv +0 -0
  31. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/shami/__init__.py +0 -0
  32. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/shami/codeswitch.py +0 -0
  33. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/shami/diacritize.py +0 -0
  34. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/shami/dialectal.py +0 -0
  35. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/shami/english_g2p.py +0 -0
  36. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/shami/espeak.py +0 -0
  37. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/shami/frontend.py +0 -0
  38. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/shami/levantine_g2p.py +0 -0
  39. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/shami/normalize.py +0 -0
  40. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/shami/phoneme_inventory.py +0 -0
  41. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/_thirdparty/zh_num.py +0 -0
  42. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/ar.py +0 -0
  43. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/en.py +0 -0
  44. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/enums.py +0 -0
  45. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/eu.py +0 -0
  46. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/fa.py +0 -0
  47. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/gl.py +0 -0
  48. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/he.py +0 -0
  49. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/ja.py +0 -0
  50. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/ko.py +0 -0
  51. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/mul.py +0 -0
  52. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/mwl.py +0 -0
  53. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/o2ipa.py +0 -0
  54. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/pt.py +0 -0
  55. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/shami.py +0 -0
  56. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/vi.py +0 -0
  57. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/phonemizers/zh.py +0 -0
  58. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/py.typed +0 -0
  59. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/readings.py +0 -0
  60. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/scripts.py +0 -0
  61. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv/translit.py +0 -0
  62. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv.egg-info/SOURCES.txt +0 -0
  63. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv.egg-info/dependency_links.txt +0 -0
  64. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv.egg-info/requires.txt +0 -0
  65. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/scriptconv.egg-info/top_level.txt +0 -0
  66. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/setup.cfg +0 -0
  67. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_arpa_stress.py +0 -0
  68. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_cangjie.py +0 -0
  69. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_cli.py +0 -0
  70. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_conventions.py +0 -0
  71. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_errors_policy.py +0 -0
  72. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_examples.py +0 -0
  73. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_graph.py +0 -0
  74. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_notation.py +0 -0
  75. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_phonemizers_cjk_ar.py +0 -0
  76. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_readings.py +0 -0
  77. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_readings_zh.py +0 -0
  78. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_scripts.py +0 -0
  79. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_scripts_stressonnx_compat.py +0 -0
  80. {scriptconv-0.0.3a13 → scriptconv-0.0.3a15}/tests/test_translit.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptconv
3
- Version: 0.0.3a13
3
+ Version: 0.0.3a15
4
4
  Summary: Zero-dependency script & phoneme-notation core — ISO-15924 detection & metadata, IPA↔ARPABET/X-SAMPA/Lexique/Kirshenbaum/Cotovía/RFE, Buckwalter↔Arabic, Hangul→jamo, kana
5
5
  License: Apache-2.0
6
6
  Project-URL: Homepage, https://github.com/TigreGotico/scriptconv
@@ -12,6 +12,7 @@ Usage
12
12
  python -m scriptconv restyle <convention> <style> <text>
13
13
  python -m scriptconv conventions [--script CODE]
14
14
  python -m scriptconv route <src> <dst>
15
+ python -m scriptconv phonemize <lang> <text> [--phonemizer ID] [--alphabet A]
15
16
 
16
17
  Examples
17
18
  --------
@@ -69,6 +70,12 @@ def main(argv: list[str] | None = None) -> int:
69
70
  rt.add_argument("src", help="Source representation id")
70
71
  rt.add_argument("dst", help="Target representation id")
71
72
 
73
+ ph = sub.add_parser("phonemize", help="Phonemize text (per-language default backend)")
74
+ ph.add_argument("lang", help="Language code")
75
+ ph.add_argument("text", help="Text to phonemize")
76
+ ph.add_argument("--phonemizer", default=None, help="Backend override (Phonemizer value)")
77
+ ph.add_argument("--alphabet", default="ipa", help="Output alphabet (default ipa)")
78
+
72
79
  args = p.parse_args(argv)
73
80
 
74
81
  if args.command is None:
@@ -86,6 +93,7 @@ def main(argv: list[str] | None = None) -> int:
86
93
  "restyle": lambda: _do_restyle(args),
87
94
  "conventions": lambda: _do_conventions(args),
88
95
  "route": lambda: _do_route(args),
96
+ "phonemize": lambda: _do_phonemize(args),
89
97
  }
90
98
  dispatch[args.command]()
91
99
  return 0
@@ -108,6 +116,16 @@ def _do_convert(args: argparse.Namespace) -> None:
108
116
  f"graph nodes: {', '.join(DEFAULT_GRAPH.nodes)})")
109
117
 
110
118
 
119
+ def _do_phonemize(args: argparse.Namespace) -> None:
120
+ from scriptconv.phonemizers import Alphabet, Phonemizer, phonemize
121
+ try:
122
+ override = Phonemizer(args.phonemizer) if args.phonemizer else None
123
+ print(phonemize(args.text, args.lang, Alphabet(args.alphabet),
124
+ override=override))
125
+ except (ValueError, ImportError) as e:
126
+ raise SystemExit(f"error: {e}")
127
+
128
+
111
129
  def _do_route(args: argparse.Namespace) -> None:
112
130
  from scriptconv.graph import DEFAULT_GRAPH
113
131
  try:
@@ -21,6 +21,8 @@ from scriptconv.phonemizers.registry import (
21
21
  get_phonemizer,
22
22
  get_phonemizer_class,
23
23
  phonemizer_for_lang,
24
+ phonemize,
25
+ register,
24
26
  )
25
27
 
26
28
  __all__ = [
@@ -37,4 +39,6 @@ __all__ = [
37
39
  "get_phonemizer",
38
40
  "get_phonemizer_class",
39
41
  "phonemizer_for_lang",
42
+ "phonemize",
43
+ "register",
40
44
  ]
@@ -45,8 +45,9 @@ class BasePhonemizer(metaclass=abc.ABCMeta):
45
45
  # optional (text, lang) -> str hook run before chunking; see module
46
46
  # docstring — scriptconv performs no normalization of its own
47
47
  self.normalizer = normalizer
48
- # local path to a phonikud ONNX model (Hebrew diacritization);
49
- # scriptconv never downloads the consumer resolves the file
48
+ # local path to a phonikud ONNX model (Hebrew diacritization), or a
49
+ # zero-arg callable resolving one lazily; scriptconv never downloads
50
+ # — the consumer resolves the file
50
51
  self.phonikud_model = phonikud_model
51
52
 
52
53
  # diacritizer model name, for languages that need one. Arabic uses
@@ -59,7 +60,9 @@ class BasePhonemizer(metaclass=abc.ABCMeta):
59
60
  @property
60
61
  def phonikud(self):
61
62
  if self._phonikud is None:
62
- if not self.phonikud_model:
63
+ model = self.phonikud_model() if callable(self.phonikud_model) \
64
+ else self.phonikud_model
65
+ if not model:
63
66
  raise ValueError(
64
67
  "Hebrew diacritization needs a local phonikud ONNX model: "
65
68
  "pass phonikud_model=<path> (scriptconv never downloads "
@@ -70,7 +73,7 @@ class BasePhonemizer(metaclass=abc.ABCMeta):
70
73
  raise ImportError(
71
74
  "Hebrew diacritization needs phonikud-onnx — install "
72
75
  "with `pip install scriptconv[he]`") from None
73
- self._phonikud = Phonikud(self.phonikud_model)
76
+ self._phonikud = Phonikud(model)
74
77
  return self._phonikud
75
78
 
76
79
  def tashkeel(self, model: Optional[str] = None):
@@ -158,3 +158,42 @@ def phonemizer_for_lang(lang: str, alphabet: Alphabet = Alphabet.IPA,
158
158
  if alphabet in _EMITS.get(candidate, (Alphabet.IPA,)):
159
159
  return get_phonemizer(candidate, alphabet, model, **kwargs)
160
160
  return get_phonemizer(_P.ESPEAK, alphabet, model, **kwargs)
161
+
162
+
163
+ def phonemize(text: str, lang: str, alphabet: Alphabet = Alphabet.IPA,
164
+ override: Optional[Phonemizer] = None,
165
+ model: Optional[str] = None, **kwargs) -> str:
166
+ """One-call facade: phonemize *text* with the language's default backend.
167
+
168
+ Equivalent to ``phonemizer_for_lang(...).phonemize_string(text, lang)``.
169
+ Construct the phonemizer yourself when phonemizing repeatedly — backends
170
+ cache models/dictionaries per instance.
171
+ """
172
+ return phonemizer_for_lang(lang, alphabet, override, model,
173
+ **kwargs).phonemize_string(text, lang)
174
+
175
+
176
+ def register(graph) -> None:
177
+ """Opt-in graph integration: add the phonemization edge to *graph*.
178
+
179
+ Adds the ``"text"`` representation — meaningful only with ``lang=``
180
+ routing context, and present only in graphs that opted in (the
181
+ :data:`scriptconv.graph.DEFAULT_GRAPH` stays orthography-only by
182
+ design) — and one dispatching ``text -> ipa`` edge that resolves the
183
+ per-language default (honouring an ``override=`` context key).
184
+
185
+ Usage::
186
+
187
+ from scriptconv.graph import DEFAULT_GRAPH
188
+ from scriptconv import phonemizers
189
+ g = DEFAULT_GRAPH.extend(phonemizers.register)
190
+ g.convert("bom dia", "text", "ipa", lang="pt")
191
+ """
192
+ from scriptconv.graph import Edge
193
+
194
+ def _text_to_ipa(text: str, lang: str = "und",
195
+ override: Optional[Phonemizer] = None, **_):
196
+ return phonemizer_for_lang(lang, Alphabet.IPA,
197
+ override).phonemize_string(text, lang)
198
+
199
+ graph.register(Edge("text", "ipa", _text_to_ipa, lossless=False))
@@ -2,7 +2,7 @@
2
2
  VERSION_MAJOR = 0
3
3
  VERSION_MINOR = 0
4
4
  VERSION_BUILD = 3
5
- VERSION_ALPHA = 13
5
+ VERSION_ALPHA = 15
6
6
  # END_VERSION_BLOCK
7
7
 
8
8
  VERSION_STR = f"{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_BUILD}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptconv
3
- Version: 0.0.3a13
3
+ Version: 0.0.3a15
4
4
  Summary: Zero-dependency script & phoneme-notation core — ISO-15924 detection & metadata, IPA↔ARPABET/X-SAMPA/Lexique/Kirshenbaum/Cotovía/RFE, Buckwalter↔Arabic, Hangul→jamo, kana
5
5
  License: Apache-2.0
6
6
  Project-URL: Homepage, https://github.com/TigreGotico/scriptconv
@@ -130,3 +130,47 @@ class TestByT5NoNetwork(unittest.TestCase):
130
130
 
131
131
  if __name__ == "__main__":
132
132
  unittest.main()
133
+
134
+
135
+ class TestFacadeAndGraph(unittest.TestCase):
136
+ def test_phonemize_facade(self):
137
+ from scriptconv.phonemizers import phonemize
138
+ out = phonemize("hola", "es", override=Phonemizer.GRAPHEMES)
139
+ self.assertEqual(out, "hola")
140
+
141
+ def test_register_is_opt_in_default_graph_untouched(self):
142
+ from scriptconv.graph import DEFAULT_GRAPH
143
+ from scriptconv import phonemizers
144
+ self.assertNotIn("text", DEFAULT_GRAPH.nodes)
145
+ g = DEFAULT_GRAPH.extend(phonemizers.register)
146
+ self.assertIn("text", g.nodes)
147
+ self.assertNotIn("text", DEFAULT_GRAPH.nodes)
148
+
149
+ def test_graph_edge_dispatches_with_override(self):
150
+ from scriptconv.graph import DEFAULT_GRAPH
151
+ from scriptconv import phonemizers
152
+ g = DEFAULT_GRAPH.extend(phonemizers.register)
153
+ out = g.convert("abc", "text", "ipa", lang="en",
154
+ override=Phonemizer.GRAPHEMES)
155
+ self.assertEqual(out, "abc")
156
+
157
+ def test_graph_edge_chains_to_arpa(self):
158
+ from scriptconv.graph import DEFAULT_GRAPH
159
+ from scriptconv import phonemizers
160
+ g = DEFAULT_GRAPH.extend(phonemizers.register)
161
+ self.assertTrue(g.can_convert("text", "arpa"))
162
+
163
+
164
+ class TestPhonikudModelResolver(unittest.TestCase):
165
+ def test_callable_resolver_invoked_lazily(self):
166
+ calls = []
167
+
168
+ def resolver():
169
+ calls.append(1)
170
+ return "" # resolves to nothing -> still the explicit ValueError
171
+
172
+ g = GraphemePhonemizer(phonikud_model=resolver)
173
+ self.assertEqual(calls, []) # not resolved at construction
174
+ with self.assertRaises(ValueError):
175
+ g.add_diacritics("שלום", "he")
176
+ self.assertEqual(calls, [1])
File without changes
File without changes
File without changes