-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdemo.py
95 lines (86 loc) · 2.49 KB
/
demo.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import bophono
import sys
options_fast = {
'weakAspirationChar': '',
'aspirateLowTones': False,
'prefixStrategy': 'always',
'aiAffixchar': 'ː',
'hightonechar':'',
'lowtonechar':'',
'nasalchar': '',
'stopSDMode': "eow",
'useUnreleasedStops': False,
'eatR': True,
'eatL': True,
'syllablesepchar': ''
}
options_fastidious = {
'weakAspirationChar': '3',
'aspirateLowTones': True,
'prefixStrategy': 'always',
'aiAffixchar': 'ː',
'hightonechar':'̄',
'lowtonechar':'̱',
'nasalchar': '',
'stopSDMode': "eow",
'eatP': False,
'useUnreleasedStops': True,
'eatK': False,
'syllablesepchar': ''
}
def toEnglish(s, mode):
s = s.replace("y", "ü")
if (mode == "expert"):
s = s.replace("ɔ", "o1")
s = s.replace("ɣ", "g2")
s = s.replace("̊", "1")
s = s.replace("̥", "1")
else:
s = s.replace("ɔ", "o")
s = s.replace("ɣ", "g")
s = s.replace("̊", "")
s = s.replace("̥", "")
s = s.replace("ɖ", "ḍ")
s = s.replace("ʈ", "ṭ")
s = s.replace("ɲ", "ny")
s = s.replace("ø", "ö")
s = s.replace("ɟ", "gy")
s = s.replace("c", "ky")
s = s.replace("j", "y")
s = s.replace("ɛ", "è")
s = s.replace("e", "é")
s = s.replace("ŋ", "ṅ")
s = s.replace("tɕ", "ch")
s = s.replace("ɕ", "sh")
s = s.replace("dʑ", "j")
s = s.replace("dz", "z")
return s
filename = 'tests/demo.txt'
converter_fastidious = bophono.UnicodeToApi(schema="MST", options = options_fastidious)
converter_fast = bophono.UnicodeToApi(schema="MST", options = options_fast)
converter_kvp = bophono.UnicodeToApi(schema="KVP", options = options_fast)
if (len(sys.argv) > 1):
filename = sys.argv[1]
with open(filename, 'r', encoding="utf8") as f:
for line in f:
line = line[:-1]
if line == '':
continue
if line.startswith('#'):
print(line[1:])
continue
print("Unicode: "+line)
words = line.split()
res_kvp = ""
res_api = ""
for word in words:
res_kvp += converter_kvp.get_api(word)+' '
res_api += converter_fast.get_api(word)+' '
print("MST-schema: "+res_api)
print("KVP-schema: "+res_kvp)
#Chinese transcription
sentence = "བཀྲ་ཤིས་"
api = converter_fast.get_api(sentence)
zh = bophono.apitochinese.api2chinese(api)
print("\n" + sentence + " -> " + api + \
" -> " + zh["zhuyin"] + " -> " + zh["chinese_trad"])