Skip to content

Instantly share code, notes, and snippets.

@stevendaniels
Last active March 25, 2022 12:27
Show Gist options
  • Save stevendaniels/2481b966fd298e3d2334ca4c59edd04a to your computer and use it in GitHub Desktop.
Save stevendaniels/2481b966fd298e3d2334ca4c59edd04a to your computer and use it in GitHub Desktop.
Creating pinyin flashcards
# 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
@stevendaniels
Copy link
Author

fix: nue2, lvn3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment