-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex_fengari.html
More file actions
450 lines (365 loc) · 15.6 KB
/
index_fengari.html
File metadata and controls
450 lines (365 loc) · 15.6 KB
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<meta charset="UTF-8"/>
<html lang="">
<head>
<title>Online IPA Phonetic Transcription</title>
<meta charset="UTF-8">
<meta name="Keywords" content="Online IPA Latin Phonetics Transcription"/>
<meta name="description"
content="Rule-base IPA phonetic transcription engine, which uses Wiktionary Lua pronunciation modules.">
<script src="fengari-web.js" type="text/javascript"></script>
<script>
fengari.load('package.path = "lua_modules/?.lua"')()
fengari.load('mw = require "mw"')()
fengari.load('require "mw-language"')()
fengari.load('libraryUtil = require "libraryUtil"')()
fengari.load('require "mw-text"')()
fengari.load('memoize = require "memoize"')()
fengari.load('m_table = require "table"')()
fengari.load('m_table.listToSet = require "table.listToSet"')()
fengari.load('package.path = "lua_modules/?.lua"')()
fengari.load('local m_debug = require "debug"')()
fengari.load('export_la = require "la-pron_wasm"')()
fengari.load('export_de = require "de-pron_wasm"')()
<!-- fengari.load('export = require "ru-pron"')()-->
// fengari.load('export = require "pt-pronunc"')()
</script>
<link rel="preconnect" href="https://fonts.googleapis.com"/>
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico"/>
<link
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@300&family=Voces&display=swap"
rel="stylesheet"
/>
</head>
<body style="font-family: 'Voces', sans-serif">
<div style="font-size: 14px; font-family: monospace">Updated version of this transcription tool is available <a
href="https://hellpanderrr.github.io/wiktionary_pron">here</a>.
</div>
<hr>
<form name="myForm">
<div>
Language:
</div>
<select class="dropdown" id="lang" onchange="giveSelection(this.value)">
<option value="Latin" selected="selected">Latin</option>
<option value="German">German</option>
</select>
<div>
Additional options:
</div>
Style:
<select class="dropdown" id="lang_style">
<option data-option="Latin">Ecc</option>
<option data-option="Latin">Classical</option>
<option data-option="German">Default</option>
</select>
Form:
<select class="dropdown" id="lang_form">
<option data-option="Latin">Phonetic</option>
<option data-option="Latin">Phonemic</option>
<option data-option="German">Phonetic</option>
<option data-option="German">Phonemic</option>
</select>
</form>
<form id="frm1" onsubmit="return false">
<div class="form-group">
<textarea
id="text_to_transcribe"
name="text_to_transcribe"
required=""
autofocus=""
style="
height: 101px;
overflow: auto;
resize: vertical;
width: 500px;
"
>
] Omnium provinciarum populi Romani quibus finitimae fuerunt gentes quae non parerent imperio nostro fines auxi. Gallias et Hispanias provincias, item Germaniam, qua includit Oceanus a Gadibus ad ostium Albis fluminis pacavi. Alpes a regione ea quae proxima est Hadriano mari ad Tuscum pacificavi nulli genti bello per iniuriam inlato. Classis mea per Oceanum ab ostio Rheni ad solis orientis regionem usque ad fines Cimbrorum navigavit, quo neque terra neque mari quisquam Romanus ante id tempus adit. Cimbrique et Charydes et Semnones et eiusdem tractus alii Germanorum populi per legatos amicitiam meam et populi Romani petierunt. Meo iussu et auspicio ducti sunt duo exercitus eodem fere tempore in Aethiopiam et in Arabiam quae appellatur Eudaemon, magnaeque hostium gentis utriusque copiae caesae sunt in acie et complura oppida capta. In Aethiopiam usque ad oppidum Nabata perventum est, cui proxima est Meroe; in Arabiam usque in fines Sabaeorum processit exercitus ad oppidum Mariba.
[27] Aegyptum imperio populi Romani adieci. Armeniam maiorem interfecto rege eius Artaxe cum possem facere provinciam malui maiorum nostrorum exemplo regnum id Tigrani regis Artavasdis filio, nepoti autem Tigranis regis, per Ti. Neronem tradere, qui tum mihi privignus erat. Et eandem gentem postea desciscentem et rebellantem domitam per Gaium filium meum regi Ariobarzani regis Medorum Artabazi filio regendam tradidi, et post eius mortem filio eius Artavasdi; quo interfecto Tigranem qui erat ex regio genere Armeniorum oriundus in id regnum misi. Provincias omnis quae trans Hadrianum mare vergunt ad orientem Cyrenasque, iam ex parte magna regibus ea possidentibus, et antea Siciliam et Sardiniam occupatas bello servili reciperavi.
</textarea
>
<input type="button" id="clear_button"/>
<div class="btn-group btn-block" role="group">
<input
id="submit"
class="btn btn-primary btn-block"
name="submit"
type="submit"
value="Show transcription"
title="or Ctrl+Enter while in the text area"
/>
<input
id="submit_by_line"
class="btn btn-primary btn-block"
name="submit"
type="button"
value="Show transcription line-by-line"
title="or Ctrl+Enter while in the text area"
/>
<input
id="submit_by_col"
class="btn btn-primary btn-block"
name="submit"
type="button"
value="Show transcription column to column"
title="or Ctrl+Enter while in the text area"
/>
</div>
</div>
</form>
<table style="overflow: auto; resize: vertical; width: 500px">
<tbody id="result"></tbody>
</table>
<pre id="output"></pre>
<script type="text/javascript">
function sanitize(text) {
return text.replace(/[^\p{L}]/gu, '')
}
function prepare_transcribe() {
text = document.getElementById('text_to_transcribe').value
textlines = text.split('\n')
div = document.getElementById('result')
div.innerHTML = ''
return [div, textlines]
}
async function transcribe() {
[div, textlines] = prepare_transcribe()
const {lang, lang_style, lang_form} = get_lang_style_form()
console.log('START TRANSCRIBE')
async function asyncMapStrict(arr, fn) {
const result = [];
console.time("Elapsed time :");
for (let idx = 0; idx < arr.length; idx += 1) {
const cur = arr[idx];
await new Promise(resolve => setTimeout(resolve, 1));
result.push(await fn(cur, idx, arr));
}
console.timeEnd("Elapsed time :")
return result;
}
async function process_line(line) {
separated = line.split(' ')
div.insertAdjacentHTML('beforeend', '</br>')
// result = separated.map((i) => get_ipa(i))
function process_word(i) {
result = get_ipa(i, lang, lang_style, lang_form)
result = result.status === 'error'
? `<span style="color:red">${result.value} </span>`
: `<span>${result.value} </span>`
div.insertAdjacentHTML('beforeend', result)
}
await asyncMapStrict(separated, process_word)
}
asyncMapStrict(textlines, process_line)
}
function transcribe_by_line() {
[div, textlines] = prepare_transcribe()
const {lang, lang_style, lang_form} = get_lang_style_form()
function process_line(line) {
separated = line.split(' ')
result = separated.map((i) => get_ipa(i, lang, lang_style, lang_form))
result = result.map((i) =>
i.status === 'error'
? `<div style="color:red">${i.value} </div>`
: `<div>${i.value} </div>`
)
row = div.insertRow(-1)
old = separated.map(
(x) => `<div style="font-family: Garamond;">${x} </div>`
)
glued = result.map(
(k, i) =>
'<div style="float:left;margin-left:5px;margin-top:5px;">' +
old[i] +
k +
'</div>'
)
glued
.reverse()
.map((x) => row.insertAdjacentHTML('afterbegin', x))
}
textlines.map(process_line)
}
function transcribe_by_column() {
[div, textlines] = prepare_transcribe()
function process_line(line) {
separated = line.split(' ')
result = separated.map((i) => get_ipa(i, lang, lang_style, lang_form))
result = result.map((i) =>
i.status === 'error'
? `<td style="color:red">${i.value} </td>`
: `<td>${i.value} </td>`
)
function insert_row(div, cells) {
row = div.insertRow(-1)
for (cell of cells) {
new_cell = row.insertCell(-1)
new_cell.outerHTML = cell
}
}
old = separated.map(
(x) => `<td style="font-family: Garamond;">${x} </td>`
)
result.map((k, i) => insert_row(div, [old[i], k]))
}
textlines.map(process_line)
}
var form = document.getElementById('frm1')
form.addEventListener('submit', transcribe)
document
.getElementById('submit_by_line')
.addEventListener('click', transcribe_by_line)
document
.getElementById('submit_by_col')
.addEventListener('click', transcribe_by_column)
document
.getElementById('clear_button')
.addEventListener('click', clear_input)
function clear_input() {
i = document.getElementById('text_to_transcribe')
i.value = ''
}
function get_lang_style_form() {
const lang = document.querySelector('#lang').value;
const lang_style = document.querySelector('#lang_style').value;
const lang_form = document.querySelector('#lang_form').value;
return {lang, lang_style, lang_form}
}
function get_ipa(text, lang, lang_style, lang_form) {
args = lang + ';' + lang_style + ';' + lang_form
return get_ipa_cache(text, args)
}
function get_ipa_no_cache(text, args) {
console.log('doing actual IPA',text,args)
clean_text = sanitize(text)
const [lang, lang_style, lang_form] = args.split(';')
switch (lang) {
case 'Latin':
switch (lang_style) {
case 'Ecc':
switch (lang_form) {
case 'Phonetic':
command = `return (export_la.convert_words('${clean_text}',true,true,false))`
console.log(command)
break;
case 'Phonemic':
command = `return (export_la.convert_words('${clean_text}',false,true,false))`
break;
}
break;
case 'Classical':
switch (lang_form) {
case 'Phonetic':
command = `return (export_la.convert_words('${clean_text}',true,false,false))`
break;
case 'Phonemic':
command = `return (export_la.convert_words('${clean_text}',false,false,false))`
break;
}
break;
}
break;
case 'German':
switch (lang_form) {
case 'Phonetic':
command = `return (export_de.phonetic('${clean_text}'))`
console.log(command)
break;
case 'Phonemic':
command = `return (export_de.phonemic('${clean_text}'))`
console.log(command)
break;
}
break;
}
try {
ipa = fengari.load(command)()
} catch (err) {
ipa = ''
}
split = text.split(/([\p{L}]+)/gu)
index_in_split = split
.map((x, n) => x === clean_text && n)
.filter(Boolean)[0]
split[index_in_split] = ipa
if (!ipa) {
return new Object({value: text, status: 'error'})
}
ipa = split.join('')
console.log('Stopped doing actual IPA',text,args)
return new Object({value: ipa, status: 'success'})
}
const memoizedFunction = (fn) => {
let cache = {};
return (value) => {
if (value in cache) {
return cache[value];
} else {
let result = fn(value);
cache[value] = result;
return result;
}
}
}
function memoizeLocalStorage(
fn,
options = {ttl: 100, backgroundRefresh: false},
) {
if (!fn.name)
throw new Error('memoizeLocalStorage only accepts non-anonymous functions');
// Fetch localstorage or init new object
const cache = JSON.parse(localStorage.getItem(fn.name) || '{}');
//executes and caches result
function executeAndCacheFn(fn, args, argsKey) {
const result = fn(...args);
// reset the cache value
cache[fn.name] = {
...cache[fn.name],
[argsKey]: {expiration: Date.now() + options.ttl, result},
};
localStorage.setItem(fn.name, JSON.stringify(cache));
}
return function () {
// Note: JSON.stringify is non-deterministic,
// consider something like json-stable-stringify to avoid extra cache misses
const argsKey = JSON.stringify(arguments);
if (
!cache[fn.name] ||
!cache[fn.name][argsKey] ||
cache[fn.name][argsKey].expiration >= Date.now()
) {
executeAndCacheFn(fn, arguments, argsKey);
} else if (options.backgroundRefresh) {
executeAndCacheFn(fn, arguments, argsKey);
}
console.log('Using cached', argsKey)
return cache[fn.name][argsKey].result;
};
}
const get_ipa_cache = memoizeLocalStorage(get_ipa_no_cache);
</script>
<script>
var sel1 = document.querySelector('#lang');
var sel2 = document.querySelector('#lang_style');
var sel3 = document.querySelector('#lang_form');
var options2 = sel2.querySelectorAll('option');
var options3 = sel3.querySelectorAll('option');
function giveSelection(selValue) {
sel2.innerHTML = '';
for (var i = 0; i < options2.length; i++) {
if (options2[i].dataset.option === selValue) {
sel2.appendChild(options2[i]);
}
}
sel3.innerHTML = '';
for (var i = 0; i < options3.length; i++) {
if (options3[i].dataset.option === selValue) {
sel3.appendChild(options3[i]);
}
}
}
giveSelection("Latin")
</script>
</body>
</html>