-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zawgyi.html
290 lines (227 loc) · 18.1 KB
/
Zawgyi.html
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!doctype html>
<html >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<title>Test Zawgyi encoding of page</title>
<style>
@font-face {
font-family: ZawgyiOne;
src: url(res/fonts/ZawgyiOne.ttf);
}
@font-face {
font-family: Padauk;
src: url(res/fonts/Padauk.ttf);
}
.zaw5 {
font-family: ZawgyiOne;
font-size:26px;
}
.bur5 {
font-family: Padauk;
font-size:28px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-bg-1">
<form name=f1>
Test UI :
<div>
Is keyboard Zawgyi : <input type=checkbox id=isZawgyi onchange="isZawgyiChnged(this)">
<div title="For ref - unicode text with Zawgyi font (works only if this device has this font)
Test String 2 with Zawgyi-One font" style = "font-family:Zawgyi-One;" >
Label 1 ၿဖိဳး ၾကာ ၾကည္း ေျပာျပခ် ၿမိဳ ျဖစ္သ
</div>
<div style = "font-family:Padauk;" title="Same string 2 with default font This string is in Zawgyi encoding. Meaning with Zawgyi font will look in one way (and mean one thing in Burmese) but with Unicode "Padauk" Burmese font will look different. This file is saved with Unicode-16 encoding (not default UTF-8)" >
Label 2 ၿဖိဳး ၾကာ ၾကည္း ေျပာျပခ် ၿမိဳ ျဖစ္သ
</div>
<div style = "font-family:Padauk;" id = 'dev1a'>Label 3 Unicode က္က က မြန်မာနိုင်ငံ</div>
<div id = 'dev1b' style = "font-family:ZawgyiOne;" >Label 4 Zawgyi ျမန္မာနိုင္ငံ</div>
<div>
<span title='Label to prompt user what to type'>To detect if Zawgyi encoding, type မြန်မာနိုင်ငံ or <span style = "font-family:Zawgyi-One;" >ျမန္မာနိုင္ငံ</span> <input type=text id=t1 len=20>
<input type=button value="Go" onclick="goProcess()" id=btn1>
<div id = "dev2out" title="Output appended with <br>" style="font-family:Padauk;">Output :<br><br> </div>
<div id = "dev2err" title="Exceptions if any appended with <br>"
style="font-family:Padauk;">(Errs 2) <br><br>
</div>
</div>
</div>
</div>
On pressing Go we convert a string from Zawgyi to Unicode and back. <br>
(1) If device does not have the Burmese Unicode font installed some of the unicode text might appear incorrectly.<br>
(2) If you do not have the Zawgyi-One font intalled then some of the Zawgyi text will be rendered with the default font and not look accurate.<br>
In both cases can ignore that as our app will only display the sected encoding. So some devices will have either Zawgyi or Unicode appearing correctly. And some will have both both appearing correctly.
<br>
<div>
</div>
</form>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/myanmar-tools/1.1.3/zawgyi_detector.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/tinycolor/1.4.1/tinycolor.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/myanmar-tools/1.1.0/zawgyi_converter.min.js"></script>
<script>
const zawgyi_converter = new google_myanmar_tools.ZawgyiConverter();
var isZawgyiEncoding = false;//set on change of checkbox
const output1 = document.getElementById('dev2out');
const excptn = document.getElementById('dev2err');;//initialize to exception
function isZawgyiChnged(itm){
isZawgyiEncoding = itm.checked;
output1.innerHTML = "User selected is Zawgyi Encoding : " + isZawgyiEncoding + ", time " + new Date() + "<br>";
}
function goProcess(){
//this is a test function to test the capabilities of the library. In app code we will only convert to Zawgyi if phone is Zawgyi.
var userTypedText = document.f1.t1.value;//from UI
const UnicodeStr = "က္က က မြန်မာနိုင်ငံ ကဥွ ကညွ က္ဋ က္";
const ZawgyiString = "ျမန္မာနိုင္ငံ";
///alert('TODO isZawgyiEncoding, userTypedText, UnicodeStr, ZawgyiString ');
var output = "Start Process: <br>User selected, is Zawgyi Encoding : " +
isZawgyiEncoding + ", time " + new Date() + "<br>";
output1.innerHTML = output;
var result = "na";
try{
result = predict(userTypedText);
var prediction = result.probability === -1 ? "No Signal" : (result.probability < 0.01 ? "Unicode" : (result.probability > 0.99 ? "See Zawgyi" : "Not Enough Info"));
output = output + "Prediction for user string " + prediction + " (Score: " + formatFixed(result.score) + "; Zawgyi Probability: " + result.probability.toFixed(4) + ".)<br>";
var o2 = "";
if(isZawgyiEncoding){
o2 = "User text in Unicode : " + zawgyi_converter.zawgyiToUnicode(userTypedText) + ".<br>";
}else{
o2 = "User text already in Unicode. " + userTypedText + " <br>";
}
output = output + o2;
output = output + "Covert test : U to Z " + zawgyi_converter.unicodeToZawgyi(UnicodeStr) +
"<br> Z to U :" + zawgyi_converter.zawgyiToUnicode(ZawgyiString) +
", U to Z to U :" +
zawgyi_converter.zawgyiToUnicode(zawgyi_converter.unicodeToZawgyi(UnicodeStr)) + "; expect :" + UnicodeStr + ". Zawgyi str :" + ZawgyiString;
const u2 = "ဖြိုး ကြာ ကြည်း ပြောပြချ မြို ဖြစ်သ";
const z2 = "ၿဖိဳး ၾကာ ၾကည္း ေျပာျပခ် ၿမိဳ ျဖစ္သ";
const u2z = zawgyi_converter.unicodeToZawgyi(u2);
const z2u = zawgyi_converter.zawgyiToUnicode(u2z);
output = output + "<br> u2 : " + u2 + "; -> z :" + u2z + "; back to U :" + z2u + ", same U :" + (z2u === u2);
const u3 = zawgyi_converter.zawgyiToUnicode(z2);
const z3 = zawgyi_converter.unicodeToZawgyi(u3);
//const z3u = zawgyi_converter.zawgyiToUnicode(u2z);
output = output + "<br> z2 : " + z2 + "; -> u :" + u3 + "; back to Z :" + z3 + ", same Z :" + (z3 === z2);
//put to output div
}catch(e){
//log to exception div
excptn.innerHTML="Exception : " + e + "<br> Current output " + output;//and trace where we are
}
output1.innerHTML = output;
}
function formatFixed(number) {
return (number > 0 ? "+" : "") + number.toFixed(4);
}
function getIndexForCodePoint(cp) {
// Standard Myanmar code point range before digits
var STD_CP0 = 0x1000;
var STD_CP1 = 0x103F;
// Standard Myanmar code point range after digits
var AFT_CP0 = 0x104A;
var AFT_CP1 = 0x109F;
// Extended Myanmar code point range A
var EXA_CP0 = 0xAA60;
var EXA_CP1 = 0xAA7F;
// Extended Myanmar code point range B
var EXB_CP0 = 0xA9E0;
var EXB_CP1 = 0xA9FF;
// Unicode space characters
var SPC_CP0 = 0x2000;
var SPC_CP1 = 0x200B;
// Indices into Markov nodes
var STD_OFFSET = 1;
var AFT_OFFSET = STD_OFFSET + STD_CP1 - STD_CP0 + 1;
var EXA_OFFSET = AFT_OFFSET + AFT_CP1 - AFT_CP0 + 1;
var EXB_OFFSET = EXA_OFFSET + EXA_CP1 - EXA_CP0 + 1;
var SPC_OFFSET = EXB_OFFSET + EXB_CP1 - EXB_CP0 + 1;
var NUM_STATES = SPC_OFFSET + SPC_CP1 - SPC_CP0 + 1;
if (STD_CP0 <= cp && cp <= STD_CP1) {
return cp - STD_CP0 + STD_OFFSET;
}
if (AFT_CP0 <= cp && cp <= AFT_CP1) {
return cp - AFT_CP0 + AFT_OFFSET;
}
if (EXA_CP0 <= cp && cp <= EXA_CP1) {
return cp - EXA_CP0 + EXA_OFFSET;
}
if (EXB_CP0 <= cp && cp <= EXB_CP1) {
return cp - EXB_CP0 + EXB_OFFSET;
}
if (SPC_CP0 <= cp && cp <= SPC_CP1) {
return cp - SPC_CP0 + SPC_OFFSET;
}
return 0;
}
function predict(input) {
var totalDelta = 0.0;
var prevCp = 0;
var prevState = 0;
var record = [];
var seenTransition = false;
for (let offset = 0; offset <= input.length; offset++) {
var cp;
var currState;
if (offset === input.length) {
cp = 0;
currState = 0;
} else {
// Note: All interesting characters are in the BMP.
cp = input.charCodeAt(offset);
currState = getIndexForCodePoint(cp);
}
var isNullState = (currState === 0);
// Ignore 0-to-0 transitions
if (prevState != 0 || currState != 0) {
var delta = window.detector.model.classifier.getLogProbabilityDifference(prevState, currState);
record.push({ prevCp, cp, delta, isNullState, hasSignal: true });
totalDelta += delta;
seenTransition = true;
} else {
record.push({ prevCp, cp, isNullState, hasSignal: false });
}
prevCp = cp;
prevState = currState;
}
// Special case: if there is no signal (both log probabilities are zero), return -1.
// This happens when the input string contains no Myanmar-range code points.
var probability, score;
if (!seenTransition) {
score = 0;
probability = -Infinity;
} else {
// result = Pz/(Pu+Pz)
// = exp(logPz)/(exp(logPu)+exp(logPz))
// = 1/(1+exp(logPu-logPz))
score = totalDelta;
probability = 1.0 / (1.0 + Math.exp(totalDelta));
}
return { score, probability, record };
}
window.detector = new google_myanmar_tools.ZawgyiDetector();
</script>
<script>
function codePointInfo(str){
}
</script>
</div></div>
<section class="text-center">
<div class="container">
<h1 class="heading">Zawgyi and Unicode pairs</h1>
</div>
</section>
<div class="container">
<div class = "row"><div class="col-bg-1"> <span class="zaw5">
လမ္းၫႊန္ေျမပံုပင္ျဖစ္ေၾကာင္း၊ Zawgyi</span><br/><br/></div></div>
<div class = "row "><div class="col-bg-1"><span class="bur5">
လမ်းညွှန်မြေပုံပင်ဖြစ်ကြောင်း၊ Unicode</span>
</div>
</div>
</div>
</div></div>
<br/><br/>
</html>