-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.html
More file actions
351 lines (317 loc) · 11.1 KB
/
main.html
File metadata and controls
351 lines (317 loc) · 11.1 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
<meta charset="UTF-8"/>
<html lang="">
<head>
<title>Online IPA Phonetic Transcription</title>
<meta charset="UTF-8">
<meta content="Online IPA German Phonetics Transcription немецкая фонетическая транскрипция МФА" name="Keywords"/>
<meta content="Multi-lingual IPA phonetic transcription engine. Only German lexicon is currently available. "
name="description">
<script src="./data.js"></script>
<link href="https://fonts.googleapis.com" rel="preconnect"/>
<link crossorigin href="https://fonts.gstatic.com" rel="preconnect"/>
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/>
<link
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@300&family=Voces&display=swap"
rel="stylesheet"
/>
<style>
/* loading dots */
.loading:after {
content: ' .';
animation: dots 0.5s steps(5, end) infinite;
}
@keyframes dots {
0%,
20% {
color: rgb(255, 255, 255);
text-shadow: 0.25em 0 0 rgb(255, 255, 255),
0.5em 0 0 rgb(255, 255, 255);
}
40% {
color: #090909;
text-shadow: 0.25em 0 0 rgb(255, 255, 255),
0.5em 0 0 rgb(255, 255, 255);
}
60% {
text-shadow: 0.25em 0 0 #000000,
0.5em 0 0 rgb(255, 255, 255);
}
80%,
100% {
text-shadow: 0.25em 0 0 #000000,
0.5em 0 0 #090909;
}
}
</style>
</head>
<body style="font-family: 'Voces', sans-serif">
Updated version of this app is located <a href="https://hellpanderrr.github.io/wiktionary_pron/index.html">here</a>.
<br>
<hr>
<input id="inputfile" name="inputfile" type="file"/>
<div id="lexicon_status" style="width: 300px">
Lexicon status:
<div class="loading" id="progress_bar" style="float: right">
loading
</div>
<div id="lexicon_count" style="float: right"></div>
</div>
<br/>
<form id="frm1" onsubmit="return false">
<div class="form-group">
<textarea
autocomplete="off"
autofocus=""
id="text_to_transcribe"
name="text_to_transcribe"
required=""
style="
height: 101px;
overflow: auto;
resize: vertical;
width: 500px;
"
>
Hat Herr Müller eine Frau? Ja, er hat eine Frau. Wie</textarea
>
<input id="clear_button" type="button"/>
<div class="btn-group btn-block" role="group">
<input
autocomplete="off"
class="btn btn-primary btn-block"
disabled="disabled"
id="submit"
name="submit"
title="or Ctrl+Enter while in the text area"
type="submit"
value="Show transcription"
/>
<input
autocomplete="off"
class="btn btn-primary btn-block"
disabled="disabled"
id="submit_by_line"
name="submit"
title="or Ctrl+Enter while in the text area"
type="button"
value="Show transcription line-by-line"
/>
<input
autocomplete="off"
class="btn btn-primary btn-block"
disabled="disabled"
id="submit_by_col"
name="submit"
title="or Ctrl+Enter while in the text area"
type="button"
value="Show transcription column to column"
/>
</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 transcribe() {
text = document.getElementById('text_to_transcribe').value
textlines = text.split('\n')
div = document.getElementById('result')
div.innerHTML = ''
function process_line(line) {
separated = line.split(' ')
result = separated.map((i) => get_ipa(i))
result = result.map((i) =>
i.status === 'error'
? `<span style="color:red">${i.value} </span>`
: `<span>${i.value} </span>`
)
div.insertAdjacentHTML('afterbegin', '</br>')
result
.reverse()
.map((x) => div.insertAdjacentHTML('afterbegin', x))
}
textlines.reverse().map(process_line)
}
function transcribe_by_line() {
text = document.getElementById('text_to_transcribe').value
textlines = text.split('\n')
div = document.getElementById('result')
div.innerHTML = ''
function process_line(line) {
separated = line.split(' ')
result = separated.map((i) => get_ipa(i))
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() {
text = document.getElementById('text_to_transcribe').value
textlines = text.split('\n')
div = document.getElementById('result')
div.innerHTML = ''
function process_line(line) {
separated = line.split(' ')
result = separated.map((i) => get_ipa(i))
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_ipa(text) {
clean_text = sanitize(text)
ipa = dict.get(clean_text)
if (ipa) {
ipa = decodeURIComponent(ipa)
}
if (!ipa) {
ipa = dict.get(clean_text.toLowerCase())
}
if (!ipa) {
ipa = dict.get(clean_text.toLowerCase().replace('ß', 'ss'))
}
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
console.log(ipa)
if (!ipa) {
return new Object({value: text, status: 'error'})
}
ipa = split.join('')
return new Object({value: ipa, status: 'success'})
}
const splitAndAppend = (str, delim, count) => {
const arr = str.split(delim)
return [...arr.splice(0, count), arr.join(delim)]
}
let text = ''
function process_lexicon(text) {
progress_bar = document.getElementById('progress_bar')
progress_bar.style.display = 'block'
Array.from(document.getElementsByClassName('btn')).map((x) =>
x.setAttribute('disabled', true)
)
document.getElementById('lexicon_count').style.display = 'none'
split = text.split(/\r?\n/)
lines = []
var chunk = 10000
var index = 0
function doChunk() {
var cnt = chunk
console.log(index)
while (cnt-- && index < split.length) {
;[text, ipa] = splitAndAppend(split[index], ' ', 1)
if (!ipa.includes('|')) {
lines.push([text, ipa.split(' ').join('')])
}
++index
}
if (index < split.length) {
// set Timeout for async iteration
setTimeout(doChunk, 1)
} else {
dict = new Map(lines.reverse())
console.log('dict created')
progress_bar.style.display = 'none'
document.getElementById('lexicon_count').style.display =
'block'
document.getElementById(
'lexicon_count'
).innerText = `Loaded ${dict.size} entries.`
Array.from(document.getElementsByClassName('btn')).map(
(x) => x.removeAttribute('disabled')
)
}
}
return doChunk()
}
console.log('started loading')
fetch('./data/german_ipa.txt')
.then(function (response) {
return response
})
.then(function (data) {
return data.text()
})
.then(function (Normal) {
text = Normal
console.log('loaded text')
dict = process_lexicon(text)
console.log('created dict')
})
.catch(function (err) {
console.log('Fetch problem show: ' + err.message)
})
window.addEventListener('load', function () {
if (lines_from_js) {
lines = lines_from_js.filter((x) => !x[1].includes('|'))
dict = new Map(lines)
console.log('loaded dict')
}
})
document
.getElementById('inputfile')
.addEventListener('change', function () {
var fr = new FileReader()
fr.onload = function () {
text = fr.result
dict = process_lexicon(text)
}
fr.readAsText(this.files[0])
})
</script>
</body>
</html>