Last active
March 25, 2022 12:27
-
-
Save stevendaniels/2481b966fd298e3d2334ca4c59edd04a to your computer and use it in GitHub Desktop.
Creating pinyin flashcards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Used to create tables for importing into quizlet. | |
# gem install zhongwen_tools | |
require 'zhongwen_tools' | |
require 'zhongwen_tools/core_ext/string' | |
def random_tone; (1..4).to_a.sample; end | |
def tsv_list(pyn); [pyn, pyn].join("\t"); end | |
def pinyin_list | |
pyn = ZhongwenTools::Romanization::ROMANIZATIONS_TABLE.map { |k| k[:pyn]} | |
pyns = pyn.flat_map { |p| "#{p}#{random_tone}"} | |
pyns.map { |p| p.to_py rescue p } | |
end | |
PINYIN_INITIALS = { | |
bpmf: /^[bpmf]/, | |
dtnl: /^[dtnl]/, | |
gkh: /^[gkh]/, | |
zsc: /^[zsc][^h]/, | |
zhchshr: /^([zsc]h|r)/, | |
jqx: /^[jqx]/, | |
aeoy: /^[yāáǎàēéěèōóǒò]/ | |
} | |
def pinyins_table(initial:) | |
regex = PINYIN_INITIALS.fetch(initial) | |
puts pinyin_list.select { |p| p[regex] }.map{ |p| tsv_list(p)} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fix: nue2, lvn3