PyHakka 0.1.0__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. pyhakka-0.1.0/LICENSE +29 -0
  2. pyhakka-0.1.0/PKG-INFO +40 -0
  3. pyhakka-0.1.0/README.md +8 -0
  4. pyhakka-0.1.0/pyproject.toml +72 -0
  5. pyhakka-0.1.0/setup.cfg +4 -0
  6. pyhakka-0.1.0/src/PyHakka.egg-info/PKG-INFO +40 -0
  7. pyhakka-0.1.0/src/PyHakka.egg-info/SOURCES.txt +32 -0
  8. pyhakka-0.1.0/src/PyHakka.egg-info/dependency_links.txt +1 -0
  9. pyhakka-0.1.0/src/PyHakka.egg-info/entry_points.txt +2 -0
  10. pyhakka-0.1.0/src/PyHakka.egg-info/requires.txt +7 -0
  11. pyhakka-0.1.0/src/PyHakka.egg-info/top_level.txt +1 -0
  12. pyhakka-0.1.0/src/pyhakka/__init__.py +72 -0
  13. pyhakka-0.1.0/src/pyhakka/_db.py +80 -0
  14. pyhakka-0.1.0/src/pyhakka/cli.py +293 -0
  15. pyhakka-0.1.0/src/pyhakka/data/hakka.sqlite3 +4 -0
  16. pyhakka-0.1.0/src/pyhakka/data/manifest.json +106 -0
  17. pyhakka-0.1.0/src/pyhakka/dialects.py +163 -0
  18. pyhakka-0.1.0/src/pyhakka/lexicon/__init__.py +22 -0
  19. pyhakka-0.1.0/src/pyhakka/lexicon/db.py +25 -0
  20. pyhakka-0.1.0/src/pyhakka/lexicon/query.py +385 -0
  21. pyhakka-0.1.0/src/pyhakka/phon/__init__.py +26 -0
  22. pyhakka-0.1.0/src/pyhakka/phon/converter.py +256 -0
  23. pyhakka-0.1.0/src/pyhakka/phon/parser.py +748 -0
  24. pyhakka-0.1.0/src/pyhakka/phon/schemes.py +319 -0
  25. pyhakka-0.1.0/src/pyhakka/phon/syllable.py +164 -0
  26. pyhakka-0.1.0/src/pyhakka/phon/validate.py +79 -0
  27. pyhakka-0.1.0/src/pyhakka/py.typed +0 -0
  28. pyhakka-0.1.0/src/pyhakka/sandhi/__init__.py +17 -0
  29. pyhakka-0.1.0/src/pyhakka/sandhi/rules.py +369 -0
  30. pyhakka-0.1.0/tests/test_cli.py +54 -0
  31. pyhakka-0.1.0/tests/test_lexicon.py +134 -0
  32. pyhakka-0.1.0/tests/test_phon_converter.py +121 -0
  33. pyhakka-0.1.0/tests/test_phon_parser.py +178 -0
  34. pyhakka-0.1.0/tests/test_sandhi.py +81 -0
