Skip to content

Commit

Permalink
Add support for 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 23, 2022
1 parent c45c286 commit 61b2324
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 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,20 @@ def fill_transcript(hanzi, note):
return n_filled


def fill_numpinyin(hanzi, note):
filled = False
separated = split_hanzi(hanzi, grouped=False)

if get_first(config['fields']['numpinyin'], note) == '':
trans = transcribe(separated, 'pinyin', 'simp')
tones = [get_tone_number_pinyin(t) for t in trans]
set_all(config['fields']['numpinyin'], note, to=' '.join(tones))
filled = True

return filled



def reformat_transcript(note, group, target):
if target == 'bopomofo':
return
Expand Down Expand Up @@ -311,6 +326,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 61b2324

Please sign in to comment.