scriptconv 0.0.3a6__tar.gz → 0.0.3a8__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 (34) hide show
  1. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/PKG-INFO +1 -1
  2. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv/__init__.py +40 -0
  3. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv/__main__.py +76 -1
  4. scriptconv-0.0.3a8/scriptconv/conventions.py +536 -0
  5. scriptconv-0.0.3a8/scriptconv/graph.py +259 -0
  6. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv/notation.py +19 -28
  7. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv/readings.py +7 -2
  8. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv/translit.py +2 -0
  9. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv/version.py +1 -1
  10. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv.egg-info/PKG-INFO +1 -1
  11. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv.egg-info/SOURCES.txt +4 -0
  12. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/tests/test_cli.py +39 -0
  13. scriptconv-0.0.3a8/tests/test_conventions.py +238 -0
  14. scriptconv-0.0.3a8/tests/test_graph.py +132 -0
  15. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/LICENSE +0 -0
  16. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/README.md +0 -0
  17. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/pyproject.toml +0 -0
  18. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/requirements.txt +0 -0
  19. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv/cangjie.py +0 -0
  20. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv/data/__init__.py +0 -0
  21. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv/data/cangjie5_tc.tsv.gz +0 -0
  22. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv/py.typed +0 -0
  23. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv/scripts.py +0 -0
  24. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv.egg-info/dependency_links.txt +0 -0
  25. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv.egg-info/requires.txt +0 -0
  26. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/scriptconv.egg-info/top_level.txt +0 -0
  27. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/setup.cfg +0 -0
  28. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/tests/test_cangjie.py +0 -0
  29. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/tests/test_examples.py +0 -0
  30. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/tests/test_notation.py +0 -0
  31. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/tests/test_readings.py +0 -0
  32. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/tests/test_readings_zh.py +0 -0
  33. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/tests/test_scripts.py +0 -0
  34. {scriptconv-0.0.3a6 → scriptconv-0.0.3a8}/tests/test_translit.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptconv
3
- Version: 0.0.3a6
3
+ Version: 0.0.3a8
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
@@ -22,6 +22,14 @@ readings:
22
22
  extra; Chinese hanzi → pinyin/bopomofo via the ``zh`` extra).
23
23
  cangjie:
24
24
  Hanzi → Cangjie5 input codes (shape decomposition, vendored table).
25
+ graph:
26
+ Conversion-graph engine: representations (notations and orthographies)
27
+ as nodes, registered transforms as edges, lossless-preferring routing.
28
+ External packages extend graph instances explicitly.
29
+ conventions:
30
+ Orthographic conventions — script-scoped decorations orthogonal to
31
+ identity (tashkeel, niqqud, wakachigaki, pinyin tone spelling…).
32
+ Scripts are nodes; conventions are parameters, never nodes.
25
33
 
26
34
  Zero required runtime dependencies (stdlib only); the readings module
27
35
  needs the optional ``ja``/``zh`` extras.
@@ -75,6 +83,23 @@ from scriptconv.readings import (
75
83
  to_pinyin,
76
84
  to_bopomofo,
77
85
  )
