py-pinyin-split 0.1.0rc0__py3-none-any.whl

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.
@@ -0,0 +1,4 @@
1
+ # SPDX-FileCopyrightText: 2024-present Lukas Strobel <mail@lstrobel.com>
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ __version__ = "0.1.0rc0"
@@ -0,0 +1,5 @@
1
+ # SPDX-FileCopyrightText: 2024-present Lukas Strobel <mail@lstrobel.com>
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ from .pinyinsplit import *
@@ -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
pinyin_split/py.typed ADDED
File without changes
@@ -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,8 @@
1
+ pinyin_split/__about__.py,sha256=sLnDninEDyHmmjsr-DqhwLTLkD3RnqdlcbujIk3SD8k,131
2
+ pinyin_split/__init__.py,sha256=C_yW3uPj81PKc5Jw0D1B1O04W15USdAI699x3081peE,133
3
+ pinyin_split/pinyinsplit.py,sha256=8c3aqERo59jYvmK2nDAcqGlgNQd2quscbZUNDP-6tNI,5813
4
+ pinyin_split/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ py_pinyin_split-0.1.0rc0.dist-info/METADATA,sha256=mUswC5Buu1khf2dBU8qBRspQb7gaDXdbLVoLtCH90JA,1962
6
+ py_pinyin_split-0.1.0rc0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
7
+ py_pinyin_split-0.1.0rc0.dist-info/licenses/LICENSE.txt,sha256=2AwJzKbLVny2U88ZQxtPU6SAyh_Rw1Lp_lchwKghIOY,1097
8
+ py_pinyin_split-0.1.0rc0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.26.3
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -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.