#! /usr/bin/python3
# Last edited on 2026-03-18 23:41:18 by stolfi

import os, sys, re;
from sys import stdin as inp, stdout as out, stderr as err

def main():
  inp.reconfigure(encoding="utf-8")
  out.reconfigure(encoding="utf-8")
  
  out.write("# Created by {convert_pinyn_to_numeric.py} - do not edit.\n")
  out.write("# -*- coding: utf-8 -*-\n")
  
  pinyin_vows = r"āēīōūǖ" + r"àèìòùǜ" + r"áéíóúǘ" + r"ǎěǐǒǔǚ"
  unmark_vows = r"aeiouü" * 4
  ntones_nums = r"111111" + r"444444" + r"222222" + r"333333"

  pats = []
  subs = []
  nv = len(pinyin_vows)
  for i in range (nv):
    pats.append(re.compile(pinyin_vows[i]))
    subs.append(unmark_vows[i] + ntones_nums[i])

  for line in inp:
    line = line.strip()
    if re.match(r"[ ]*([#]|$)", line):
      continue
    else:
      m = re.fullmatch(r"([<][a-z][0-9.]+[>])[ ]*(.*)", line)
      if m != None:
        loc = m.group(1)
        line = m.group(2)
      else:
        loc = ""
      line = re.sub(r"[\]\[.,;:()]", " ", line)
      words = line.split()
      out.write(loc);
      for word in words:
        word = word.lower()
        for i in range (nv):
          word = re.sub(pats[i], subs[i], word)
        word = re.sub(r"ü", "uu", word)
        word = re.sub(r"^(.*)([0-9])(.*)$", r"\1\3\2", word)
        if re.fullmatch(r"[a-z]+", word): word += "5"
        out.write(" "); out.write(word)
      out.write("\n")
  return
  # ----------------------------------------------------------------------
    
main()