86
+ from scriptconv.conventions import (
87
+ Convention,
88
+ Transition,
89
+ CONVENTION_REGISTRY,
90
+ conventions_for,
91
+ restyle,
92
+ strip,
93
+ apply,
94
+ detect as detect_convention,
95
+ )
96
+ from scriptconv.graph import (
97
+ Representation,
98
+ Edge,
99
+ ConversionGraph,
100
+ DEFAULT_GRAPH,
101
+ REPRESENTATIONS,
102
+ )
78
103
  from scriptconv.cangjie import (
79
104
  cangjie_code,
80
105
  to_cangjie,
@@ -123,6 +148,21 @@ __all__ = [
123
148
  "tokens",
124
149
  "to_hiragana",
125
150
  "to_katakana",
151
+ # conventions (orthographic decorations, orthogonal to script identity)
152
+ "Convention",
153
+ "Transition",
154
+ "CONVENTION_REGISTRY",
155
+ "conventions_for",
156
+ "restyle",
157
+ "strip",
158
+ "apply",
159
+ "detect_convention",
160
+ # graph (conversion routing engine over representations)
161
+ "Representation",
162
+ "Edge",
163
+ "ConversionGraph",
164
+ "DEFAULT_GRAPH",
165
+ "REPRESENTATIONS",
126
166
  # cangjie (vendored Cangjie5 table)
127
167
  "cangjie_code",
128
168
  "to_cangjie",
@@ -8,6 +8,10 @@ Usage
8
8
  python -m scriptconv direction <text>
9
9
  python -m scriptconv decompose <text>
10
10
  python -m scriptconv lang <code>
11
+ python -m scriptconv strip <convention> <text>
12
+ python -m scriptconv restyle <convention> <style> <text>
13
+ python -m scriptconv conventions [--script CODE]
14
+ python -m scriptconv route <src> <dst>
11
15
 
12
16
  Examples
13
17
  --------
@@ -48,6 +52,23 @@ def main(argv: list[str] | None = None) -> int:
48
52
  lang = sub.add_parser("lang", help="Map language code to script")
49
53
  lang.add_argument("code", help="BCP-47 or ISO 639 language code")
50
54
 
55
+ st = sub.add_parser("strip", help="Remove an orthographic convention's decoration")
56
+ st.add_argument("convention", help="Convention id (see `conventions`)")
57
+ st.add_argument("text", help="Text to strip")
58
+
59
+ rs = sub.add_parser("restyle", help="Rewrite text between a convention's styles")
60
+ rs.add_argument("convention", help="Convention id (see `conventions`)")
61
+ rs.add_argument("to", help="Target style")
62
+ rs.add_argument("text", help="Text to restyle")
63
+ rs.add_argument("--from", dest="frm", default=None, help="Source style")
64
+
65
+ cv = sub.add_parser("conventions", help="List orthographic conventions")
66
+ cv.add_argument("--script", default=None, help="Filter by ISO-15924 script code")
67
+
68
+ rt = sub.add_parser("route", help="Show the conversion path between representations")
69
+ rt.add_argument("src", help="Source representation id")
70
+ rt.add_argument("dst", help="Target representation id")
71
+
51
72
  args = p.parse_args(argv)
52
73
 
53
74
  if args.command is None:
@@ -61,6 +82,10 @@ def main(argv: list[str] | None = None) -> int:
61
82
  "direction": lambda: _do_direction(args),
62
83
  "decompose": lambda: _do_decompose(args),
63
84
  "lang": lambda: _do_lang(args),
85
+ "strip": lambda: _do_strip(args),
86
+ "restyle": lambda: _do_restyle(args),
87
+ "conventions": lambda: _do_conventions(args),
88
+ "route": lambda: _do_route(args),
64
89
  }
65
90
  dispatch[args.command]()
66
91
  return 0
@@ -70,9 +95,31 @@ def _do_convert(args: argparse.Namespace) -> None:
70
95
  from scriptconv.notation import Notation, convert
71
96
  try:
72
97
  print(convert(args.text, args.src, args.dst))
98
+ return
99
+ except ValueError:
100
+ pass
101
+ # not a notation pair — try any representation pair on the default graph
102
+ from scriptconv.graph import DEFAULT_GRAPH
103
+ try:
104
+ print(DEFAULT_GRAPH.convert(args.text, args.src, args.dst))
73
105
  except ValueError as e:
74
106
  valid = ", ".join(n.value for n in Notation)
75
- raise SystemExit(f"error: {e} (valid notations: {valid})")
107
+ raise SystemExit(f"error: {e} (valid notations: {valid}; "
108
+ f"graph nodes: {', '.join(DEFAULT_GRAPH.nodes)})")
109
+
110
+
111
+ def _do_route(args: argparse.Namespace) -> None:
112
+ from scriptconv.graph import DEFAULT_GRAPH
113
+ try:
114
+ path = DEFAULT_GRAPH.route(args.src, args.dst)
115
+ except ValueError as e:
116
+ raise SystemExit(f"error: {e}")
117
+ if not path:
118
+ print("(identity)")
119
+ for e in path:
120
+ flags = "lossless" if e.lossless else "lossy"
121
+ extra = f", needs scriptconv[{e.requires}]" if e.requires else ""
122
+ print(f" {e.src} -> {e.dst} ({flags}, cost {e.cost:g}{extra})")
76
123
 
77
124
 
78
125
  def _do_detect(args: argparse.Namespace) -> None:
@@ -100,6 +147,34 @@ def _do_decompose(args: argparse.Namespace) -> None:
100
147
  print(decompose_hangul(args.text))
101
148
 
102
149
 
150
+ def _do_strip(args: argparse.Namespace) -> None:
151
+ from scriptconv.conventions import strip
152
+ try:
153
+ print(strip(args.text, args.convention))
154
+ except ValueError as e:
155
+ raise SystemExit(f"error: {e}")
156
+
157
+
158
+ def _do_restyle(args: argparse.Namespace) -> None:
159
+ from scriptconv.conventions import restyle
160
+ try:
161
+ print(restyle(args.text, args.convention, args.to, frm=args.frm))
162
+ except ValueError as e:
163
+ raise SystemExit(f"error: {e}")
164
+
165
+
166
+ def _do_conventions(args: argparse.Namespace) -> None:
167
+ from scriptconv.conventions import CONVENTION_REGISTRY, conventions_for
168
+ convs = (conventions_for(args.script) if args.script
169
+ else list(CONVENTION_REGISTRY.values()))
170
+ if not convs:
171
+ print("(no conventions registered for that script)")
172
+ for c in convs:
173
+ system = f" [{c.system}]" if c.system else ""
174
+ print(f" {c.id}{system} scripts={','.join(c.scripts)} "
175
+ f"styles={','.join(c.styles)} — {c.name}")
176
+
177
+
103
178
  def _do_lang(args: argparse.Namespace) -> None:
104
179
  from scriptconv.scripts import lang_to_script
105
180
  print(lang_to_script(args.code) or "(unknown)")