Mel Seto commited on
Commit
46bdae9
·
1 Parent(s): 24f0565

add pypinyin and test

Browse files
pyproject.toml CHANGED
@@ -6,6 +6,8 @@ readme = "README.md"
6
  requires-python = ">=3.12"
7
  dependencies = [
8
  "gradio>=4.44.1",
 
 
9
  ]
10
 
11
  [dependency-groups]
 
6
  requires-python = ">=3.12"
7
  dependencies = [
8
  "gradio>=4.44.1",
9
+ "pypinyin>=0.55.0",
10
+ "pytest>=8.4.2",
11
  ]
12
 
13
  [dependency-groups]
tests/__init__.py ADDED
File without changes
tests/test_utils.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ from utils.utils import get_pinyin
3
+
4
+ @pytest.mark.parametrize("text, expected", [
5
+ ("举棋不定", "jǔ qí bù dìng"),
6
+ ("风", "fēng"),
7
+ ("不怕慢,就怕站", "bù pà màn , jiù pà zhàn"),
8
+ ])
9
+ def test_get_pinyin_accent(text, expected):
10
+ assert get_pinyin(text) == expected
utils/__init__.py ADDED
File without changes
utils/utils.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from pypinyin import pinyin, Style
2
+
3
+ def get_pinyin(text: str):
4
+ """Convert Chinese characters to pinyin with tones."""
5
+ py_list = pinyin(text, style=Style.TONE, heteronym=False)
6
+ return " ".join([syllable[0] for syllable in py_list])