scriptconv 0.0.2a2__tar.gz → 0.0.3a2__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 (26) hide show
  1. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/PKG-INFO +21 -9
  2. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/README.md +15 -6
  3. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/pyproject.toml +8 -3
  4. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/scriptconv/__init__.py +12 -1
  5. scriptconv-0.0.3a2/scriptconv/readings.py +71 -0
  6. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/scriptconv/version.py +1 -1
  7. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/scriptconv.egg-info/PKG-INFO +21 -9
  8. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/scriptconv.egg-info/SOURCES.txt +2 -0
  9. scriptconv-0.0.3a2/scriptconv.egg-info/requires.txt +8 -0
  10. scriptconv-0.0.3a2/tests/test_readings.py +73 -0
  11. scriptconv-0.0.2a2/scriptconv.egg-info/requires.txt +0 -4
  12. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/LICENSE +0 -0
  13. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/requirements.txt +0 -0
  14. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/scriptconv/__main__.py +0 -0
  15. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/scriptconv/notation.py +0 -0
  16. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/scriptconv/py.typed +0 -0
  17. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/scriptconv/scripts.py +0 -0
  18. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/scriptconv/translit.py +0 -0
  19. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/scriptconv.egg-info/dependency_links.txt +0 -0
  20. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/scriptconv.egg-info/top_level.txt +0 -0
  21. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/setup.cfg +0 -0
  22. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/tests/test_cli.py +0 -0
  23. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/tests/test_examples.py +0 -0
  24. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/tests/test_notation.py +0 -0
  25. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/tests/test_scripts.py +0 -0
  26. {scriptconv-0.0.2a2 → scriptconv-0.0.3a2}/tests/test_translit.py +0 -0
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptconv
3
- Version: 0.0.2a2
4
- Summary: Shared script-conversion core — ISO-15924 detection, IPA↔ARPA/X-SAMPA/Lexique, Buckwalter, Hangul→jamo
3
+ Version: 0.0.3a2
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
7
7
  Project-URL: Issues, https://github.com/TigreGotico/scriptconv/issues
8
- Keywords: ipa,arpabet,x-sampa,lexique,buckwalter,hangul,script,iso15924,tts,g2p,phoneme
8
+ Keywords: ipa,arpabet,x-sampa,kirshenbaum,cotovia,rfe,lexique,buckwalter,hangul,jamo,kana,transliteration,notation,phoneme,phonetic-alphabet,script,iso15924,unicode,tts,g2p
9
9
  Classifier: Development Status :: 3 - Alpha
10
10
  Classifier: Intended Audience :: Developers
11
11
  Classifier: Intended Audience :: Science/Research
@@ -20,9 +20,12 @@ Classifier: Operating System :: OS Independent
20
20
  Requires-Python: >=3.10
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
+ Provides-Extra: ja
24
+ Requires-Dist: pykakasi<3,>=2.3; extra == "ja"
23
25
  Provides-Extra: test
24
26
  Requires-Dist: pytest; extra == "test"
25
27
  Requires-Dist: pytest-timeout; extra == "test"
28
+ Requires-Dist: pykakasi<3,>=2.3; extra == "test"
26
29
  Dynamic: license-file
27
30
 
28
31
  # scriptconv
