Mario Hilgemeier

Japanese Kana Writing Exercise Sheet

#!/usr/bin/python
#
# romaji2kana -------
# 2004 by Mario Hilgemeier http://hilgemeier.gmxhome.de
#
# Task: produce a test sheet for writing exercises
#       of katakana or hiragana characters
#       for each given romaji syllable;
#       the test sheet will be in random order
#
# usage: romaji2kana_01.py t > kana.test
#
# kana.test is the text file for printout
# t is the test type:
# t  syllable set
# 1  basic kana
# 2  basic + voiced + unvoiced
# 3  basic + voiced + unvoiced + combinations
#
# romaji2kana_01: 2004-09-29, all kana; value: 2.50 hours
# ! ji and zu have two answers each, therefore ji2 and zu2
#   are printed.

import sys
import string
import whrandom

test_type = string.atoi(sys.argv[1])

basic = ["a", "i", "u", "e", "o",
"ka", "ki", "ku", "ke", "ko",
"sa", "shi", "su", "se", "so",
"ta", "chi", "tsu", "te", "to",
"na", "ni", "nu", "ne", "no",
"ha", "hi", "fu", "he", "ho",
"ma", "mi", "mu", "me", "mo",
"ya",       "yu",       "yo",
"ra", "ri", "ru", "re", "ro",
"wa",       "wo",       "n"]

voiced = ["ga", "gi", "gu", "ge", "go",
"za", "ji2", "zu2", "ze", "zo",
"da", "de", "do",
"ba", "bi", "bu", "be", "bo",
"pa", "pi", "pu", "pe", "po",
] # and unvoiced

combined = ["kya","kyu","kyo",
"gya","gyu","gyo",
"sha","shu","sho",
"ja","ju","jo",
"cha","chu","cho",
"nya","nyu","nyo",
"hya","hyu","hyo",
"bya","byu","byo",
"pya","pyu","pyo",
"mya","myu","myo",
"rya","ryu","ryo"]

# assemble the selected lists
if (test_type == 1):
  allsyl = basic
  print "\nkana test : basic\n---------\n"
elif (test_type == 2):
  allsyl = basic + voiced
  print "\nkana test : basic + voiced + unvoiced \n---------\n"
elif (test_type == 3):
  allsyl = basic + voiced + combined
  print "\nkana test : basic + voiced + unvoiced + combinations \n---------\n"
else:
  allsyl = basic
syllables = len(allsyl)
# print syllables, allsyl

# randomize their concatenation
whrandom.seed(0,0,0) # time-based randomization
for i in xrange (0, syllables):
  j = whrandom.randint(i, syllables-1)
  exchg = allsyl.pop(j)
  allsyl.insert(i, exchg)

# print test sheet with syllables in groups of 6

spaceA = "\n\n\n    "
spaceB = "         "
for i in xrange (0, syllables):
  if ((i % 6) == 0):
    print spaceA, allsyl[i],
  else:
    print spaceB, allsyl[i],

print spaceA,"python program available at http://hilgemeier.gmxhome.de/codes/index.html"

--------------------------------------

Download Python code romaji2kana_01.py


Algorithms and Program Codes


© Copyright 2001-2004 Mario Hilgemeier, email: contact
homepage stylized apple blossom