-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinyinToZhuyinDialnumCodegen.py
executable file
·62 lines (58 loc) · 1.89 KB
/
pinyinToZhuyinDialnumCodegen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
import csv
import sys
if len(sys.argv) < 2:
print ( "Give me the file path" )
exit(1)
with open(sys.argv[1], 'rb') as csvfile:
data = csv.reader(csvfile)
quote = "'"
dquote = "\""
separator = ", "
javaUniPrefix = "\\u"
VowelConsonant = ""
Combination = ""
ZhuyinSignChar = ""
ZhuyinSound = ""
ZhuyinSoundMappingDialerNum = ""
theConsonantRow = None
theConsonantRowSound = None
theConsonantP = None
totalCount = 0
for i, row in enumerate(data):
if ( i < 1 ):
theConsonantRow = row
continue
elif ( i == 1 ):
theConsonantRowSound = row
#
for j, col in enumerate(row):
if ( j < 1 ):
continue
if ( i == 1 and j > 1 ):
theSign = theConsonantRow[j]
VowelConsonant += "consonant2num.put(\"" + col + "\", \"\"); // " + theSign + "\n"
if ( len( theSign ) < 5 ):
theCoded = str(hex(ord(theSign.decode('utf-8'))))[2:] # No 0x prefix
ZhuyinSignChar += quote + javaUniPrefix + theCoded + quote + separator
ZhuyinSound += dquote + theConsonantRowSound[j] + dquote + separator
theConsonantP = row
continue
elif ( j == 1 and i > 1 ):
theSign = row[0]
VowelConsonant += "vowel2num.put(\"" + col + "\", \"\"); // " + theSign + "\n"
if ( len( theSign ) < 5 ):
theCoded = str(hex(ord(theSign.decode('utf-8'))))[2:] # No 0x prefix
ZhuyinSignChar += quote + javaUniPrefix + theCoded + quote + separator
ZhuyinSound += dquote + row[1] + dquote + separator
continue
if ( col == "" ):
continue
Combination += "p2zMap.put(\"" + col + "\", consonant2num.get(\"" + theConsonantP[j] + "\")" + " + " + "vowel2num.get(\"" + row[1] + "\") " + ");" + "\n"
totalCount += 1;
print VowelConsonant
print Combination
print totalCount
#
print ZhuyinSignChar
print ZhuyinSound