pyhakka-0.1.0/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 HakkaCL
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ Note on Bundled Linguistic Data:
26
+ Code in this repository is licensed under the MIT License above.
27
+ Bundled lexical and phonological tables compiled from Hakka-Char-Tables,
28
+ Hakka-Word-Tables, HKILANG, and MCPDict remain subject to their respective
29
+ CC BY 4.0 and MIT licenses. See NOTICE.md for full attribution and licensing.
pyhakka-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,40 @@
1
+ Metadata-Version: 2.4
2
+ Name: PyHakka
3
+ Version: 0.1.0
4
+ Summary: Computational linguistics and dialectology toolkit for Hakka Chinese: phonetic conversion (HPS-Ext / IPA / Guangdong / HKILANG), lexicon lookup across 229 varieties, and tone sandhi.
5
+ Author: HakkaCL Contributors
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/HakkaCL/hakka
8
+ Project-URL: Repository, https://github.com/HakkaCL/hakka
9
+ Project-URL: Issues, https://github.com/HakkaCL/hakka/issues
10
+ Keywords: hakka,linguistics,phonology,ipa,dialectology,tone-sandhi,chinese,nlp
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Scientific/Engineering
21
+ Classifier: Topic :: Text Processing :: Linguistic
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=8.0; extra == "dev"
28
+ Requires-Dist: ruff>=0.4; extra == "dev"
29
+ Provides-Extra: build
30
+ Requires-Dist: opencc-python-reimplemented>=0.1.7; extra == "build"
31
+ Dynamic: license-file
32
+
33
+ # PyHakka
34
+
35
+ 客家話計算語言學與方言學 Python 工具庫([`HakkaCL/hakka`](https://github.com/HakkaCL/hakka) Monorepo 之 Python 套件)。
36
+
37
+ - **預設腔調**:標準惠陽腔(`huiyang`,六調 `44/11/31/53/1/5`)
38
+ - **預設記音**:客家語拼音擴展方案(`hps_ext`,HPS-Ext)
39
+ - **核心模組**:`pyhakka.phon`(音節解析、校驗、多方案無損互轉)、`pyhakka.dialects`(229 點音系元數據)、`pyhakka.lexicon`(查字、查詞、同音反查、跨點比較)、`pyhakka.sandhi`(連讀變調與音段同化)。
40
+ - 若需標準惠陽腔句子級漢字轉拼音,請使用姊妹庫 [`to-hakka`](https://github.com/HakkaCL/to-hakka)。
@@ -0,0 +1,8 @@
1
+ # PyHakka
2
+
3
+ 客家話計算語言學與方言學 Python 工具庫([`HakkaCL/hakka`](https://github.com/HakkaCL/hakka) Monorepo 之 Python 套件)。
4
+
5
+ - **預設腔調**:標準惠陽腔(`huiyang`,六調 `44/11/31/53/1/5`)
6
+ - **預設記音**:客家語拼音擴展方案(`hps_ext`,HPS-Ext)
7
+ - **核心模組**:`pyhakka.phon`(音節解析、校驗、多方案無損互轉)、`pyhakka.dialects`(229 點音系元數據)、`pyhakka.lexicon`(查字、查詞、同音反查、跨點比較)、`pyhakka.sandhi`(連讀變調與音段同化)。
8
+ - 若需標準惠陽腔句子級漢字轉拼音,請使用姊妹庫 [`to-hakka`](https://github.com/HakkaCL/to-hakka)。
@@ -0,0 +1,72 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "PyHakka"
7
+ version = "0.1.0"
8
+ description = "Computational linguistics and dialectology toolkit for Hakka Chinese: phonetic conversion (HPS-Ext / IPA / Guangdong / HKILANG), lexicon lookup across 229 varieties, and tone sandhi."
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ requires-python = ">=3.10"
12
+ authors = [
13
+ {name = "HakkaCL Contributors"},
14
+ ]
15
+ keywords = [
16
+ "hakka",
17
+ "linguistics",
18
+ "phonology",
19
+ "ipa",
20
+ "dialectology",
21
+ "tone-sandhi",
22
+ "chinese",
23
+ "nlp",
24
+ ]
25
+ classifiers = [
26
+ "Development Status :: 4 - Beta",
27
+ "Intended Audience :: Developers",
28
+ "Intended Audience :: Science/Research",
29
+ "License :: OSI Approved :: MIT License",
30
+ "Programming Language :: Python :: 3",
31
+ "Programming Language :: Python :: 3.10",
32
+ "Programming Language :: Python :: 3.11",
33
+ "Programming Language :: Python :: 3.12",
34
+ "Programming Language :: Python :: 3.13",
35
+ "Topic :: Scientific/Engineering",
36
+ "Topic :: Text Processing :: Linguistic",
37
+ "Typing :: Typed",
38
+ ]
39
+ dependencies = []
40
+
41
+ [project.optional-dependencies]
42
+ dev = [
43
+ "pytest>=8.0",
44
+ "ruff>=0.4",
45
+ ]
46
+ build = [
47
+ "opencc-python-reimplemented>=0.1.7",
48
+ ]
49
+
50
+ [project.scripts]
51
+ pyhakka = "pyhakka.cli:main"
52
+
53
+ [project.urls]
54
+ Homepage = "https://github.com/HakkaCL/hakka"
55
+ Repository = "https://github.com/HakkaCL/hakka"
56
+ Issues = "https://github.com/HakkaCL/hakka/issues"
57
+
58
+ [tool.setuptools.packages.find]
59
+ where = ["src"]
60
+
61
+ [tool.setuptools.package-data]
62
+ pyhakka = ["py.typed", "data/hakka.sqlite3", "data/manifest.json"]
63
+
64
+ [tool.pytest.ini_options]
65
+ testpaths = ["tests"]
66
+
67
+ [tool.ruff]
68
+ line-length = 100
69
+ target-version = "py310"
70
+
71
+ [tool.ruff.lint]
72
+ select = ["E4", "E7", "E9", "F", "I", "UP", "B", "PIE"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,40 @@
1
+ Metadata-Version: 2.4
2
+ Name: PyHakka
3
+ Version: 0.1.0
4
+ Summary: Computational linguistics and dialectology toolkit for Hakka Chinese: phonetic conversion (HPS-Ext / IPA / Guangdong / HKILANG), lexicon lookup across 229 varieties, and tone sandhi.
5
+ Author: HakkaCL Contributors
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/HakkaCL/hakka
8
+ Project-URL: Repository, https://github.com/HakkaCL/hakka
9
+ Project-URL: Issues, https://github.com/HakkaCL/hakka/issues
10
+ Keywords: hakka,linguistics,phonology,ipa,dialectology,tone-sandhi,chinese,nlp
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Scientific/Engineering
21
+ Classifier: Topic :: Text Processing :: Linguistic
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=8.0; extra == "dev"
28
+ Requires-Dist: ruff>=0.4; extra == "dev"
29
+ Provides-Extra: build
30
+ Requires-Dist: opencc-python-reimplemented>=0.1.7; extra == "build"
31
+ Dynamic: license-file
32
+
33
+ # PyHakka
34
+
35
+ 客家話計算語言學與方言學 Python 工具庫([`HakkaCL/hakka`](https://github.com/HakkaCL/hakka) Monorepo 之 Python 套件)。
36
+
37
+ - **預設腔調**:標準惠陽腔(`huiyang`,六調 `44/11/31/53/1/5`)
38
+ - **預設記音**:客家語拼音擴展方案(`hps_ext`,HPS-Ext)
39
+ - **核心模組**:`pyhakka.phon`(音節解析、校驗、多方案無損互轉)、`pyhakka.dialects`(229 點音系元數據)、`pyhakka.lexicon`(查字、查詞、同音反查、跨點比較)、`pyhakka.sandhi`(連讀變調與音段同化)。
40
+ - 若需標準惠陽腔句子級漢字轉拼音,請使用姊妹庫 [`to-hakka`](https://github.com/HakkaCL/to-hakka)。
@@ -0,0 +1,32 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/PyHakka.egg-info/PKG-INFO
5
+ src/PyHakka.egg-info/SOURCES.txt
6
+ src/PyHakka.egg-info/dependency_links.txt
7
+ src/PyHakka.egg-info/entry_points.txt
8
+ src/PyHakka.egg-info/requires.txt
9
+ src/PyHakka.egg-info/top_level.txt
10
+ src/pyhakka/__init__.py
11
+ src/pyhakka/_db.py
12
+ src/pyhakka/cli.py
13
+ src/pyhakka/dialects.py
14
+ src/pyhakka/py.typed
15
+ src/pyhakka/data/hakka.sqlite3
16
+ src/pyhakka/data/manifest.json
17
+ src/pyhakka/lexicon/__init__.py
18
+ src/pyhakka/lexicon/db.py
19
+ src/pyhakka/lexicon/query.py
20
+ src/pyhakka/phon/__init__.py
21
+ src/pyhakka/phon/converter.py
22
+ src/pyhakka/phon/parser.py
23
+ src/pyhakka/phon/schemes.py
24
+ src/pyhakka/phon/syllable.py
25
+ src/pyhakka/phon/validate.py
26
+ src/pyhakka/sandhi/__init__.py
27
+ src/pyhakka/sandhi/rules.py
28
+ tests/test_cli.py
29
+ tests/test_lexicon.py
30
+ tests/test_phon_converter.py
31
+ tests/test_phon_parser.py
32
+ tests/test_sandhi.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pyhakka = pyhakka.cli:main
@@ -0,0 +1,7 @@
1
+
2
+ [build]
3
+ opencc-python-reimplemented>=0.1.7
4
+
5
+ [dev]
6
+ pytest>=8.0
7
+ ruff>=0.4
@@ -0,0 +1 @@
1
+ pyhakka
@@ -0,0 +1,72 @@
1
+ """PyHakka — Computational linguistics and dialectology toolkit for Hakka Chinese.
2
+
3
+ Default variety: Standard Huiyang Hakka (``huiyang``).
4
+ Default romanization: Hakka Pinyin System Extended (HPS-Ext, ``hps_ext``).
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from pyhakka.dialects import (
10
+ DEFAULT_DIALECT,
11
+ DEFAULT_SCHEME,
12
+ DialectInfo,
13
+ ToneSpec,
14
+ get_dialect,
15
+ list_dialects,
16
+ )
17
+ from pyhakka.lexicon import (
18
+ CharReading,
19
+ WordReading,
20
+ compare_dialects,
21
+ get_manifest,
22
+ lookup_char,
23
+ lookup_word,
24
+ search_by_pron,
25
+ )
26
+ from pyhakka.phon import (
27
+ CANONICAL_SCHEMES,
28
+ Syllable,
29
+ ValidationResult,
30
+ convert,
31
+ format_syllable,
32
+ parse_syllable,
33
+ parse_syllables,
34
+ validate_syllable,
35
+ )
36
+ from pyhakka.sandhi import (
37
+ SandhiChange,
38
+ SandhiResult,
39
+ apply_sandhi,
40
+ list_sandhi_dialects,
41
+ )
42
+
43
+ __version__ = "0.1.0"
44
+
45
+ __all__ = [
46
+ "CANONICAL_SCHEMES",
47
+ "DEFAULT_DIALECT",
48
+ "DEFAULT_SCHEME",
49
+ "CharReading",
50
+ "DialectInfo",
51
+ "SandhiChange",
52
+ "SandhiResult",
53
+ "Syllable",
54
+ "ToneSpec",
55
+ "ValidationResult",
56
+ "WordReading",
57
+ "__version__",
58
+ "apply_sandhi",
59
+ "compare_dialects",
60
+ "convert",
61
+ "format_syllable",
62
+ "get_dialect",
63
+ "get_manifest",
64
+ "list_dialects",
65
+ "list_sandhi_dialects",
66
+ "lookup_char",
67
+ "lookup_word",
68
+ "parse_syllable",
69
+ "parse_syllables",
70
+ "search_by_pron",
71
+ "validate_syllable",
72
+ ]
@@ -0,0 +1,80 @@
1
+ """Internal read-only SQLite connection manager and Simplified/Traditional bridging."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import sqlite3
7
+ from functools import lru_cache
8
+ from pathlib import Path
9
+ from typing import Any
10
+
11
+ DATA_DIR = Path(__file__).resolve().parent / "data"
12
+ DEFAULT_DB_PATH = DATA_DIR / "hakka.sqlite3"
13
+ MANIFEST_PATH = DATA_DIR / "manifest.json"
14
+
15
+ _CONNECTION: sqlite3.Connection | None = None
16
+
17
+
18
+ def get_db_path() -> Path:
19
+ return DEFAULT_DB_PATH
20
+
21
+
22
+ def get_manifest() -> dict[str, Any]:
23
+ return json.loads(MANIFEST_PATH.read_text(encoding="utf-8"))
24
+
25
+
26
+ def get_connection() -> sqlite3.Connection:
27
+ global _CONNECTION
28
+ if _CONNECTION is None:
29
+ db_path = get_db_path()
30
+ if not db_path.exists():
31
+ raise FileNotFoundError(
32
+ f"PyHakka database not found at {db_path}. "
33
+ "Run `python3 scripts/build_db.py` to compile it."
34
+ )
35
+ conn = sqlite3.connect(
36
+ f"file:{db_path}?mode=ro",
37
+ uri=True,
38
+ check_same_thread=False,
39
+ )
40
+ conn.row_factory = sqlite3.Row
41
+ _CONNECTION = conn
42
+ return _CONNECTION
43
+
44
+
45
+ @lru_cache(maxsize=8192)
46
+ def expand_char_variants(ch: str) -> tuple[str, ...]:
47
+ """Return `(ch, ...)` including mapped Traditional candidates for a Simplified char."""
48
+ if len(ch) != 1:
49
+ return (ch,)
50
+ conn = get_connection()
51
+ rows = conn.execute(
52
+ "SELECT trad FROM simp_trad WHERE simp = ? ORDER BY trad",
53
+ (ch,),
54
+ ).fetchall()
55
+ if not rows:
56
+ return (ch,)
57
+ seen = {ch}
58
+ out = [ch]
59
+ for r in rows:
60
+ t = r["trad"]
61
+ if t not in seen:
62
+ seen.add(t)
63
+ out.append(t)
64
+ return tuple(out)
65
+
66
+
67
+ @lru_cache(maxsize=8192)
68
+ def to_simplified_char(ch: str) -> str:
69
+ """Return Simplified equivalent of a Traditional char if unique in simp_trad."""
70
+ if len(ch) != 1:
71
+ return ch
72
+ conn = get_connection()
73
+ rows = conn.execute("SELECT simp FROM simp_trad WHERE trad = ?", (ch,)).fetchall()
74
+ if len(rows) == 1:
75
+ return str(rows[0]["simp"])
76
+ return ch
77
+
78
+
79
+ def to_simplified_text(text: str) -> str:
80
+ return "".join(to_simplified_char(ch) for ch in text)