Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit 682a973

Browse files
committed
Add support for pinyin field with tone numbers
resolves #56
1 parent c45c286 commit 682a973

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

chinese/behavior.py

+15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
sanitize_transcript,
2929
split_transcript,
3030
transcribe,
31+
get_tone_number_pinyin,
3132
)
3233
from .translate import translate
3334
from .util import (
@@ -155,6 +156,19 @@ def fill_transcript(hanzi, note):
155156
return n_filled
156157

157158

159+
def fill_tone_numbers(hanzi, note):
160+
filled = False
161+
separated = split_hanzi(hanzi, grouped=False)
162+
163+
if get_first(config['fields']['toneNumbers'], note) == '':
164+
trans = transcribe(separated, 'pinyin', 'simp')
165+
tones = [get_tone_number_pinyin(t) for t in trans]
166+
set_all(config['fields']['toneNumbers'], note, to=' '.join(tones))
167+
filled = True
168+
169+
return filled
170+
171+
158172
def reformat_transcript(note, group, target):
159173
if target == 'bopomofo':
160174
return
@@ -311,6 +325,7 @@ def update_fields(note, focus_field, fields):
311325
fill_all_defs(hanzi, copy)
312326
fill_classifier(hanzi, copy)
313327
fill_transcript(hanzi, copy)
328+
fill_tone_numbers(hanzi, copy)
314329
fill_trad(hanzi, copy)
315330
fill_color(hanzi, copy)
316331
fill_sound(hanzi, copy)

chinese/config.json

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
"法語",
3535
"法语"
3636
],
37+
"toneNumbers": [
38+
"Tone Numbers",
39+
"Tones",
40+
"NumPinyin"
41+
],
3742
"pinyin": [
3843
"Pinyin",
3944
"Reading",

tests/test_config.py

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def test_get_fields_no_arg(self):
3737
'Hanzi (Color)',
3838
'Hanzi',
3939
'Measure Word',
40+
"NumPinyin",
4041
'Pinyin (Taiwan)',
4142
'Pinyin',
4243
'Reading',
@@ -55,6 +56,8 @@ def test_get_fields_no_arg(self):
5556
'Sound (Mandarin)',
5657
'Sound',
5758
'Spoken',
59+
'Tone Numbers',
60+
'Tones',
5861
'Trad',
5962
'Trad.',
6063
'TradColor',

0 commit comments

Comments
 (0)