From 42a2917bf7aa3ab424ada2fc3acf224b74020a7f Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 10 Apr 2020 11:56:18 -0400 Subject: Add support for collapsing emphatic character sequences --- ext/bg/js/translator.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'ext/bg/js/translator.js') diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 27f91c05..402ac6bd 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -348,17 +348,27 @@ class Translator { getAllDeinflections(text, options) { const translationOptions = options.translation; + const collapseEmphaticOptions = [[false, false]]; + switch (translationOptions.collapseEmphaticSequences) { + case 'true': + collapseEmphaticOptions.push([true, false]); + break; + case 'full': + collapseEmphaticOptions.push([true, true]); + break; + } const textOptionVariantArray = [ Translator.getTextOptionEntryVariants(translationOptions.convertHalfWidthCharacters), Translator.getTextOptionEntryVariants(translationOptions.convertNumericCharacters), Translator.getTextOptionEntryVariants(translationOptions.convertAlphabeticCharacters), Translator.getTextOptionEntryVariants(translationOptions.convertHiraganaToKatakana), - Translator.getTextOptionEntryVariants(translationOptions.convertKatakanaToHiragana) + Translator.getTextOptionEntryVariants(translationOptions.convertKatakanaToHiragana), + collapseEmphaticOptions ]; const deinflections = []; const used = new Set(); - for (const [halfWidth, numeric, alphabetic, katakana, hiragana] of Translator.getArrayVariants(textOptionVariantArray)) { + for (const [halfWidth, numeric, alphabetic, katakana, hiragana, [collapseEmphatic, collapseEmphaticFull]] of Translator.getArrayVariants(textOptionVariantArray)) { let text2 = text; const sourceMap = new TextSourceMap(text2); if (halfWidth) { @@ -376,6 +386,9 @@ class Translator { if (hiragana) { text2 = jp.convertKatakanaToHiragana(text2); } + if (collapseEmphatic) { + text2 = jp.collapseEmphaticSequences(text2, collapseEmphaticFull, sourceMap); + } for (let i = text2.length; i > 0; --i) { const text2Substring = text2.substring(0, i); -- cgit v1.2.3 From 70f0b8b0cd7c85bd8af230cf6a74a0d0e1d0bbc2 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 11 Apr 2020 18:58:14 -0400 Subject: Fix 'full' mode not being a superset of 'true' mode --- ext/bg/js/translator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/bg/js/translator.js') diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 402ac6bd..fd14b72d 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -354,7 +354,7 @@ class Translator { collapseEmphaticOptions.push([true, false]); break; case 'full': - collapseEmphaticOptions.push([true, true]); + collapseEmphaticOptions.push([true, false], [true, true]); break; } const textOptionVariantArray = [ -- cgit v1.2.3