@ozgurguler/trnorm 0.1.2 → 0.1.3
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/package.json +1 -1
- package/src/lexicon.js +7 -0
- package/src/normalizer.js +14 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ozgurguler/trnorm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Turkish text normalization for speech, in JavaScript: written -> spoken form for TTS, evaluation normalization for ASR (WER/CER), and spoken -> digits. The same output as the Python trnorm.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
package/src/lexicon.js
CHANGED
|
@@ -271,6 +271,13 @@ export const CAPS_WORDS = new Set([
|
|
|
271
271
|
'YIL', 'GÜN', 'İŞ', 'EV', 'EL', 'AN', 'ÖZ',
|
|
272
272
|
]);
|
|
273
273
|
|
|
274
|
+
// Titles that are also written in capitals or without the spaces ("DR. ÖĞR. ÜYESİ", "DR.ÖĞR.ÜYESİ", "Prof.Dr."):
|
|
275
|
+
// those forms are read the same (normalizer.js _ABBR_FORMS). Only titles: "AV." or "SOK." in capitals could be other words.
|
|
276
|
+
export const TITLE_ABBREVIATIONS = [
|
|
277
|
+
'Prof. Dr.', 'Doç. Dr.', 'Yrd. Doç. Dr.', 'Dr. Öğr. Üyesi', 'Öğr. Gör.', 'Arş. Gör.', 'Uzm. Dr.', 'Op. Dr.',
|
|
278
|
+
'Yrd. Doç.', 'Prof.', 'Doç.', 'Dr.', 'Uzm.', 'Müh.',
|
|
279
|
+
];
|
|
280
|
+
|
|
274
281
|
// Dotted / colon abbreviations (case-sensitive). Longest match wins.
|
|
275
282
|
export const ABBREVIATIONS = dict({
|
|
276
283
|
'Prof. Dr.': 'profesör doktor',
|
package/src/normalizer.js
CHANGED
|
@@ -491,8 +491,20 @@ function _pass_web(text) {
|
|
|
491
491
|
return _sub(_URL_RE, url, text);
|
|
492
492
|
}
|
|
493
493
|
|
|
494
|
+
// ABBREVIATIONS, and each title also in capitals and without the spaces after its dots
|
|
495
|
+
const _ABBR_FORMS = (() => {
|
|
496
|
+
const forms = new Map(L.ABBREVIATIONS);
|
|
497
|
+
for (const key of L.TITLE_ABBREVIATIONS) {
|
|
498
|
+
const spoken = L.ABBREVIATIONS.get(key);
|
|
499
|
+
for (const form of [key.replaceAll('. ', '.'), tr_upper(key), tr_upper(key).replaceAll('. ', '.')]) {
|
|
500
|
+
if (!forms.has(form)) forms.set(form, spoken);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return forms;
|
|
504
|
+
})();
|
|
505
|
+
|
|
494
506
|
function _build_abbr_re() {
|
|
495
|
-
const keys = [...
|
|
507
|
+
const keys = [..._ABBR_FORMS.keys()].sort((a, b) => plen(b) - plen(a));
|
|
496
508
|
const alt = keys.map(re.escape).join('|');
|
|
497
509
|
const first = [...new Set(keys.map(first_cp))].join('');
|
|
498
510
|
// every key has a "." or a ":" ("Dr.", "No:")
|
|
@@ -509,7 +521,7 @@ const _SPACE_CAPITAL_RE = re.compile(`${S}+[${UP}]`);
|
|
|
509
521
|
function _pass_abbreviations(text) {
|
|
510
522
|
const repl = (m) => {
|
|
511
523
|
const key = m[1];
|
|
512
|
-
let out =
|
|
524
|
+
let out = _ABBR_FORMS.get(key);
|
|
513
525
|
if (L.SENTENCE_FINAL_ABBR.has(key)) {
|
|
514
526
|
const rest = text.slice(end(m));
|
|
515
527
|
if (!strip(rest) || _SPACE_CAPITAL_RE.match(rest)) out += '.';
|