Skip to content

Commit

Permalink
Add tone number pinyin field
Browse files Browse the repository at this point in the history
resolves jdlorimer#56
  • Loading branch information
sc-rwirnata committed May 22, 2022
1 parent c45c286 commit 3bb9132
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions chinese/behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
sanitize_transcript,
split_transcript,
transcribe,
get_tone_number_pinyin,
)
from .translate import translate
from .util import (
Expand Down Expand Up @@ -155,6 +156,19 @@ def fill_transcript(hanzi, note):
return n_filled


def fill_numpinyin(hanzi, note):
key = 'numpinyin'
separated = split_hanzi(hanzi, grouped=False)

if get_first(config['fields'][key], note) == '':
trans = transcribe(separated, 'pinyin', 'simp')
tone = ""
for t in trans:
tone += get_tone_number_pinyin(t) + ' '

set_all(config['fields'][key], note, to=tone.strip())


def reformat_transcript(note, group, target):
if target == 'bopomofo':
return
Expand Down Expand Up @@ -311,6 +325,7 @@ def update_fields(note, focus_field, fields):
fill_all_defs(hanzi, copy)
fill_classifier(hanzi, copy)
fill_transcript(hanzi, copy)
fill_numpinyin(hanzi, copy)
fill_trad(hanzi, copy)
fill_color(hanzi, copy)
fill_sound(hanzi, copy)
Expand Down
4 changes: 4 additions & 0 deletions chinese/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
"法語",
"法语"
],
"numpinyin": [
"NumPinyin",
"Tone Number"
],
"pinyin": [
"Pinyin",
"Reading",
Expand Down

0 comments on commit 3bb9132

Please sign in to comment.