@@ -31,12 +34,21 @@ Dynamic: license-file
31
34
  [![Build Tests](https://github.com/TigreGotico/scriptconv/actions/workflows/build-tests.yml/badge.svg?branch=dev)](https://github.com/TigreGotico/scriptconv/actions/workflows/build-tests.yml)
32
35
  [![PyPI version](https://img.shields.io/pypi/v/scriptconv.svg)](https://pypi.org/project/scriptconv/)
33
36
 
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 / Lexique / Kirshenbaum / Cotovía / RFE,
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.
37
+ **scriptconv** is a zero-dependency Python library for written-script and
38
+ phoneme-notation operations:
39
+
40
+ - **Script identification & metadata** ISO-15924 detection, character-range
41
+ lookup, typological `script_type`, base direction, mixed-script segmentation
42
+ (`script_runs`), and language script mapping.
43
+ - **Phoneme-notation transcoding** — IPA ↔ ARPABET, X-SAMPA, Lexique,
44
+ Kirshenbaum, Cotovía and RFE, routed through IPA, with queryable per-notation
45
+ fidelity metadata (`NOTATION_INFO`) and a `looks_like_ipa` detector.
46
+ - **Script transliteration & decomposition** — Buckwalter ↔ Arabic script,
47
+ Hangul → jamo (compatibility or conjoining), Hiragana ↔ Katakana.
48
+
49
+ Every conversion is a pure data table or arithmetic operation — **no
50
+ phonemization**, no linguistic rules, no external files, and no runtime
51
+ dependencies beyond the Python standard library.
40
52
 
41
53
  Transcoding is reversible where the target inventory permits — see
42
54
  [Fidelity guarantees](#fidelity-guarantees) for the exact per-notation guarantees.
@@ -4,12 +4,21 @@
4
4
  [![Build Tests](https://github.com/TigreGotico/scriptconv/actions/workflows/build-tests.yml/badge.svg?branch=dev)](https://github.com/TigreGotico/scriptconv/actions/workflows/build-tests.yml)
5
5
  [![PyPI version](https://img.shields.io/pypi/v/scriptconv.svg)](https://pypi.org/project/scriptconv/)
6
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 / Lexique / Kirshenbaum / Cotovía / RFE,
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.
7
+ **scriptconv** is a zero-dependency Python library for written-script and
8
+ phoneme-notation operations:
9
+
10
+ - **Script identification & metadata** ISO-15924 detection, character-range
11
+ lookup, typological `script_type`, base direction, mixed-script segmentation
12
+ (`script_runs`), and language script mapping.
13
+ - **Phoneme-notation transcoding** — IPA ↔ ARPABET, X-SAMPA, Lexique,
14
+ Kirshenbaum, Cotovía and RFE, routed through IPA, with queryable per-notation
15
+ fidelity metadata (`NOTATION_INFO`) and a `looks_like_ipa` detector.
16
+ - **Script transliteration & decomposition** — Buckwalter ↔ Arabic script,
17
+ Hangul → jamo (compatibility or conjoining), Hiragana ↔ Katakana.
18
+
19
+ Every conversion is a pure data table or arithmetic operation — **no
20
+ phonemization**, no linguistic rules, no external files, and no runtime
21
+ dependencies beyond the Python standard library.
13
22
 
14
23
  Transcoding is reversible where the target inventory permits — see
15
24
  [Fidelity guarantees](#fidelity-guarantees) for the exact per-notation guarantees.
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
  [project]
6
6
  name = "scriptconv"
7
7
  dynamic = ["version", "dependencies"]
8
- description = "Shared script-conversion core — ISO-15924 detection, IPA↔ARPA/X-SAMPA/Lexique, Buckwalter, Hangul→jamo"
8
+ description = "Zero-dependency script & phoneme-notation core — ISO-15924 detection & metadata, IPA↔ARPABET/X-SAMPA/Lexique/Kirshenbaum/Cotovía/RFE, Buckwalter↔Arabic, Hangul→jamo, kana"
9
9
  readme = "README.md"
10
10
  license = {text = "Apache-2.0"}
11
11
  requires-python = ">=3.10"
@@ -22,14 +22,19 @@ classifiers = [
22
22
  "License :: OSI Approved :: Apache Software License",
23
23
  "Operating System :: OS Independent",
24
24
  ]
25
- keywords = ["ipa", "arpabet", "x-sampa", "lexique", "buckwalter", "hangul", "script", "iso15924", "tts", "g2p", "phoneme"]
25
+ keywords = [
26
+ "ipa", "arpabet", "x-sampa", "kirshenbaum", "cotovia", "rfe", "lexique",
27
+ "buckwalter", "hangul", "jamo", "kana", "transliteration", "notation",
28
+ "phoneme", "phonetic-alphabet", "script", "iso15924", "unicode", "tts", "g2p",
29
+ ]
26
30
 
27
31
  [tool.setuptools.dynamic]
28
32
  version = {attr = "scriptconv.version.VERSION_STR"}
29
33
  dependencies = {file = ["requirements.txt"]}
30
34
 
31
35
  [project.optional-dependencies]
32
- test = ["pytest", "pytest-timeout"]
36
+ ja = ["pykakasi>=2.3,<3"]
37
+ test = ["pytest", "pytest-timeout", "pykakasi>=2.3,<3"]
33
38
 
34
39
  [project.urls]
35
40
  Homepage = "https://github.com/TigreGotico/scriptconv"
@@ -17,8 +17,12 @@ notation:
17
17
  translit:
18
18
  Script-level decomposition and transliteration (Hangul → jamo,
19
19
  Hiragana ↔ Katakana).
20
+ readings:
21
+ Dictionary-backed respelling (Japanese kanji → kana). Needs the
22
+ optional ``pykakasi`` dependency (``pip install scriptconv[ja]``).
20
23
 
21
- Zero runtime dependencies (stdlib only).
24
+ Zero required runtime dependencies (stdlib only); the readings module
25
+ needs the optional ``ja`` extra.
22
26
  """
23
27
 
24
28
  from scriptconv.scripts import (
@@ -61,6 +65,10 @@ from scriptconv.translit import (
61
65
  hira_to_kana,
62
66
  kana_to_hira,
63
67
  )
68
+ from scriptconv.readings import (
69
+ to_hiragana,
70
+ to_katakana,
71
+ )
64
72
 
65
73
  __all__ = [
66
74
  # scripts
@@ -100,4 +108,7 @@ __all__ = [
100
108
  "decompose_hangul",
101
109
  "hira_to_kana",
102
110
  "kana_to_hira",
111
+ # readings (dictionary-backed, needs scriptconv[ja])
112
+ "to_hiragana",
113
+ "to_katakana",
103
114
  ]
@@ -0,0 +1,71 @@
1
+ """Dictionary-backed script respelling (Japanese kanji → kana).
2
+
3
+ Unlike the table-driven modules (:mod:`scriptconv.translit`,
4
+ :mod:`scriptconv.notation`), converting kanji to kana is not a codepoint
5
+ mapping: a kanji's kana spelling is a *lexical* property resolved against a
6
+ reading dictionary, and genuinely ambiguous readings are decided by the
7
+ dictionary's segmentation. This is still orthography — the output is how the
8
+ word is written in kana, exactly as an IME or furigana would render it — not
9
+ phonemization; no sound rules are applied.
10
+
11
+ Because it needs a reading dictionary, this module requires the optional
12
+ ``pykakasi`` dependency (``pip install scriptconv[ja]``). Importing the
13
+ module is always safe; the dependency is resolved on first conversion and a
14
+ missing dictionary raises :class:`ImportError` rather than silently returning
15
+ unconverted text.
16
+ """
17
+ from __future__ import annotations
18
+
19
+ __all__ = ["to_hiragana", "to_katakana"]
20
+
21
+ _kakasi = None
22
+
23
+ _HIRA = range(0x3040, 0x30A0)
24
+ _KANA = range(0x30A0, 0x3100)
25
+
26
+
27
+ def _converter():
28
+ global _kakasi
29
+ if _kakasi is None:
30
+ try:
31
+ import pykakasi
32
+ except ImportError:
33
+ raise ImportError(
34
+ "kanji→kana conversion needs the reading dictionary from "
35
+ "pykakasi — install with `pip install scriptconv[ja]`"
36
+ ) from None
37
+ _kakasi = pykakasi.kakasi()
38
+ return _kakasi
39
+
40
+
41
+ def to_hiragana(text: str, keep_katakana: bool = False) -> str:
42
+ """Respell Japanese text in hiragana.
43
+
44
+ Kanji are resolved to their dictionary reading; existing kana and any
45
+ non-Japanese characters pass through. With ``keep_katakana=True``,
46
+ katakana tokens keep their original script (useful when katakana marks
47
+ loanwords deliberately) instead of being folded into hiragana.
48
+ """
49
+ out = []
50
+ for token in _converter().convert(text):
51
+ orig = token["orig"]
52
+ if keep_katakana and orig and all(ord(c) in _KANA or not _is_japanese(c)
53
+ for c in orig):
54
+ out.append(orig)
55
+ else:
56
+ out.append(token["hira"])
57
+ return "".join(out)
58
+
59
+
60
+ def to_katakana(text: str) -> str:
61
+ """Respell Japanese text in katakana.
62
+
63
+ Kanji are resolved to their dictionary reading; existing kana are
64
+ transposed to katakana and any non-Japanese characters pass through.
65
+ """
66
+ return "".join(token["kana"] for token in _converter().convert(text))
67
+
68
+
69
+ def _is_japanese(ch: str) -> bool:
70
+ cp = ord(ch)
71
+ return cp in _HIRA or cp in _KANA or 0x4E00 <= cp <= 0x9FFF
@@ -1,7 +1,7 @@
1
1
  # START_VERSION_BLOCK
2
2
  VERSION_MAJOR = 0
3
3
  VERSION_MINOR = 0
4
- VERSION_BUILD = 2
4
+ VERSION_BUILD = 3
5
5
  VERSION_ALPHA = 2
6
6
  # END_VERSION_BLOCK
7
7
 
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptconv
3
- Version: 0.0.2a2
4
- Summary: Shared script-conversion core — ISO-15924 detection, IPA↔ARPA/X-SAMPA/Lexique, Buckwalter, Hangul→jamo
3
+ Version: 0.0.3a2
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
7
7
  Project-URL: Issues, https://github.com/TigreGotico/scriptconv/issues
8
- Keywords: ipa,arpabet,x-sampa,lexique,buckwalter,hangul,script,iso15924,tts,g2p,phoneme
8
+ Keywords: ipa,arpabet,x-sampa,kirshenbaum,cotovia,rfe,lexique,buckwalter,hangul,jamo,kana,transliteration,notation,phoneme,phonetic-alphabet,script,iso15924,unicode,tts,g2p
9
9
  Classifier: Development Status :: 3 - Alpha
10
10
  Classifier: Intended Audience :: Developers
11
11
  Classifier: Intended Audience :: Science/Research
@@ -20,9 +20,12 @@ Classifier: Operating System :: OS Independent
20
20
  Requires-Python: >=3.10
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
+ Provides-Extra: ja
24
+ Requires-Dist: pykakasi<3,>=2.3; extra == "ja"
23
25
  Provides-Extra: test
24
26
  Requires-Dist: pytest; extra == "test"
25
27
  Requires-Dist: pytest-timeout; extra == "test"
28
+ Requires-Dist: pykakasi<3,>=2.3; extra == "test"
26
29
  Dynamic: license-file
27
30
 
28
31
  # scriptconv
@@ -31,12 +34,21 @@ Dynamic: license-file
31
34
  [![Build Tests](https://github.com/TigreGotico/scriptconv/actions/workflows/build-tests.yml/badge.svg?branch=dev)](https://github.com/TigreGotico/scriptconv/actions/workflows/build-tests.yml)
32
35
  [![PyPI version](https://img.shields.io/pypi/v/scriptconv.svg)](https://pypi.org/project/scriptconv/)
33
36
 
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 / Lexique / Kirshenbaum / Cotovía / RFE,
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.
37
+ **scriptconv** is a zero-dependency Python library for written-script and
38
+ phoneme-notation operations:
39
+
40
+ - **Script identification & metadata** ISO-15924 detection, character-range
41
+ lookup, typological `script_type`, base direction, mixed-script segmentation
42
+ (`script_runs`), and language script mapping.
43
+ - **Phoneme-notation transcoding** — IPA ↔ ARPABET, X-SAMPA, Lexique,
44
+ Kirshenbaum, Cotovía and RFE, routed through IPA, with queryable per-notation
45
+ fidelity metadata (`NOTATION_INFO`) and a `looks_like_ipa` detector.
46
+ - **Script transliteration & decomposition** — Buckwalter ↔ Arabic script,
47
+ Hangul → jamo (compatibility or conjoining), Hiragana ↔ Katakana.
48
+
49
+ Every conversion is a pure data table or arithmetic operation — **no
50
+ phonemization**, no linguistic rules, no external files, and no runtime
51
+ dependencies beyond the Python standard library.
40
52
 
41
53
  Transcoding is reversible where the target inventory permits — see
42
54
  [Fidelity guarantees](#fidelity-guarantees) for the exact per-notation guarantees.
@@ -6,6 +6,7 @@ scriptconv/__init__.py
6
6
  scriptconv/__main__.py
7
7
  scriptconv/notation.py
8
8
  scriptconv/py.typed
9
+ scriptconv/readings.py
9
10
  scriptconv/scripts.py
10
11
  scriptconv/translit.py
11
12
  scriptconv/version.py
@@ -17,5 +18,6 @@ scriptconv.egg-info/top_level.txt
17
18
  tests/test_cli.py
18
19
  tests/test_examples.py
19
20
  tests/test_notation.py
21
+ tests/test_readings.py
20
22
  tests/test_scripts.py
21
23
  tests/test_translit.py
@@ -0,0 +1,8 @@
1
+
2
+ [ja]
3
+ pykakasi<3,>=2.3
4
+
5
+ [test]
6
+ pytest
7
+ pytest-timeout
8
+ pykakasi<3,>=2.3
@@ -0,0 +1,73 @@
1
+ import sys
2
+ import unittest
3
+ from unittest import mock
4
+
5
+ from scriptconv import to_hiragana, to_katakana
6
+ from scriptconv import readings
7
+
8
+
9
+ class TestToHiragana(unittest.TestCase):
10
+ def test_kanji_resolved_to_reading(self):
11
+ self.assertEqual(to_hiragana("日本語"), "にほんご")
12
+
13
+ def test_katakana_folded_by_default(self):
14
+ self.assertEqual(to_hiragana("コーヒー"), "こーひー")
15
+
16
+ def test_keep_katakana_flag_preserves_loanwords(self):
17
+ self.assertEqual(to_hiragana("コーヒー", keep_katakana=True), "コーヒー")
18
+
19
+ def test_keep_katakana_still_converts_kanji(self):
20
+ out = to_hiragana("私はコーヒーが好き", keep_katakana=True)
21
+ self.assertIn("コーヒー", out)
22
+ self.assertNotIn("私", out)
23
+ self.assertNotIn("好", out)
24
+
25
+ def test_hiragana_passes_through(self):
26
+ self.assertEqual(to_hiragana("こんにちは"), "こんにちは")
27
+
28
+ def test_non_japanese_passes_through(self):
29
+ self.assertEqual(to_hiragana("OVOS 123!"), "OVOS 123!")
30
+
31
+ def test_mixed_script_sentence(self):
32
+ out = to_hiragana("東京タワーは333mです")
33
+ self.assertIn("とうきょう", out)
34
+ self.assertIn("333m", out)
35
+
36
+ def test_empty_string(self):
37
+ self.assertEqual(to_hiragana(""), "")
38
+
39
+
40
+ class TestToKatakana(unittest.TestCase):
41
+ def test_kanji_resolved_to_reading(self):
42
+ self.assertEqual(to_katakana("日本語"), "ニホンゴ")
43
+
44
+ def test_hiragana_transposed(self):
45
+ self.assertEqual(to_katakana("こんにちは"), "コンニチハ")
46
+
47
+ def test_katakana_passes_through(self):
48
+ self.assertEqual(to_katakana("コーヒー"), "コーヒー")
49
+
50
+ def test_non_japanese_passes_through(self):
51
+ self.assertEqual(to_katakana("OVOS 123!"), "OVOS 123!")
52
+
53
+ def test_empty_string(self):
54
+ self.assertEqual(to_katakana(""), "")
55
+
56
+
57
+ class TestDependencyBoundary(unittest.TestCase):
58
+ def test_missing_pykakasi_raises_with_install_hint(self):
59
+ with mock.patch.object(readings, "_kakasi", None), \
60
+ mock.patch.dict(sys.modules, {"pykakasi": None}):
61
+ with self.assertRaises(ImportError) as ctx:
62
+ to_hiragana("日本語")
63
+ self.assertIn("scriptconv[ja]", str(ctx.exception))
64
+
65
+ def test_converter_instance_is_cached(self):
66
+ to_hiragana("日本語")
67
+ first = readings._kakasi
68
+ to_katakana("日本語")
69
+ self.assertIs(readings._kakasi, first)
70
+
71
+
72
+ if __name__ == "__main__":
73
+ unittest.main()
@@ -1,4 +0,0 @@
1
-
2
- [test]
3
- pytest
4
- pytest-timeout
File without changes
File without changes