@sc-voice/tools 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +21 -6
- package/package.json +2 -1
- package/src/defines.mjs +6 -1
- package/src/graph/sankey.mjs +56 -0
- package/src/math/fraction.mjs +8 -0
- package/src/text/ebt-doc.mjs +6 -2
- package/src/text/legacy-doc.mjs +29 -2
- package/src/text/word-space.mjs +83 -54
- package/src/{text → translate}/aligner.mjs +127 -38
- package/src/translate/deepl-adapter.mjs +353 -0
- package/src/translate/dpd-transformer.mjs +17 -0
- package/src/translate/mock-deepl.mjs +351 -0
- package/src/translate/quote-parser.mjs +681 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { DBG } from '../defines.mjs';
|
|
2
|
+
|
|
3
|
+
import { QuoteParser } from './quote-parser.mjs';
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
LQ1,
|
|
7
|
+
LQ2,
|
|
8
|
+
LQ3,
|
|
9
|
+
LQ4,
|
|
10
|
+
RQ1,
|
|
11
|
+
RQ2,
|
|
12
|
+
RQ3,
|
|
13
|
+
RQ4,
|
|
14
|
+
ELLIPSIS,
|
|
15
|
+
ELL,
|
|
16
|
+
APOS,
|
|
17
|
+
LDQUOT,
|
|
18
|
+
RDQUOT,
|
|
19
|
+
LSQUOT,
|
|
20
|
+
RSQUOT,
|
|
21
|
+
} = QuoteParser;
|
|
22
|
+
|
|
23
|
+
const lQuote = LQ1;
|
|
24
|
+
const rQuote = RQ1;
|
|
25
|
+
|
|
26
|
+
export class MockGlossary {
|
|
27
|
+
constructor(args) {
|
|
28
|
+
const msg = 'MockGlossary.ctor()';
|
|
29
|
+
const dbg = DBG.VERBOSE;
|
|
30
|
+
let [name, sourceLang, targetLang, glossaryEntries] = args;
|
|
31
|
+
targetLang = targetLang.replace(/-[a-z]+/i, '');
|
|
32
|
+
Object.assign(this, {
|
|
33
|
+
name,
|
|
34
|
+
ready: true,
|
|
35
|
+
sourceLang,
|
|
36
|
+
targetLang,
|
|
37
|
+
glossaryEntries,
|
|
38
|
+
});
|
|
39
|
+
dbg && console.log(msg, this);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const qp_en_deepl = new QuoteParser({ lang: 'en-deepl' });
|
|
44
|
+
const qp_fr_deepl = new QuoteParser({ lang: 'fr-deepl' });
|
|
45
|
+
|
|
46
|
+
function compare(a, b) {
|
|
47
|
+
const msg = 'MockDeepL.compare()';
|
|
48
|
+
let len = Math.max(a.length, b.length);
|
|
49
|
+
let ok = true;
|
|
50
|
+
for (let i = 0; i < len; i++) {
|
|
51
|
+
let ai = a.charAt(i);
|
|
52
|
+
let bi = b.charAt(i);
|
|
53
|
+
if (ai !== bi) {
|
|
54
|
+
ok = false;
|
|
55
|
+
console.log(msg, { i, ai, bi });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
console.log(msg, ok);
|
|
59
|
+
return ok;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class MockTranslator {
|
|
63
|
+
constructor(authKey) {
|
|
64
|
+
const msg = 'MockTranslator.ctor()';
|
|
65
|
+
const dbg = DBG.VERBOSE;
|
|
66
|
+
dbg && console.log(msg, `authKey: ${authKey.substring(0, 4)}...`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async listGlossaries() {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async createGlossary(...args) {
|
|
74
|
+
return new MockGlossary(args);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async translateText(texts, sourceLang, targetLang, translateOpts) {
|
|
78
|
+
const msg = 'MockTranslator.translateText()';
|
|
79
|
+
const dbg = DBG.DEEPL_MOCK_XLT;
|
|
80
|
+
const dbgv = dbg && DBG.VERBOSE;
|
|
81
|
+
|
|
82
|
+
return texts.map((text) => {
|
|
83
|
+
dbg && console.log(msg, `"${text}"`);
|
|
84
|
+
|
|
85
|
+
if (DBG.TRANSLATE_TEXT) {
|
|
86
|
+
// use this to debug
|
|
87
|
+
let expected = `when warned by the DEVA1s' messengers: `;
|
|
88
|
+
console.log(msg, { text, expected });
|
|
89
|
+
compare(text, expected);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
text =
|
|
93
|
+
text &&
|
|
94
|
+
text
|
|
95
|
+
.replace(
|
|
96
|
+
`${LQ1}Bhikkhus, I do not see a single thing that is so ` +
|
|
97
|
+
'very blameworthy as wrong view.',
|
|
98
|
+
`${LQ1}Bhikkhus, eu não vejo uma única coisa que seja ` +
|
|
99
|
+
'tão culpável como uma visão incorreta. ',
|
|
100
|
+
)
|
|
101
|
+
.replace(/\baus Anteilnahme an. /g, 'por compaixão.')
|
|
102
|
+
.replace(/\bBei welchen drei\? /g, 'Quais são os três? ')
|
|
103
|
+
.replace(/\bDas ist ein Moench, /g, 'Este é um bhikkhu ')
|
|
104
|
+
.replace(/\bman einen Moench, /g, 'chama um bhikkhu ')
|
|
105
|
+
.replace(/, Moenche, /, 'bhikkhus,')
|
|
106
|
+
.replace(/\bthe dart of craving/g, 'o dardo do anseio')
|
|
107
|
+
.replace(/\bUpaka/g, 'UPAKA')
|
|
108
|
+
.replace(
|
|
109
|
+
`I say, ‘You say, “I said UK!”?’.`,
|
|
110
|
+
`Eu digo: "Está a dizer: "Eu disse Reino Unido!"?`,
|
|
111
|
+
)
|
|
112
|
+
.replace(
|
|
113
|
+
`${LQ1}${LQ2}I say, ${LQ3}You say, ${LQ4}I said PT!${RQ4}?${RQ3}.${RQ2}${RQ1}`,
|
|
114
|
+
`${LQ1}${LQ2}Eu digo, ${LQ3}Você diz, ${LQ4}Eu disse PT!${RQ4}?${RQ3}.${RQ2}${RQ1}`,
|
|
115
|
+
)
|
|
116
|
+
.replace(`Der Pfeil des Verlangens`, 'O dardo do anseio')
|
|
117
|
+
.replace(
|
|
118
|
+
'„Moench, du sammelst Almosen, bevor du isst;',
|
|
119
|
+
'"Bhikkhu, você esmola comida antes de comer;',
|
|
120
|
+
)
|
|
121
|
+
.replace(
|
|
122
|
+
'“Bhikkhu, you seek alms before you eat;',
|
|
123
|
+
'"Bhikkhu, você procura esmola comida antes de comer;',
|
|
124
|
+
//).replace(
|
|
125
|
+
//`${LQ1}${LQ2}I say, ${LQ3}You say, ${LQ4}I said FR!${RQ4}?${RQ3}.${RQ2}${RQ1}`,
|
|
126
|
+
//`${LQ1}${LQ2}Je dis, ${LQ3}Vous dites, ${LQ4}Je dis FR!${RQ4}?${RQ3}.${RQ2}${RQ1}`
|
|
127
|
+
)
|
|
128
|
+
.replace(
|
|
129
|
+
`${LQ2}I say, ${LQ3}You say, ${LQ4}I said FR!${RQ4}?${RQ3}.${RQ2}${RQ1}`,
|
|
130
|
+
`${LQ2}Je dis, ${LQ3}Vous dites, ${LQ4}Je dis FR!${RQ4}?${RQ3}.${RQ2}${RQ1}.`,
|
|
131
|
+
)
|
|
132
|
+
.replace(
|
|
133
|
+
`${LQ2}I say, ${LQ3}You say, ${LQ4}I said PT!${RQ4}?${RQ3}.${RQ2}${RQ1}`,
|
|
134
|
+
`${LQ2}Eu digo, ${LQ3}Você diz, ${LQ4}Eu disse PT!${RQ4}?${RQ3}.${RQ2}${RQ1}`,
|
|
135
|
+
)
|
|
136
|
+
.replace(
|
|
137
|
+
`${LQ2}I say, ${LQ3}You say, ${LQ4}I said PT!${RQ4}?${RQ3}.${RQ2}${RQ1}`,
|
|
138
|
+
`${LQ2}Eu digo, ${LQ3}Você diz, ${LQ4}Eu disse PT!${RQ4}?${RQ3}.${RQ2}${RQ1}`,
|
|
139
|
+
)
|
|
140
|
+
.replace(
|
|
141
|
+
qp_fr_deepl.testcaseFeelingsEN('French'),
|
|
142
|
+
'comment échapper à ce sentiment français ? ',
|
|
143
|
+
)
|
|
144
|
+
.replace(
|
|
145
|
+
qp_fr_deepl.testcaseRebirthEN('FR'),
|
|
146
|
+
`${LQ2} Je comprends : ${LQ3}La renaissance est terminée ` +
|
|
147
|
+
`en FR${RQ3}${RQ2}?${RQ1}.`,
|
|
148
|
+
)
|
|
149
|
+
.replace(
|
|
150
|
+
qp_fr_deepl.testcasePleasuresEN('French'),
|
|
151
|
+
"comprendre la gratification, l'inconvénient et " +
|
|
152
|
+
'la fuite des plaisirs français',
|
|
153
|
+
)
|
|
154
|
+
.replace(
|
|
155
|
+
"craving aggregates' origin",
|
|
156
|
+
"l'origine des agrégats de l'envie",
|
|
157
|
+
)
|
|
158
|
+
.replace(
|
|
159
|
+
"The French child's toy",
|
|
160
|
+
"Le jouet de l'enfant français",
|
|
161
|
+
)
|
|
162
|
+
.replace('Springtime', 'Primavera')
|
|
163
|
+
.replace(
|
|
164
|
+
'“Bhikkhu, that is incorrect view;',
|
|
165
|
+
'"Bhikkhu, essa visão é incorrecta;',
|
|
166
|
+
)
|
|
167
|
+
.replace(
|
|
168
|
+
'are these things skillful or unskillful?',
|
|
169
|
+
'estas coisas são hábeis ou inábeis? ',
|
|
170
|
+
)
|
|
171
|
+
.replace(
|
|
172
|
+
'succeed in the system of skillful teaching.',
|
|
173
|
+
'tenha sucesso no sistema de ensino hábil. ',
|
|
174
|
+
)
|
|
175
|
+
.replace(
|
|
176
|
+
'so the skillful person ',
|
|
177
|
+
'por isso, a pessoa hábil ',
|
|
178
|
+
)
|
|
179
|
+
.replace(
|
|
180
|
+
'They are entirely a heap of the skillful. "',
|
|
181
|
+
'São inteiramente um amontoado de hábeis. " ',
|
|
182
|
+
)
|
|
183
|
+
.replace(
|
|
184
|
+
'He gives up the unskillful and develops the skillful.',
|
|
185
|
+
'Abandona o inábil e desenvolve o hábil. ',
|
|
186
|
+
)
|
|
187
|
+
.replace(
|
|
188
|
+
'Whatever qualities are skillful, part of the skillful, all are rooted.',
|
|
189
|
+
'Quaisquer que sejam as qualidades hábeis, parte do hábil, todas estão enraizadas. ',
|
|
190
|
+
)
|
|
191
|
+
.replace(
|
|
192
|
+
'One who desires merit, grounded in the skillful, ',
|
|
193
|
+
'Aquele que deseja o mérito, baseado no hábil, ',
|
|
194
|
+
)
|
|
195
|
+
.replace(
|
|
196
|
+
'There Sāriputta addressed the bhikkhus',
|
|
197
|
+
'Aí Sāriputta dirigiu-se aos monges ',
|
|
198
|
+
)
|
|
199
|
+
.replace(
|
|
200
|
+
'There the Blessed One is now staying',
|
|
201
|
+
'Lá o Abençoado está agora a ficar ',
|
|
202
|
+
)
|
|
203
|
+
.replace('There exists, brahmin.', 'Existe, brâmane. ')
|
|
204
|
+
.replace('2. endeavor', '2. esforzarse ')
|
|
205
|
+
.replace(
|
|
206
|
+
'2. Endeavor',
|
|
207
|
+
'2. Endeavor ', // WHY!?
|
|
208
|
+
)
|
|
209
|
+
.replace('2. padhānasutta', '2. padhānasutta ')
|
|
210
|
+
.replace('2. Padhānasutta', '2. Padhānasutta ')
|
|
211
|
+
.replace(
|
|
212
|
+
QuoteParser.testcaseThinking_EN('SPAN'),
|
|
213
|
+
[
|
|
214
|
+
`Pensando, `,
|
|
215
|
+
`${LQ1}He hecho cosas SPAN por medio `,
|
|
216
|
+
`del cuerpo, la palabra y la mente${RQ1}, `,
|
|
217
|
+
`se mortifican.`,
|
|
218
|
+
].join(''),
|
|
219
|
+
)
|
|
220
|
+
.replace('springtime', 'Primavera')
|
|
221
|
+
.replace(
|
|
222
|
+
QuoteParser.testcaseEllipsisEN('PT', {
|
|
223
|
+
prefix: 'They understand: ',
|
|
224
|
+
lQuote,
|
|
225
|
+
rQuote,
|
|
226
|
+
ellipsis: ELL,
|
|
227
|
+
}),
|
|
228
|
+
`Eles compreendem: ${LQ1}Isto é PT${RQ1}<ell/>${LQ1}Isto é sofrimento${RQ1}<ell/>${LQ1}Isto é a origem${RQ1}.`,
|
|
229
|
+
)
|
|
230
|
+
.replace(
|
|
231
|
+
QuoteParser.testcaseEllipsisEN('ES', {
|
|
232
|
+
lQuote,
|
|
233
|
+
rQuote,
|
|
234
|
+
ellipsis: ELL,
|
|
235
|
+
}),
|
|
236
|
+
[
|
|
237
|
+
`Comprenden: `,
|
|
238
|
+
`${LQ1}Esto es ES${RQ1}`,
|
|
239
|
+
ELL,
|
|
240
|
+
`${LQ1}Esto es sufrimiento${RQ1}`,
|
|
241
|
+
ELL,
|
|
242
|
+
`${LQ1}Este es el origen${RQ1}`,
|
|
243
|
+
`.`,
|
|
244
|
+
].join(''),
|
|
245
|
+
)
|
|
246
|
+
.replace(
|
|
247
|
+
'And what are dark and bright deeds?',
|
|
248
|
+
'E o que são actos sombrios e luminosos?',
|
|
249
|
+
)
|
|
250
|
+
.replace(
|
|
251
|
+
'On the side of dark and bright',
|
|
252
|
+
'Do lado do sombrio e do luminoso',
|
|
253
|
+
)
|
|
254
|
+
.replace(
|
|
255
|
+
'That is why I sleep at ease. ',
|
|
256
|
+
`É por isso que durmo tranquilo. `,
|
|
257
|
+
)
|
|
258
|
+
.replace(
|
|
259
|
+
QuoteParser.testcaseQuotesEN({ lang: 'mind/PT', lQuote }),
|
|
260
|
+
`${LQ1}Ouça e aplique bem a sua mente/PT, eu falarei.`,
|
|
261
|
+
)
|
|
262
|
+
.replace(
|
|
263
|
+
QuoteParser.testcaseQuotesEN({ lang: 'mind/PT', rQuote }),
|
|
264
|
+
`Ouça e aplique bem a sua mente/PT, eu falarei.${RQ1}`,
|
|
265
|
+
)
|
|
266
|
+
.replace(
|
|
267
|
+
QuoteParser.testcaseQuotesEN({
|
|
268
|
+
lang: 'mind/PT',
|
|
269
|
+
lQuote,
|
|
270
|
+
rQuote,
|
|
271
|
+
}),
|
|
272
|
+
`${LQ1}Ouça e aplique bem a sua mente/PT, eu falarei.${RQ1}`,
|
|
273
|
+
)
|
|
274
|
+
.replace(
|
|
275
|
+
QuoteParser.testcaseDonationEN({
|
|
276
|
+
lang: 'religious-PT',
|
|
277
|
+
rQuote: QuoteParser.RQ1,
|
|
278
|
+
people: 'people',
|
|
279
|
+
}),
|
|
280
|
+
`Estas são duas pessoas no mundo que são dignas de um donativo religioso-PT, e é aí que deve dar um presente.${RQ1} `,
|
|
281
|
+
)
|
|
282
|
+
.replace(
|
|
283
|
+
QuoteParser.testcaseMisterEN({
|
|
284
|
+
lang: 'messenger/PT',
|
|
285
|
+
lQuote: QuoteParser.LQ3,
|
|
286
|
+
rQuote: QuoteParser.RQ3,
|
|
287
|
+
gods: 'DEVA1s',
|
|
288
|
+
}),
|
|
289
|
+
`‘Senhor, você não viu o primeiro mensageiro/PT dos devas que apareceu entre os seres humanos?’ `,
|
|
290
|
+
)
|
|
291
|
+
.replace(
|
|
292
|
+
`These are two people in the world who are worthy of a religious-PT donation.${RQ1}`,
|
|
293
|
+
`Estas são duas pessoas no mundo que são dignas de um donativo religioso-PT.${RQ1}`,
|
|
294
|
+
)
|
|
295
|
+
.replace(
|
|
296
|
+
QuoteParser.testcaseMisterEN({
|
|
297
|
+
lang: 'messenger/PT',
|
|
298
|
+
lQuote: QuoteParser.LQ2,
|
|
299
|
+
rQuote: QuoteParser.RQ2,
|
|
300
|
+
gods: 'DEVA1s',
|
|
301
|
+
}),
|
|
302
|
+
`${LQ2}Senhor, não viu o primeiro mensageiro/PT dos DEVA1s que apareceu entre os seres humanos?${RQ2}`,
|
|
303
|
+
)
|
|
304
|
+
.replace(
|
|
305
|
+
QuoteParser.testcaseElderlyEN({
|
|
306
|
+
lQuote: LQ2,
|
|
307
|
+
rQuote: RQ2,
|
|
308
|
+
lang: ' PT',
|
|
309
|
+
}),
|
|
310
|
+
LQ2 +
|
|
311
|
+
`Senhor PT, não viu entre os seres humanos ` +
|
|
312
|
+
`uma mulher ou um homem idoso - com oitenta, ` +
|
|
313
|
+
`noventa ou cem anos - dobrado, torto, apoiado ` +
|
|
314
|
+
`num bordão, a tremer ao andar, doente, fora de moda, ` +
|
|
315
|
+
`com os dentes partidos, o cabelo grisalho e escasso ` +
|
|
316
|
+
`ou calvo, a pele enrugada e os membros manchados?` +
|
|
317
|
+
RQ2,
|
|
318
|
+
)
|
|
319
|
+
.replace(
|
|
320
|
+
QuoteParser.testcaseSickEN({
|
|
321
|
+
lQuote1: LQ3,
|
|
322
|
+
rQuote1: RQ3,
|
|
323
|
+
rQuote2: RQ2,
|
|
324
|
+
lang: 'PT sickness',
|
|
325
|
+
apos: APOS,
|
|
326
|
+
}),
|
|
327
|
+
LQ3 +
|
|
328
|
+
'Eu também estou sujeito a ficar doente. ' +
|
|
329
|
+
'Não estou isento da doença de PT. É melhor fazer o ' +
|
|
330
|
+
'bem através do corpo, da fala e da mente' +
|
|
331
|
+
RQ3 +
|
|
332
|
+
'?' +
|
|
333
|
+
RQ2,
|
|
334
|
+
)
|
|
335
|
+
.replace(
|
|
336
|
+
`when warned by the DEVA1s' messengers: `,
|
|
337
|
+
`quando avisados pelos mensageiros dos devas: `,
|
|
338
|
+
);
|
|
339
|
+
return {
|
|
340
|
+
text,
|
|
341
|
+
};
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export class MockDeepL {
|
|
347
|
+
constructor() {}
|
|
348
|
+
static get Translator() {
|
|
349
|
+
return MockTranslator;
|
|
350
|
+
}
|
|
351
|
+
}
|