-
Notifications
You must be signed in to change notification settings - Fork 0
/
asl2ibus_table.py
executable file
·186 lines (145 loc) · 3.96 KB
/
asl2ibus_table.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env python
# coding: utf-8
# In[1]:
from xml.dom import minidom
with open('ogsl.asl', 'r') as infile:
asl = infile.read()
# In[2]:
reps = [
['š','sz'],
['Š','SZ'],
['ṣ','s,'],
['Ṣ','S,'],
['ṭ','t,'],
['Ṭ','T,'],
['ś',"s'"],
['Ś',"S'"],
['ʾ',"'"],
['₀','0'],
['₁','1'],
['₂','2'],
['₃','3'],
['₄','4'],
['₅','5'],
['₆','6'],
['₇','7'],
['₈','8'],
['₉','9'],
['ₓ','x'],
['ḫ','h,'],
['Ḫ','H,'],
['ŋ','j'],
['Ŋ','J'],
['û','u'],
['ā','aa'],
['ē','ee'],
['ī','ii'],
['ū','uu'],
['×','x'],
['°','0'],
['·','.'],
['⁺','+'],
['⁻','-'],
['𒑱',':'],
]
def to_ascii(s):
for fro, to in reps:
s=s.replace(fro, to)
return s
# In[3]:
def unistr2unicode(x):
x=x.replace('X', "x58") # replace X with unicode X
x=x.replace('None', "x58") # replace None with unicode X (|UD.MA₂.AB×(U.U.U).ŠIR|)
return ''.join(chr(int(y[1:], base=16)) for y in x.split('.'))
print(unistr2unicode("x12000.x12094.x1223E"))
print(unistr2unicode("x12000"))
# In[4]:
def maybeadd(reading, unic, sign='', prio = 1000):
reading=to_ascii(reading).strip('|')
sign=to_ascii(sign).strip('|')
if reading not in mapping:
mapping[reading]={(unic,sign,prio)}
else:
mapping[reading].add((unic,sign,prio))
# In[5]:
mapping = {}
funic = None
unic = None
in_form = False
listcodes = []
in_sign = False
for line in asl.splitlines():
if line =="":
continue
if line.startswith("@sign"):
in_sign = True
sign = line.split()[1]
if line.strip()=="@end sign" :
if in_sign:
if sign and unic and not in_form:
maybeadd(sign, unic, sign)
if sign and funic and in_form: # end sign also ends last form
maybeadd(sign, funic, sign)
if listcodes != [] and unic:
for listcode in listcodes:
maybeadd(listcode, unic, sign, 500)
listcodes=[]
in_form = False
unic = None
funic = None
sign = None
in_sign = False
if line.startswith("@list") and not in_form:
listcode = line.split()[1]
listcodes.append(listcode)
if line.startswith("@v"):
reading = line.split()[1]
if sign and unic and not in_form:
maybeadd(reading, unic, sign)
if sign and funic and in_form:
maybeadd(reading, funic, sign)
if line.startswith("@ucode"):
if in_form:
funic = unistr2unicode(line.split()[1])
else:
unic = unistr2unicode(line.split()[1])
#if line.startswith("@uname"):
# uname = unistr2unicode(line.split(maxsplit=1))[1]
if line.startswith("@form"):
in_form = True
foo, formcode, sign, *foo = line.split()
if line=="@end form":
in_form = False
if sign and funic:
maybeadd(sign, funic)
funic = None
if line.startswith("@form"):
pass
print(mapping['darengal'])
print(mapping['LAK797'])
print(mapping["'u4"])
print(mapping["libiszx"])
#print(mapping["MZL224"])
# In[6]:
valid_chars = ''.join(sorted(list(set(''.join(k for k in mapping.keys())))))
#''.join(k for k in mapping.keys())
valid_chars
print(list(mapping["'u4"]))
# In[7]:
inf = ""
from calendar import timegm
from time import gmtime
with open("ibus-table-cuneiform_pre.txt",'r') as infile:
inf = infile.read()
inf = inf.format(VALID_INPUTS= valid_chars, SERIAL=timegm(gmtime()))
with open("ibus-table-cuneiform.txt",'w') as outfile:
outfile.write(inf)
for reading, vals in mapping.items():
if len(vals)>1:
for unic,name,prio in sorted(list(vals)):
outfile.write(f"{reading}({name})\t{unic}\t{prio}\t### {name}\n")
else:
unic,name, prio = vals.pop()
outfile.write(f"{reading}\t{unic}\t{prio}\t### {name}\n")
outfile.write("END_TABLE")
print("Written")