From 58670a41c66a953aae97fdc8fe9e00c31947a839 Mon Sep 17 00:00:00 2001 From: Eana Hufwe Date: Wed, 4 Sep 2024 23:53:26 +0000 Subject: [PATCH] feat(jukebox): convertMonoruby by dictionary when encountering words not in dictionary --- packages/common/src/utils/transliterate.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/common/src/utils/transliterate.ts b/packages/common/src/utils/transliterate.ts index fb05935..32432ef 100644 --- a/packages/common/src/utils/transliterate.ts +++ b/packages/common/src/utils/transliterate.ts @@ -165,10 +165,19 @@ async function applyFuriganaMapping( if (cache?.[text]?.[furigana]) { return cache[text][furigana]; } - const [{ segmentedText, segmentedFurigana }, created] = + let [{ segmentedText, segmentedFurigana }, created] = await FuriganaMapping.findOrCreate({ where: { text, furigana }, }); + if (created) { + const [textGroups, furiganaGroups] = convertMonoruby(text, furigana); + if (textGroups.length > 1 && furiganaGroups.length > 1) { + segmentedText = textGroups.join(","); + segmentedFurigana = furiganaGroups.join(","); + await FuriganaMapping.update({ segmentedText, segmentedFurigana }, { where: { text, furigana } }); + created = false; + } + } if (created || !segmentedText || !segmentedFurigana) { return [v]; } @@ -574,3 +583,7 @@ export async function transliterate( return text; } } +function convertMonoruby(text: string, furigana: string): [any, any] { + throw new Error("Function not implemented."); +} +