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

Add support for Pinyin with tone numbers instead of accents. #220

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 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,
tone_marks_to_numbers,
)
from .translate import translate
from .util import (
Expand Down Expand Up @@ -152,6 +153,12 @@ def fill_transcript(hanzi, note):
else:
reformat_transcript(note, key, target)

if get_first(config['fields']['pinyinNum'], note) == '':
t = transcribe(separated, target, type_)
s = tone_marks_to_numbers(str.join(" ", t))
set_all(config['fields']['pinyinNum'], note, to=s)
n_filled += 1

return n_filled


Expand Down
3 changes: 3 additions & 0 deletions chinese/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
"大陸拼音",
"拼音"
],
"pinyinNum": [
"PinyinNum"
],
"pinyinTaiwan": [
"Pinyin (Taiwan)",
"台湾拼音",
Expand Down
4 changes: 4 additions & 0 deletions chinese/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ def _split(pattern, s):

return list(filter(lambda s: s.strip(), separated))

def tone_marks_to_numbers(s):
assert isinstance(s, str)
s2, *_ = replace_tone_marks([cleanup(s)])
return s2

def tone_number(s):
assert isinstance(s, str)
Expand Down