py-pinyin-split 0.1.0rc0__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.
- py_pinyin_split-0.1.0rc0/.github/workflows/publish.yml +120 -0
- py_pinyin_split-0.1.0rc0/.gitignore +30 -0
- py_pinyin_split-0.1.0rc0/.python-version +1 -0
- py_pinyin_split-0.1.0rc0/LICENSE.txt +9 -0
- py_pinyin_split-0.1.0rc0/PKG-INFO +58 -0
- py_pinyin_split-0.1.0rc0/README.md +33 -0
- py_pinyin_split-0.1.0rc0/pyproject.toml +60 -0
- py_pinyin_split-0.1.0rc0/src/pinyin_split/__about__.py +4 -0
- py_pinyin_split-0.1.0rc0/src/pinyin_split/__init__.py +5 -0
- py_pinyin_split-0.1.0rc0/src/pinyin_split/pinyinsplit.py +469 -0
- py_pinyin_split-0.1.0rc0/src/pinyin_split/py.typed +0 -0
- py_pinyin_split-0.1.0rc0/tests/__init__.py +3 -0
- py_pinyin_split-0.1.0rc0/tests/test_pinyinsplit.py +63 -0
- py_pinyin_split-0.1.0rc0/uv.lock +22 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
|
|
2
|
+
|
|
3
|
+
on: push
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
name: Build distribution 📦
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
|
|
13
|
+
- name: Install uv
|
|
14
|
+
uses: astral-sh/setup-uv@v3
|
|
15
|
+
with:
|
|
16
|
+
# Install a specific version of uv.
|
|
17
|
+
version: "0.5.2"
|
|
18
|
+
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version-file: "pyproject.toml"
|
|
23
|
+
|
|
24
|
+
- name: Build a binary wheel and a source tarball
|
|
25
|
+
run: uv build
|
|
26
|
+
|
|
27
|
+
- name: Store the distribution packages
|
|
28
|
+
uses: actions/upload-artifact@v4
|
|
29
|
+
with:
|
|
30
|
+
name: python-package-distributions
|
|
31
|
+
path: dist/
|
|
32
|
+
|
|
33
|
+
publish-to-pypi:
|
|
34
|
+
name: >-
|
|
35
|
+
Publish Python 🐍 distribution 📦 to PyPI
|
|
36
|
+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
|
|
37
|
+
needs:
|
|
38
|
+
- build
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
environment:
|
|
41
|
+
name: pypi
|
|
42
|
+
url: https://pypi.org/p/pinyin-split
|
|
43
|
+
permissions:
|
|
44
|
+
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
45
|
+
|
|
46
|
+
steps:
|
|
47
|
+
- name: Download all the dists
|
|
48
|
+
uses: actions/download-artifact@v4
|
|
49
|
+
with:
|
|
50
|
+
name: python-package-distributions
|
|
51
|
+
path: dist/
|
|
52
|
+
- name: Publish distribution 📦 to PyPI
|
|
53
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
54
|
+
|
|
55
|
+
github-release:
|
|
56
|
+
name: >-
|
|
57
|
+
Sign the Python 🐍 distribution 📦 with Sigstore
|
|
58
|
+
and upload them to GitHub Release
|
|
59
|
+
needs:
|
|
60
|
+
- publish-to-pypi
|
|
61
|
+
runs-on: ubuntu-latest
|
|
62
|
+
|
|
63
|
+
permissions:
|
|
64
|
+
contents: write # IMPORTANT: mandatory for making GitHub Releases
|
|
65
|
+
id-token: write # IMPORTANT: mandatory for sigstore
|
|
66
|
+
|
|
67
|
+
steps:
|
|
68
|
+
- name: Download all the dists
|
|
69
|
+
uses: actions/download-artifact@v4
|
|
70
|
+
with:
|
|
71
|
+
name: python-package-distributions
|
|
72
|
+
path: dist/
|
|
73
|
+
- name: Sign the dists with Sigstore
|
|
74
|
+
uses: sigstore/gh-action-sigstore-python@v3.0.0
|
|
75
|
+
with:
|
|
76
|
+
inputs: >-
|
|
77
|
+
./dist/*.tar.gz
|
|
78
|
+
./dist/*.whl
|
|
79
|
+
- name: Create GitHub Release
|
|
80
|
+
env:
|
|
81
|
+
GITHUB_TOKEN: ${{ github.token }}
|
|
82
|
+
run: >-
|
|
83
|
+
gh release create
|
|
84
|
+
'${{ github.ref_name }}'
|
|
85
|
+
--repo '${{ github.repository }}'
|
|
86
|
+
--notes ""
|
|
87
|
+
- name: Upload artifact signatures to GitHub Release
|
|
88
|
+
env:
|
|
89
|
+
GITHUB_TOKEN: ${{ github.token }}
|
|
90
|
+
# Upload to GitHub Release using the `gh` CLI.
|
|
91
|
+
# `dist/` contains the built packages, and the
|
|
92
|
+
# sigstore-produced signatures and certificates.
|
|
93
|
+
run: >-
|
|
94
|
+
gh release upload
|
|
95
|
+
'${{ github.ref_name }}' dist/**
|
|
96
|
+
--repo '${{ github.repository }}'
|
|
97
|
+
|
|
98
|
+
publish-to-testpypi:
|
|
99
|
+
name: Publish Python 🐍 distribution 📦 to TestPyPI
|
|
100
|
+
needs:
|
|
101
|
+
- build
|
|
102
|
+
runs-on: ubuntu-latest
|
|
103
|
+
|
|
104
|
+
environment:
|
|
105
|
+
name: testpypi
|
|
106
|
+
url: https://test.pypi.org/p/pinyin-split
|
|
107
|
+
|
|
108
|
+
permissions:
|
|
109
|
+
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
110
|
+
|
|
111
|
+
steps:
|
|
112
|
+
- name: Download all the dists
|
|
113
|
+
uses: actions/download-artifact@v4
|
|
114
|
+
with:
|
|
115
|
+
name: python-package-distributions
|
|
116
|
+
path: dist/
|
|
117
|
+
- name: Publish distribution 📦 to TestPyPI
|
|
118
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
119
|
+
with:
|
|
120
|
+
repository-url: https://test.pypi.org/legacy/
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Python-generated files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[oc]
|
|
4
|
+
build/
|
|
5
|
+
dist/
|
|
6
|
+
wheels/
|
|
7
|
+
*.egg-info
|
|
8
|
+
|
|
9
|
+
# Unit test / coverage reports
|
|
10
|
+
htmlcov/
|
|
11
|
+
.tox/
|
|
12
|
+
.nox/
|
|
13
|
+
.coverage
|
|
14
|
+
.coverage.*
|
|
15
|
+
.cache
|
|
16
|
+
nosetests.xml
|
|
17
|
+
coverage.xml
|
|
18
|
+
*.cover
|
|
19
|
+
*.py,cover
|
|
20
|
+
.hypothesis/
|
|
21
|
+
.pytest_cache/
|
|
22
|
+
cover/
|
|
23
|
+
|
|
24
|
+
# Virtual environments
|
|
25
|
+
.venv
|
|
26
|
+
.DS_Store
|
|
27
|
+
|
|
28
|
+
.aider*
|
|
29
|
+
.env
|
|
30
|
+
.ruff_cache
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.8
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Lukas Strobel <git@lstrobel.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: py-pinyin-split
|
|
3
|
+
Version: 0.1.0rc0
|
|
4
|
+
Project-URL: Documentation, https://github.com/lstrobel/pinyin-split#readme
|
|
5
|
+
Project-URL: Issues, https://github.com/lstrobel/pinyin-split/issues
|
|
6
|
+
Project-URL: Source, https://github.com/lstrobel/pinyin-split
|
|
7
|
+
Author-email: Thomas Lee <thomaslee@throput.com>, lstrobel <mail@lstrobel.com>
|
|
8
|
+
Maintainer-email: lstrobel <mail@lstrobel.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
Keywords: chinese,pinyin
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
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 :: Implementation :: CPython
|
|
20
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
21
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Requires-Dist: pygtrie>=2.5.0
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# pinyin-split
|
|
27
|
+
|
|
28
|
+
A Python library for splitting Chinese Pinyin phrases into possible permutations of valid Pinyin syllables.
|
|
29
|
+
|
|
30
|
+
Based originally on [pinyinsplit](https://github.com/throput/pinyinsplit) by [@tomlee](https://github.com/tomlee).
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install pinyin-split
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from pinyin_split import split
|
|
42
|
+
|
|
43
|
+
# Basic usage
|
|
44
|
+
split('xianggangdaxue')
|
|
45
|
+
[['xiang', 'gang', 'da', 'xue'], ['xiang', 'gang', 'da', 'xu', 'e'],
|
|
46
|
+
['xi', 'ang', 'gang', 'da', 'xue'], ['xi', 'ang', 'gang', 'da', 'xu', 'e']]
|
|
47
|
+
|
|
48
|
+
# Complex example
|
|
49
|
+
split('shediaoyingxiongchuan')
|
|
50
|
+
[['she', 'diao', 'ying', 'xiong', 'chuan'],
|
|
51
|
+
['she', 'diao', 'ying', 'xiong', 'chu', 'an'],
|
|
52
|
+
['she', 'di', 'ao', 'ying', 'xiong', 'chuan'],
|
|
53
|
+
['she', 'di', 'ao', 'ying', 'xiong', 'chu', 'an']]
|
|
54
|
+
|
|
55
|
+
# Invalid input returns empty list
|
|
56
|
+
split('shediaoyingxiongchuanxyz')
|
|
57
|
+
[]
|
|
58
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# pinyin-split
|
|
2
|
+
|
|
3
|
+
A Python library for splitting Chinese Pinyin phrases into possible permutations of valid Pinyin syllables.
|
|
4
|
+
|
|
5
|
+
Based originally on [pinyinsplit](https://github.com/throput/pinyinsplit) by [@tomlee](https://github.com/tomlee).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install pinyin-split
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from pinyin_split import split
|
|
17
|
+
|
|
18
|
+
# Basic usage
|
|
19
|
+
split('xianggangdaxue')
|
|
20
|
+
[['xiang', 'gang', 'da', 'xue'], ['xiang', 'gang', 'da', 'xu', 'e'],
|
|
21
|
+
['xi', 'ang', 'gang', 'da', 'xue'], ['xi', 'ang', 'gang', 'da', 'xu', 'e']]
|
|
22
|
+
|
|
23
|
+
# Complex example
|
|
24
|
+
split('shediaoyingxiongchuan')
|
|
25
|
+
[['she', 'diao', 'ying', 'xiong', 'chuan'],
|
|
26
|
+
['she', 'diao', 'ying', 'xiong', 'chu', 'an'],
|
|
27
|
+
['she', 'di', 'ao', 'ying', 'xiong', 'chuan'],
|
|
28
|
+
['she', 'di', 'ao', 'ying', 'xiong', 'chu', 'an']]
|
|
29
|
+
|
|
30
|
+
# Invalid input returns empty list
|
|
31
|
+
split('shediaoyingxiongchuanxyz')
|
|
32
|
+
[]
|
|
33
|
+
```
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[tool.hatch.build.targets.wheel]
|
|
6
|
+
packages = ["src/pinyin_split"]
|
|
7
|
+
|
|
8
|
+
[project]
|
|
9
|
+
name = "py-pinyin-split"
|
|
10
|
+
dynamic = ["version"]
|
|
11
|
+
description = ''
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
license = "MIT"
|
|
15
|
+
keywords = ['chinese', 'pinyin']
|
|
16
|
+
authors = [
|
|
17
|
+
{ name = "Thomas Lee", email = "thomaslee@throput.com" },
|
|
18
|
+
{ name = "lstrobel", email = "mail@lstrobel.com" },
|
|
19
|
+
]
|
|
20
|
+
maintainers = [{ name = "lstrobel", email = "mail@lstrobel.com" }]
|
|
21
|
+
classifiers = [
|
|
22
|
+
"Development Status :: 4 - Beta",
|
|
23
|
+
"Programming Language :: Python",
|
|
24
|
+
"Programming Language :: Python :: 3.8",
|
|
25
|
+
"Programming Language :: Python :: 3.9",
|
|
26
|
+
"Programming Language :: Python :: 3.10",
|
|
27
|
+
"Programming Language :: Python :: 3.11",
|
|
28
|
+
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
30
|
+
"Programming Language :: Python :: Implementation :: PyPy",
|
|
31
|
+
'License :: OSI Approved :: MIT License',
|
|
32
|
+
'Topic :: Text Processing :: Linguistic',
|
|
33
|
+
]
|
|
34
|
+
dependencies = ["pygtrie>=2.5.0"]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Documentation = "https://github.com/lstrobel/pinyin-split#readme"
|
|
38
|
+
Issues = "https://github.com/lstrobel/pinyin-split/issues"
|
|
39
|
+
Source = "https://github.com/lstrobel/pinyin-split"
|
|
40
|
+
|
|
41
|
+
[tool.hatch.version]
|
|
42
|
+
path = "src/pinyin_split/__about__.py"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.envs.types]
|
|
45
|
+
extra-dependencies = ["mypy>=1.0.0"]
|
|
46
|
+
[tool.hatch.envs.types.scripts]
|
|
47
|
+
check = "mypy --install-types --non-interactive {args:src/pinyin_split tests}"
|
|
48
|
+
|
|
49
|
+
[tool.coverage.run]
|
|
50
|
+
source_pkgs = ["pinyin_split", "tests"]
|
|
51
|
+
branch = true
|
|
52
|
+
parallel = true
|
|
53
|
+
omit = ["src/pinyin_split/__about__.py"]
|
|
54
|
+
|
|
55
|
+
[tool.coverage.paths]
|
|
56
|
+
pinyin_split = ["src/pinyin_split", "*/pinyin-split/src/pinyin_split"]
|
|
57
|
+
tests = ["tests", "*/pinyin-split/tests"]
|
|
58
|
+
|
|
59
|
+
[tool.coverage.report]
|
|
60
|
+
exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]
|
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
import copy
|
|
2
|
+
from pygtrie import CharTrie
|
|
3
|
+
|
|
4
|
+
_pylist = [
|
|
5
|
+
"a",
|
|
6
|
+
"ai",
|
|
7
|
+
"an",
|
|
8
|
+
"ang",
|
|
9
|
+
"ao",
|
|
10
|
+
"ba",
|
|
11
|
+
"bai",
|
|
12
|
+
"ban",
|
|
13
|
+
"bang",
|
|
14
|
+
"bao",
|
|
15
|
+
"bei",
|
|
16
|
+
"ben",
|
|
17
|
+
"beng",
|
|
18
|
+
"bi",
|
|
19
|
+
"bian",
|
|
20
|
+
"biang",
|
|
21
|
+
"biao",
|
|
22
|
+
"bie",
|
|
23
|
+
"bin",
|
|
24
|
+
"bing",
|
|
25
|
+
"bo",
|
|
26
|
+
"bu",
|
|
27
|
+
"ca",
|
|
28
|
+
"cai",
|
|
29
|
+
"can",
|
|
30
|
+
"cang",
|
|
31
|
+
"cao",
|
|
32
|
+
"ce",
|
|
33
|
+
"cen",
|
|
34
|
+
"ceng",
|
|
35
|
+
"cha",
|
|
36
|
+
"chai",
|
|
37
|
+
"chan",
|
|
38
|
+
"chang",
|
|
39
|
+
"chao",
|
|
40
|
+
"che",
|
|
41
|
+
"chen",
|
|
42
|
+
"cheng",
|
|
43
|
+
"chi",
|
|
44
|
+
"chong",
|
|
45
|
+
"chou",
|
|
46
|
+
"chu",
|
|
47
|
+
"chua",
|
|
48
|
+
"chuai",
|
|
49
|
+
"chuan",
|
|
50
|
+
"chuang",
|
|
51
|
+
"chui",
|
|
52
|
+
"chun",
|
|
53
|
+
"chuo",
|
|
54
|
+
"ci",
|
|
55
|
+
"cong",
|
|
56
|
+
"cou",
|
|
57
|
+
"cu",
|
|
58
|
+
"cuan",
|
|
59
|
+
"cui",
|
|
60
|
+
"cun",
|
|
61
|
+
"cuo",
|
|
62
|
+
"da",
|
|
63
|
+
"dai",
|
|
64
|
+
"dan",
|
|
65
|
+
"dang",
|
|
66
|
+
"dao",
|
|
67
|
+
"de",
|
|
68
|
+
"dei",
|
|
69
|
+
"den",
|
|
70
|
+
"deng",
|
|
71
|
+
"di",
|
|
72
|
+
"dia",
|
|
73
|
+
"dian",
|
|
74
|
+
"diang",
|
|
75
|
+
"diao",
|
|
76
|
+
"die",
|
|
77
|
+
"ding",
|
|
78
|
+
"diu",
|
|
79
|
+
"dong",
|
|
80
|
+
"dou",
|
|
81
|
+
"du",
|
|
82
|
+
"duan",
|
|
83
|
+
"dui",
|
|
84
|
+
"dun",
|
|
85
|
+
"duo",
|
|
86
|
+
"e",
|
|
87
|
+
"ei",
|
|
88
|
+
"en",
|
|
89
|
+
"eng",
|
|
90
|
+
"er",
|
|
91
|
+
"fa",
|
|
92
|
+
"fan",
|
|
93
|
+
"fang",
|
|
94
|
+
"fei",
|
|
95
|
+
"fen",
|
|
96
|
+
"feng",
|
|
97
|
+
"fiao",
|
|
98
|
+
"fo",
|
|
99
|
+
"fou",
|
|
100
|
+
"fu",
|
|
101
|
+
"ga",
|
|
102
|
+
"gai",
|
|
103
|
+
"gan",
|
|
104
|
+
"gang",
|
|
105
|
+
"gao",
|
|
106
|
+
"ge",
|
|
107
|
+
"gei",
|
|
108
|
+
"gen",
|
|
109
|
+
"geng",
|
|
110
|
+
"gong",
|
|
111
|
+
"gou",
|
|
112
|
+
"gu",
|
|
113
|
+
"gua",
|
|
114
|
+
"guai",
|
|
115
|
+
"guan",
|
|
116
|
+
"guang",
|
|
117
|
+
"gui",
|
|
118
|
+
"gun",
|
|
119
|
+
"guo",
|
|
120
|
+
"ha",
|
|
121
|
+
"hai",
|
|
122
|
+
"han",
|
|
123
|
+
"hang",
|
|
124
|
+
"hao",
|
|
125
|
+
"he",
|
|
126
|
+
"hei",
|
|
127
|
+
"hen",
|
|
128
|
+
"heng",
|
|
129
|
+
"hong",
|
|
130
|
+
"hou",
|
|
131
|
+
"hu",
|
|
132
|
+
"hua",
|
|
133
|
+
"huai",
|
|
134
|
+
"huan",
|
|
135
|
+
"huang",
|
|
136
|
+
"hui",
|
|
137
|
+
"hun",
|
|
138
|
+
"huo",
|
|
139
|
+
"ji",
|
|
140
|
+
"jia",
|
|
141
|
+
"jian",
|
|
142
|
+
"jiang",
|
|
143
|
+
"jiao",
|
|
144
|
+
"jie",
|
|
145
|
+
"jin",
|
|
146
|
+
"jing",
|
|
147
|
+
"jiong",
|
|
148
|
+
"jiu",
|
|
149
|
+
"ju",
|
|
150
|
+
"juan",
|
|
151
|
+
"jue",
|
|
152
|
+
"jun",
|
|
153
|
+
"ka",
|
|
154
|
+
"kai",
|
|
155
|
+
"kan",
|
|
156
|
+
"kang",
|
|
157
|
+
"kao",
|
|
158
|
+
"ke",
|
|
159
|
+
"kei",
|
|
160
|
+
"ken",
|
|
161
|
+
"keng",
|
|
162
|
+
"kong",
|
|
163
|
+
"kou",
|
|
164
|
+
"ku",
|
|
165
|
+
"kua",
|
|
166
|
+
"kuai",
|
|
167
|
+
"kuan",
|
|
168
|
+
"kuang",
|
|
169
|
+
"kui",
|
|
170
|
+
"kun",
|
|
171
|
+
"kuo",
|
|
172
|
+
"la",
|
|
173
|
+
"lai",
|
|
174
|
+
"lan",
|
|
175
|
+
"lang",
|
|
176
|
+
"lao",
|
|
177
|
+
"le",
|
|
178
|
+
"lei",
|
|
179
|
+
"leng",
|
|
180
|
+
"li",
|
|
181
|
+
"lia",
|
|
182
|
+
"lian",
|
|
183
|
+
"liang",
|
|
184
|
+
"liao",
|
|
185
|
+
"lie",
|
|
186
|
+
"lin",
|
|
187
|
+
"ling",
|
|
188
|
+
"liu",
|
|
189
|
+
"long",
|
|
190
|
+
"lou",
|
|
191
|
+
"lu",
|
|
192
|
+
"luan",
|
|
193
|
+
"lue",
|
|
194
|
+
"lun",
|
|
195
|
+
"luo",
|
|
196
|
+
"lv",
|
|
197
|
+
"lve",
|
|
198
|
+
"lvn",
|
|
199
|
+
"lü",
|
|
200
|
+
"lüe",
|
|
201
|
+
"lün",
|
|
202
|
+
"ma",
|
|
203
|
+
"mai",
|
|
204
|
+
"man",
|
|
205
|
+
"mang",
|
|
206
|
+
"mao",
|
|
207
|
+
"me",
|
|
208
|
+
"mei",
|
|
209
|
+
"men",
|
|
210
|
+
"meng",
|
|
211
|
+
"mi",
|
|
212
|
+
"mian",
|
|
213
|
+
"miao",
|
|
214
|
+
"mie",
|
|
215
|
+
"min",
|
|
216
|
+
"ming",
|
|
217
|
+
"miu",
|
|
218
|
+
"mo",
|
|
219
|
+
"mou",
|
|
220
|
+
"mu",
|
|
221
|
+
"na",
|
|
222
|
+
"nai",
|
|
223
|
+
"nan",
|
|
224
|
+
"nang",
|
|
225
|
+
"nao",
|
|
226
|
+
"ne",
|
|
227
|
+
"nei",
|
|
228
|
+
"nen",
|
|
229
|
+
"neng",
|
|
230
|
+
"ni",
|
|
231
|
+
"nia",
|
|
232
|
+
"nian",
|
|
233
|
+
"niang",
|
|
234
|
+
"niao",
|
|
235
|
+
"nie",
|
|
236
|
+
"nin",
|
|
237
|
+
"ning",
|
|
238
|
+
"niu",
|
|
239
|
+
"nong",
|
|
240
|
+
"nou",
|
|
241
|
+
"nu",
|
|
242
|
+
"nuan",
|
|
243
|
+
"nue",
|
|
244
|
+
"nun",
|
|
245
|
+
"nuo",
|
|
246
|
+
"nv",
|
|
247
|
+
"nve",
|
|
248
|
+
"nü",
|
|
249
|
+
"nüe",
|
|
250
|
+
"ou",
|
|
251
|
+
"pa",
|
|
252
|
+
"pai",
|
|
253
|
+
"pan",
|
|
254
|
+
"pang",
|
|
255
|
+
"pao",
|
|
256
|
+
"pei",
|
|
257
|
+
"pen",
|
|
258
|
+
"peng",
|
|
259
|
+
"pi",
|
|
260
|
+
"pian",
|
|
261
|
+
"piao",
|
|
262
|
+
"pie",
|
|
263
|
+
"pin",
|
|
264
|
+
"ping",
|
|
265
|
+
"po",
|
|
266
|
+
"pou",
|
|
267
|
+
"pu",
|
|
268
|
+
"qi",
|
|
269
|
+
"qia",
|
|
270
|
+
"qian",
|
|
271
|
+
"qiang",
|
|
272
|
+
"qiao",
|
|
273
|
+
"qie",
|
|
274
|
+
"qin",
|
|
275
|
+
"qing",
|
|
276
|
+
"qiong",
|
|
277
|
+
"qiu",
|
|
278
|
+
"qu",
|
|
279
|
+
"quan",
|
|
280
|
+
"que",
|
|
281
|
+
"qun",
|
|
282
|
+
"ran",
|
|
283
|
+
"rang",
|
|
284
|
+
"rao",
|
|
285
|
+
"re",
|
|
286
|
+
"ren",
|
|
287
|
+
"reng",
|
|
288
|
+
"ri",
|
|
289
|
+
"rong",
|
|
290
|
+
"rou",
|
|
291
|
+
"ru",
|
|
292
|
+
"rua",
|
|
293
|
+
"ruan",
|
|
294
|
+
"rui",
|
|
295
|
+
"run",
|
|
296
|
+
"ruo",
|
|
297
|
+
"sa",
|
|
298
|
+
"sai",
|
|
299
|
+
"san",
|
|
300
|
+
"sang",
|
|
301
|
+
"sao",
|
|
302
|
+
"se",
|
|
303
|
+
"sei",
|
|
304
|
+
"sen",
|
|
305
|
+
"seng",
|
|
306
|
+
"sha",
|
|
307
|
+
"shai",
|
|
308
|
+
"shan",
|
|
309
|
+
"shang",
|
|
310
|
+
"shao",
|
|
311
|
+
"she",
|
|
312
|
+
"shei",
|
|
313
|
+
"shen",
|
|
314
|
+
"sheng",
|
|
315
|
+
"shi",
|
|
316
|
+
"shong",
|
|
317
|
+
"shou",
|
|
318
|
+
"shu",
|
|
319
|
+
"shua",
|
|
320
|
+
"shuai",
|
|
321
|
+
"shuan",
|
|
322
|
+
"shuang",
|
|
323
|
+
"shui",
|
|
324
|
+
"shun",
|
|
325
|
+
"shuo",
|
|
326
|
+
"si",
|
|
327
|
+
"song",
|
|
328
|
+
"sou",
|
|
329
|
+
"su",
|
|
330
|
+
"suan",
|
|
331
|
+
"sui",
|
|
332
|
+
"sun",
|
|
333
|
+
"suo",
|
|
334
|
+
"ta",
|
|
335
|
+
"tai",
|
|
336
|
+
"tan",
|
|
337
|
+
"tang",
|
|
338
|
+
"tao",
|
|
339
|
+
"te",
|
|
340
|
+
"tei",
|
|
341
|
+
"teng",
|
|
342
|
+
"ti",
|
|
343
|
+
"tian",
|
|
344
|
+
"tiao",
|
|
345
|
+
"tie",
|
|
346
|
+
"ting",
|
|
347
|
+
"tong",
|
|
348
|
+
"tou",
|
|
349
|
+
"tu",
|
|
350
|
+
"tuan",
|
|
351
|
+
"tui",
|
|
352
|
+
"tun",
|
|
353
|
+
"tuo",
|
|
354
|
+
"wa",
|
|
355
|
+
"wai",
|
|
356
|
+
"wan",
|
|
357
|
+
"wang",
|
|
358
|
+
"wei",
|
|
359
|
+
"wen",
|
|
360
|
+
"weng",
|
|
361
|
+
"wo",
|
|
362
|
+
"wu",
|
|
363
|
+
"xi",
|
|
364
|
+
"xia",
|
|
365
|
+
"xian",
|
|
366
|
+
"xiang",
|
|
367
|
+
"xiao",
|
|
368
|
+
"xie",
|
|
369
|
+
"xin",
|
|
370
|
+
"xing",
|
|
371
|
+
"xiong",
|
|
372
|
+
"xiu",
|
|
373
|
+
"xu",
|
|
374
|
+
"xuan",
|
|
375
|
+
"xue",
|
|
376
|
+
"xun",
|
|
377
|
+
"ya",
|
|
378
|
+
"yai",
|
|
379
|
+
"yan",
|
|
380
|
+
"yang",
|
|
381
|
+
"yao",
|
|
382
|
+
"ye",
|
|
383
|
+
"yi",
|
|
384
|
+
"yin",
|
|
385
|
+
"ying",
|
|
386
|
+
"yo",
|
|
387
|
+
"yong",
|
|
388
|
+
"you",
|
|
389
|
+
"yu",
|
|
390
|
+
"yuan",
|
|
391
|
+
"yue",
|
|
392
|
+
"yun",
|
|
393
|
+
"za",
|
|
394
|
+
"zai",
|
|
395
|
+
"zan",
|
|
396
|
+
"zang",
|
|
397
|
+
"zao",
|
|
398
|
+
"ze",
|
|
399
|
+
"zei",
|
|
400
|
+
"zen",
|
|
401
|
+
"zeng",
|
|
402
|
+
"zha",
|
|
403
|
+
"zhai",
|
|
404
|
+
"zhan",
|
|
405
|
+
"zhang",
|
|
406
|
+
"zhao",
|
|
407
|
+
"zhe",
|
|
408
|
+
"zhei",
|
|
409
|
+
"zhen",
|
|
410
|
+
"zheng",
|
|
411
|
+
"zhi",
|
|
412
|
+
"zhong",
|
|
413
|
+
"zhou",
|
|
414
|
+
"zhu",
|
|
415
|
+
"zhua",
|
|
416
|
+
"zhuai",
|
|
417
|
+
"zhuan",
|
|
418
|
+
"zhuang",
|
|
419
|
+
"zhui",
|
|
420
|
+
"zhun",
|
|
421
|
+
"zhuo",
|
|
422
|
+
"zi",
|
|
423
|
+
"zong",
|
|
424
|
+
"zou",
|
|
425
|
+
"zu",
|
|
426
|
+
"zuan",
|
|
427
|
+
"zui",
|
|
428
|
+
"zun",
|
|
429
|
+
"zuo",
|
|
430
|
+
"ê",
|
|
431
|
+
]
|
|
432
|
+
|
|
433
|
+
_trie = None
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def _init_trie():
|
|
437
|
+
global _trie
|
|
438
|
+
if _trie is None:
|
|
439
|
+
_trie = CharTrie()
|
|
440
|
+
for py in _pylist:
|
|
441
|
+
_trie[py] = len(py)
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
def split(phrase):
|
|
445
|
+
_init_trie()
|
|
446
|
+
phrase_lc = phrase.lower()
|
|
447
|
+
split_list = []
|
|
448
|
+
results = []
|
|
449
|
+
if phrase:
|
|
450
|
+
split_list.append((phrase, phrase_lc, []))
|
|
451
|
+
while split_list:
|
|
452
|
+
pair = split_list.pop()
|
|
453
|
+
phrase = pair[0]
|
|
454
|
+
phrase_lc = pair[1]
|
|
455
|
+
words = pair[2]
|
|
456
|
+
matches = _trie.prefixes(phrase_lc)
|
|
457
|
+
for match in matches:
|
|
458
|
+
n = match[1]
|
|
459
|
+
# Get the word and convert to lowercase
|
|
460
|
+
word = phrase[:n].lower()
|
|
461
|
+
tail = phrase[n:]
|
|
462
|
+
tail_lc = phrase_lc[n:]
|
|
463
|
+
words_copy = copy.deepcopy(words)
|
|
464
|
+
words_copy.append(word)
|
|
465
|
+
if tail:
|
|
466
|
+
split_list.append((tail, tail_lc, words_copy))
|
|
467
|
+
else:
|
|
468
|
+
results.append(words_copy)
|
|
469
|
+
return results
|
|
File without changes
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from pinyin_split import split
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_basic_splits():
|
|
5
|
+
"""Test basic pinyin splitting cases"""
|
|
6
|
+
assert split("nihao") == [["ni", "hao"]]
|
|
7
|
+
assert split("beijing") == [["bei", "jing"]]
|
|
8
|
+
assert split("zhongguo") == [["zhong", "guo"]]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_single_syllables():
|
|
12
|
+
"""Test single syllable cases"""
|
|
13
|
+
assert split("a") == [["a"]]
|
|
14
|
+
assert split("ai") == [["ai"]]
|
|
15
|
+
assert split("an") == [["an"]]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_ambiguous_splits():
|
|
19
|
+
"""Test cases where multiple valid splits are possible"""
|
|
20
|
+
assert sorted(split("xian")) == sorted([["xi", "an"], ["xian"]])
|
|
21
|
+
assert sorted(split("yingying")) == sorted([["ying", "ying"]])
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_case_sensitivity():
|
|
25
|
+
"""Test that splitting works regardless of case"""
|
|
26
|
+
# The current implementation preserves case
|
|
27
|
+
assert split("NIHAO") == [["ni", "hao"]]
|
|
28
|
+
assert split("BeIJinG") == [["bei", "jing"]]
|
|
29
|
+
assert split("ZhongGuo") == [["zhong", "guo"]]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_edge_cases():
|
|
33
|
+
"""Test edge cases and invalid inputs"""
|
|
34
|
+
assert split("") == []
|
|
35
|
+
assert split(" ") == []
|
|
36
|
+
assert split("x") == [] # Single consonant isn't valid pinyin
|
|
37
|
+
assert split("abc") == [] # Invalid pinyin sequence
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_complex_combinations():
|
|
41
|
+
"""Test more complex and challenging combinations"""
|
|
42
|
+
assert sorted(split("zhongguoren")) == sorted([["zhong", "guo", "ren"]])
|
|
43
|
+
assert sorted(split("meiguoxing")) == sorted([["mei", "guo", "xing"]])
|
|
44
|
+
# The current implementation finds multiple valid splits
|
|
45
|
+
assert sorted(split("xiaolongbao")) == sorted(
|
|
46
|
+
[["xiao", "long", "bao"], ["xi", "ao", "long", "bao"]]
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_special_syllables():
|
|
51
|
+
"""Test special pinyin syllables and combinations"""
|
|
52
|
+
# The current implementation finds all valid splits
|
|
53
|
+
assert sorted(split("lüe")) == sorted([["lüe"], ["lü", "e"]])
|
|
54
|
+
assert sorted(split("lue")) == sorted([["lue"], ["lu", "e"]])
|
|
55
|
+
assert sorted(split("nüe")) == sorted([["nüe"], ["nü", "e"]])
|
|
56
|
+
assert sorted(split("nue")) == sorted([["nue"], ["nu", "e"]])
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_overlapping_possibilities():
|
|
60
|
+
"""Test cases where syllables could overlap"""
|
|
61
|
+
# The current implementation finds all valid splits
|
|
62
|
+
assert sorted(split("shangai")) == sorted([["shang", "ai"], ["shan", "gai"]])
|
|
63
|
+
assert sorted(split("haixian")) == sorted([["hai", "xian"], ["hai", "xi", "an"]])
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
version = 1
|
|
2
|
+
requires-python = ">=3.8"
|
|
3
|
+
|
|
4
|
+
[[package]]
|
|
5
|
+
name = "pinyin-split"
|
|
6
|
+
version = "0.0.1"
|
|
7
|
+
source = { editable = "." }
|
|
8
|
+
dependencies = [
|
|
9
|
+
{ name = "pygtrie" },
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[package.metadata]
|
|
13
|
+
requires-dist = [{ name = "pygtrie", specifier = ">=2.5.0" }]
|
|
14
|
+
|
|
15
|
+
[[package]]
|
|
16
|
+
name = "pygtrie"
|
|
17
|
+
version = "2.5.0"
|
|
18
|
+
source = { registry = "https://pypi.org/simple" }
|
|
19
|
+
sdist = { url = "https://files.pythonhosted.org/packages/b9/13/55deec25bf09383216fa7f1dfcdbfca40a04aa00b6d15a5cbf25af8fce5f/pygtrie-2.5.0.tar.gz", hash = "sha256:203514ad826eb403dab1d2e2ddd034e0d1534bbe4dbe0213bb0593f66beba4e2", size = 39266 }
|
|
20
|
+
wheels = [
|
|
21
|
+
{ url = "https://files.pythonhosted.org/packages/ec/cd/bd196b2cf014afb1009de8b0f05ecd54011d881944e62763f3c1b1e8ef37/pygtrie-2.5.0-py3-none-any.whl", hash = "sha256:8795cda8105493d5ae159a5bef313ff13156c5d4d72feddefacaad59f8c8ce16", size = 25099 },
|
|
22
|
+
]
|