name-pinyin 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.
- name_pinyin-0/LICENSE +21 -0
- name_pinyin-0/PKG-INFO +46 -0
- name_pinyin-0/README.md +31 -0
- name_pinyin-0/name_pinyin/__init__.py +105 -0
- name_pinyin-0/name_pinyin.egg-info/PKG-INFO +46 -0
- name_pinyin-0/name_pinyin.egg-info/SOURCES.txt +9 -0
- name_pinyin-0/name_pinyin.egg-info/dependency_links.txt +1 -0
- name_pinyin-0/name_pinyin.egg-info/requires.txt +1 -0
- name_pinyin-0/name_pinyin.egg-info/top_level.txt +1 -0
- name_pinyin-0/setup.cfg +4 -0
- name_pinyin-0/setup.py +22 -0
name_pinyin-0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 qaq_fei
|
|
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.
|
name_pinyin-0/PKG-INFO
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: name_pinyin
|
|
3
|
+
Version: 0
|
|
4
|
+
Summary: A library for validating pinyin against Chinese names.
|
|
5
|
+
Home-page: https://github.com/qaqFei/name_pinyin
|
|
6
|
+
Author: qaqFei
|
|
7
|
+
Author-email: qaq_fei@163.com
|
|
8
|
+
License: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Requires-Python: >=3.8.0
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: pypinyin
|
|
15
|
+
|
|
16
|
+
# name_pinyin
|
|
17
|
+
|
|
18
|
+
A library for validating pinyin against Chinese names.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install name_pinyin
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from name_pinyin import match_pinyin_name
|
|
30
|
+
|
|
31
|
+
# full pinyin
|
|
32
|
+
match_pinyin_name("欧阳锋", "ouyangfeng") # True
|
|
33
|
+
match_pinyin_name("诸葛亮", "zhugeliang") # True
|
|
34
|
+
|
|
35
|
+
# initials
|
|
36
|
+
match_pinyin_name("欧阳锋", "oyf") # True
|
|
37
|
+
match_pinyin_name("诸葛亮", "zgl") # True
|
|
38
|
+
|
|
39
|
+
# mixed full pinyin and initials
|
|
40
|
+
match_pinyin_name("欧阳锋", "ouyangf") # True
|
|
41
|
+
match_pinyin_name("诸葛亮", "zhugeliang") # True
|
|
42
|
+
|
|
43
|
+
# case insensitive, spaces and hyphens are ignored
|
|
44
|
+
match_pinyin_name("欧阳锋", "Ou Yang Feng") # True
|
|
45
|
+
match_pinyin_name("欧阳锋", "ou-yang-feng") # True
|
|
46
|
+
```
|
name_pinyin-0/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# name_pinyin
|
|
2
|
+
|
|
3
|
+
A library for validating pinyin against Chinese names.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install name_pinyin
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from name_pinyin import match_pinyin_name
|
|
15
|
+
|
|
16
|
+
# full pinyin
|
|
17
|
+
match_pinyin_name("欧阳锋", "ouyangfeng") # True
|
|
18
|
+
match_pinyin_name("诸葛亮", "zhugeliang") # True
|
|
19
|
+
|
|
20
|
+
# initials
|
|
21
|
+
match_pinyin_name("欧阳锋", "oyf") # True
|
|
22
|
+
match_pinyin_name("诸葛亮", "zgl") # True
|
|
23
|
+
|
|
24
|
+
# mixed full pinyin and initials
|
|
25
|
+
match_pinyin_name("欧阳锋", "ouyangf") # True
|
|
26
|
+
match_pinyin_name("诸葛亮", "zhugeliang") # True
|
|
27
|
+
|
|
28
|
+
# case insensitive, spaces and hyphens are ignored
|
|
29
|
+
match_pinyin_name("欧阳锋", "Ou Yang Feng") # True
|
|
30
|
+
match_pinyin_name("欧阳锋", "ou-yang-feng") # True
|
|
31
|
+
```
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import functools
|
|
3
|
+
|
|
4
|
+
import pypinyin
|
|
5
|
+
|
|
6
|
+
__version__ = 0
|
|
7
|
+
__all__ = ["match_pinyin_name"]
|
|
8
|
+
|
|
9
|
+
SURNAME_FIX = {
|
|
10
|
+
"单": "shan", "仇": "qiu", "解": "xie", "查": "zha", "区": "ou",
|
|
11
|
+
"朴": "piao", "乐": "yue", "覃": "qin", "盖": "ge", "繁": "po",
|
|
12
|
+
"种": "chong", "秘": "bi", "员": "yun", "能": "nai", "阚": "kan",
|
|
13
|
+
"都": "du", "句": "gou", "缪": "miao", "乜": "nie", "华": "hua",
|
|
14
|
+
"曲": "qu", "哈": "ha", "要": "yao", "任": "ren", "应": "ying",
|
|
15
|
+
"过": "guo", "谌": "chen",
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
COMPOUND_SURNAMES = {
|
|
19
|
+
"欧阳", "司马", "上官", "夏侯", "诸葛", "东方", "皇甫",
|
|
20
|
+
"尉迟", "公孙", "慕容", "长孙", "宇文", "司徒", "司空",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@functools.lru_cache(maxsize=4096)
|
|
24
|
+
def _name_to_pinyin(name: str) -> tuple[tuple[str, ...], ...]:
|
|
25
|
+
if not name:
|
|
26
|
+
return ()
|
|
27
|
+
|
|
28
|
+
surname_len = 1
|
|
29
|
+
for comp in COMPOUND_SURNAMES:
|
|
30
|
+
if name.startswith(comp):
|
|
31
|
+
surname_len = len(comp)
|
|
32
|
+
break
|
|
33
|
+
|
|
34
|
+
surname = name[:surname_len]
|
|
35
|
+
given = name[surname_len:]
|
|
36
|
+
|
|
37
|
+
result: list[tuple[str, ...]] = []
|
|
38
|
+
|
|
39
|
+
for ch in surname:
|
|
40
|
+
py = pypinyin.lazy_pinyin(ch, style=pypinyin.NORMAL)
|
|
41
|
+
base = tuple(py) if py else (ch,)
|
|
42
|
+
if ch in SURNAME_FIX:
|
|
43
|
+
result.append((SURNAME_FIX[ch],) + base)
|
|
44
|
+
else:
|
|
45
|
+
result.append(base)
|
|
46
|
+
|
|
47
|
+
for ch in given:
|
|
48
|
+
py = pypinyin.lazy_pinyin(ch, style=pypinyin.NORMAL)
|
|
49
|
+
base = tuple(py) if py else (ch,)
|
|
50
|
+
if ch in SURNAME_FIX and SURNAME_FIX[ch] not in base:
|
|
51
|
+
result.append(base + (SURNAME_FIX[ch],))
|
|
52
|
+
else:
|
|
53
|
+
result.append(base)
|
|
54
|
+
|
|
55
|
+
return tuple(result)
|
|
56
|
+
|
|
57
|
+
def _initials(syllable: str) -> list[str]:
|
|
58
|
+
cands = [syllable]
|
|
59
|
+
if syllable.startswith(("zh", "ch", "sh")):
|
|
60
|
+
cands.append(syllable[:2])
|
|
61
|
+
cands.append(syllable[0])
|
|
62
|
+
elif syllable and syllable[0].isalpha():
|
|
63
|
+
cands.append(syllable[0])
|
|
64
|
+
return cands
|
|
65
|
+
|
|
66
|
+
def _match_syllables(syllables: tuple[tuple[str, ...], ...], sub: str) -> bool:
|
|
67
|
+
parts: list[list[str]] = []
|
|
68
|
+
for candidates in syllables:
|
|
69
|
+
if not candidates:
|
|
70
|
+
continue
|
|
71
|
+
letter_cands = [c for c in candidates if c.isalpha()]
|
|
72
|
+
if not letter_cands:
|
|
73
|
+
continue
|
|
74
|
+
expanded: list[str] = []
|
|
75
|
+
for c in letter_cands:
|
|
76
|
+
expanded.extend(_initials(c.lower()))
|
|
77
|
+
seen = set()
|
|
78
|
+
parts.append([x for x in expanded if not (x in seen or seen.add(x))])
|
|
79
|
+
|
|
80
|
+
if not parts:
|
|
81
|
+
return sub == ""
|
|
82
|
+
|
|
83
|
+
sub = sub.lower()
|
|
84
|
+
n = len(parts)
|
|
85
|
+
|
|
86
|
+
@functools.lru_cache(maxsize=None)
|
|
87
|
+
def dfs(i: int, pos: int) -> bool:
|
|
88
|
+
if i == n:
|
|
89
|
+
return pos == len(sub)
|
|
90
|
+
if dfs(i + 1, pos):
|
|
91
|
+
return True
|
|
92
|
+
for cand in parts[i]:
|
|
93
|
+
if sub.startswith(cand, pos):
|
|
94
|
+
if dfs(i + 1, pos + len(cand)):
|
|
95
|
+
return True
|
|
96
|
+
return False
|
|
97
|
+
|
|
98
|
+
return dfs(0, 0)
|
|
99
|
+
|
|
100
|
+
def match_pinyin_name(name: str, sub: str) -> bool:
|
|
101
|
+
if not isinstance(name, str) or not isinstance(sub, str):
|
|
102
|
+
return False
|
|
103
|
+
cleaned = "".join(ch for ch in sub if ch.isalnum())
|
|
104
|
+
syllables = _name_to_pinyin(name)
|
|
105
|
+
return _match_syllables(syllables, cleaned)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: name_pinyin
|
|
3
|
+
Version: 0
|
|
4
|
+
Summary: A library for validating pinyin against Chinese names.
|
|
5
|
+
Home-page: https://github.com/qaqFei/name_pinyin
|
|
6
|
+
Author: qaqFei
|
|
7
|
+
Author-email: qaq_fei@163.com
|
|
8
|
+
License: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Requires-Python: >=3.8.0
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: pypinyin
|
|
15
|
+
|
|
16
|
+
# name_pinyin
|
|
17
|
+
|
|
18
|
+
A library for validating pinyin against Chinese names.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install name_pinyin
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from name_pinyin import match_pinyin_name
|
|
30
|
+
|
|
31
|
+
# full pinyin
|
|
32
|
+
match_pinyin_name("欧阳锋", "ouyangfeng") # True
|
|
33
|
+
match_pinyin_name("诸葛亮", "zhugeliang") # True
|
|
34
|
+
|
|
35
|
+
# initials
|
|
36
|
+
match_pinyin_name("欧阳锋", "oyf") # True
|
|
37
|
+
match_pinyin_name("诸葛亮", "zgl") # True
|
|
38
|
+
|
|
39
|
+
# mixed full pinyin and initials
|
|
40
|
+
match_pinyin_name("欧阳锋", "ouyangf") # True
|
|
41
|
+
match_pinyin_name("诸葛亮", "zhugeliang") # True
|
|
42
|
+
|
|
43
|
+
# case insensitive, spaces and hyphens are ignored
|
|
44
|
+
match_pinyin_name("欧阳锋", "Ou Yang Feng") # True
|
|
45
|
+
match_pinyin_name("欧阳锋", "ou-yang-feng") # True
|
|
46
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pypinyin
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
name_pinyin
|
name_pinyin-0/setup.cfg
ADDED
name_pinyin-0/setup.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import setuptools
|
|
2
|
+
|
|
3
|
+
import name_pinyin
|
|
4
|
+
|
|
5
|
+
setuptools.setup(
|
|
6
|
+
name = "name_pinyin",
|
|
7
|
+
version = f"{name_pinyin.__version__}",
|
|
8
|
+
description = "A library for validating pinyin against Chinese names.",
|
|
9
|
+
long_description = open("README.md", "r", encoding="utf-8").read(),
|
|
10
|
+
long_description_content_type = "text/markdown",
|
|
11
|
+
author = "qaqFei",
|
|
12
|
+
author_email = "qaq_fei@163.com",
|
|
13
|
+
url = "https://github.com/qaqFei/name_pinyin",
|
|
14
|
+
packages = setuptools.find_packages(),
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3.8",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
],
|
|
19
|
+
install_requires = ["pypinyin"],
|
|
20
|
+
license = "MIT License",
|
|
21
|
+
python_requires = ">=3.8.0"
|
|
22
|
+
)
|