Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. """ dictionary = [
  2. # consonant letters
  3. 'ㄱ', # = k / g
  4. 'ㄴ', # = n
  5. 'ㄷ', # = d / t
  6. 'ㄹ', # = r / l
  7. 'ㅁ', # = m
  8. 'ㅇ', # = none / ng
  9. 'ㅂ', # = b
  10. 'ㅅ', # = s
  11. 'ㅈ', # = j
  12. 'ㅎ', # = h
  13.  
  14. # vowels letters
  15. 'ㅣ', # = i
  16. 'ㅏ', # = a
  17. 'ㅓ', # = eo (Romanized as “eo” but it sounds closer to “uh” in English)
  18. 'ㅡ', # = eu
  19. 'ㅜ', # = u
  20. 'ㅗ', # = o
  21.  
  22. # iotized vowels
  23. 'ㅑ', # = ya
  24. 'ㅕ', # = yeo
  25. 'ㅛ', # = yo
  26. 'ㅠ', # = yu
  27.  
  28. # double ("tense") consonants
  29. 'ㄲ', # = kk
  30. 'ㄸ', # = tt
  31. 'ㅃ', # = pp
  32. 'ㅆ', # = ss
  33. 'ㅉ', # = jj
  34.  
  35. # consonant clusters
  36. 'ㄳ', # = gs
  37. 'ㄵ', # = nj
  38. 'ㄶ', # = nh
  39. 'ㄺ', # = lg
  40. 'ㄻ', # = lm
  41. 'ㄼ', # = lb
  42. 'ㄽ', # = ls
  43. 'ㄾ', # = lt
  44. 'ㄿ', # = lp
  45. 'ㅀ', # = lh
  46. 'ㅄ', # = bs
  47.  
  48. # iotized diphthongs
  49. 'ㅐ', # = ae
  50. 'ㅒ', # = yae
  51. 'ㅔ', # = e
  52. 'ㅖ', # = ye
  53. 'ㅢ', # = ui
  54.  
  55. # vowels and diphthongs with a w
  56. 'ㅘ', # = wa
  57. 'ㅙ', # = wae
  58. 'ㅚ', # = oe
  59. 'ㅝ', # = wo
  60. 'ㅞ', # = we
  61. 'ㅟ' # = wi
  62. ] """
  63.  
  64. initial_jamo = [ # U+1100 - U+1112
  65. 'g', 'gg', 'n', 'd',
  66. 'dd', 'r', 'm', 'b',
  67. 'bb','s', 'ss', '',
  68. 'j', 'jj', 'ch', 'k',
  69. 't', 'p', 'h'
  70. ]
  71.  
  72. medial_jamo = [ # U+1161 - U+1175
  73. 'a', 'ae','ya','yae',
  74. 'eo', 'e','yeo','ye',
  75. 'o','wa','wae','oe',
  76. 'yo','u','weo','we',
  77. 'wi','yu','eu','eui',
  78. 'i'
  79. ]
  80.  
  81.  
  82. end_jamo = [
  83. '',' g', 'gg', 'gs',
  84. 'n', 'nj','nh','d',
  85. 'l', 'rk', 'rm', 'rb',
  86. 'rs', 'rt', 'rp', 'rh',
  87. 'm', 'b', 'bs', 's',
  88. 'ss', 'ng', 'j', 'ch',
  89. 'k', 't', 'p', 'h'
  90. ]
  91.  
  92.  
  93. first_unicode = 0xac00 # equal to 44032
  94. last_unicode = 0xd7a3
  95.  
  96.  
  97. def romanizate(text):
  98. romanized = u''
  99. for chr in text:
  100. if first_unicode <= ord(chr) <= last_unicode:
  101. head = int(math.floor((ord(chr - first_unicode)) / 588))
  102. head1 = int(math.floor((ord(chr - first_unicode)) % 588))
  103. body = int(math.floor(head1 / 588))
  104. tail = int(math.floor(head1 % 588))
  105. romanized += initial_jamo[head]
  106. romanized += medial_jamo[body]
  107. romanized += end_jamo[tail]
  108.  
  109.  
  110. def is_correct(symbol, result):
  111. return result == kroman.parse(symbol)
  112.  
  113.  
  114. def do_u_want_to_play(count_of_symbols):
  115. if count_of_symbols < len(alphabet):
  116. temp_alphabet = alphabet
  117. for i in range(count_of_symbols):
  118. rand_index = random.randrange(count_of_symbols - i)
  119. test_symbol = temp_alphabet[rand_index]
  120. answer = input("let me translate for {}: ".format(test_symbol))
  121. if is_correct(test_symbol, answer):
  122. print("Right")
  123. temp_alphabet.pop(rand_index)
  124. else:
  125. print("Try harder, right answer is: {}".format(kroman.parse(test_symbol)))
  126.  
  127. do_u_want_to_play(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement