From 651bc98dade3d1bad10e49e0d624ec21679f22f5 Mon Sep 17 00:00:00 2001 From: EJClaw Date: Wed, 4 Nov 2026 16:36:30 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A0=9C=EB=AA=A9=20=EC=A0=95=EB=A6=AC=20?= =?UTF-8?q?=EA=B2=80=ED=86=A0:=20=EA=B4=84=ED=98=B8=20=EC=95=88=EC=97=90?= =?UTF-8?q?=20=ED=95=9C=EA=B8=80=EC=9D=B4=20=EC=9E=88=EB=8A=94=20=EC=9D=BC?= =?UTF-8?q?=EB=B3=B8=EC=96=B4=20=EC=A0=9C=EB=AA=A9(=E5=A4=9C=E3=81=AB?= =?UTF-8?q?=E9=A7=86=E3=81=91=E3=82=8B=20(=EB=B0=A4=EC=97=90=20=EB=8B=AC?= =?UTF-8?q?=EB=A6=AC=EB=8B=A4))=EC=9D=84=20=ED=95=9C=EA=B8=80=20=EA=B3=A1?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B4=90=EC=84=9C=20=EC=83=88=20=EA=B3=A1?= =?UTF-8?q?=EC=9D=BC=20=EB=95=8C=20=EA=B2=80=ED=86=A0=20=EC=97=86=EC=9D=B4?= =?UTF-8?q?=20=EB=B0=94=EB=A1=9C=20=EB=B0=98=EC=98=81=ED=95=98=EB=8D=98=20?= =?UTF-8?q?=EA=B2=83=20=E2=80=94=20=EA=B4=84=ED=98=B8=20=EB=B0=96=20?= =?UTF-8?q?=EC=9B=90=EC=A0=9C=EA=B0=80=20=EC=9D=BC=EB=B3=B8=EC=96=B4?= =?UTF-8?q?=EC=9D=B8=EC=A7=80=EB=A1=9C=20=EC=9D=BC=EB=B3=B8=EC=96=B4=20?= =?UTF-8?q?=EA=B3=A1=EC=9D=84=20=EA=B0=80=EB=A6=BC(japaneseName,=20?= =?UTF-8?q?=EC=A0=95=EB=8B=B5=20=EC=83=9D=EC=84=B1=EB=8F=84=20=EA=B0=99?= =?UTF-8?q?=EC=9D=80=20=EA=B8=B0=EC=A4=80).=20=ED=9A=8C=EA=B7=80=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8:=20=EA=B7=B8=20=EA=B3=A1=EC=9D=80?= =?UTF-8?q?=20=EC=9D=BC=EB=B3=B8=EC=96=B4=20=EA=B3=A1=C2=B7=EA=B2=80?= =?UTF-8?q?=ED=86=A0=20=EB=8C=80=EA=B8=B0=EB=A1=9C=20=EB=82=A8=EA=B3=A0=20?= =?UTF-8?q?DB=20=EC=A0=9C=EB=AA=A9=EC=9D=80=20=EA=B7=B8=EB=8C=80=EB=A1=9C,?= =?UTF-8?q?=20=EB=AA=BD(=E5=A4=A2)=EC=9D=80=20=ED=95=9C=EA=B5=AD=EC=96=B4?= =?UTF-8?q?=20=EA=B3=A1=EC=9C=BC=EB=A1=9C=20=EB=B0=94=EB=A1=9C=20=EB=B0=98?= =?UTF-8?q?=EC=98=81(=EA=B3=A0=EC=B9=98=EA=B8=B0=20=EC=A0=84=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=20=ED=99=95=EC=9D=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- apps/server/src/answers/index.ts | 4 ++-- apps/server/src/answers/ja-reading.ts | 6 ++++++ apps/server/src/songs/title-review.ts | 4 ++-- apps/server/src/title-review.test.ts | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/apps/server/src/answers/index.ts b/apps/server/src/answers/index.ts index b0badbe..aafd52b 100644 --- a/apps/server/src/answers/index.ts +++ b/apps/server/src/answers/index.ts @@ -10,7 +10,7 @@ import type { Database } from 'bun:sqlite'; import { cleanTitle } from '@mq/shared'; import { englishToHangul } from './en-ko'; import { kanaToHangul } from './ja-ko'; -import { hasJapanese, readJapanese, type JaReader } from './ja-reading'; +import { hasJapanese, japaneseName, readJapanese, type JaReader } from './ja-reading'; import type { WikiLookup } from './wiki'; export interface SongAnswers { @@ -115,7 +115,7 @@ export async function songAnswersBatch(db: Database | null, songs: { title: stri // the Japanese title: shown as is, or already swapped for its bracket's Korean name by cleanTitle // ("夜に駆ける (밤에 달리다)") — Wikipedia still goes first, so the order is decided on the original // only when the title outside the brackets was Japanese: "몽(夢)" is a Korean title with a 한자 alias, never renamed - const outsideJa = hasJapanese(s.title.replace(/[([{([【「『][^)\]})]】」』]*[)\]})]】」』]/g, ' ')); + const outsideJa = japaneseName(s.title); const jaTitle = hasJapanese(c.title) ? c.title : outsideJa ? c.aliases.find((a) => hasJapanese(a)) : undefined; if (opts.korean && jaTitle) { const bracket = hasJapanese(c.title) ? c.aliases.find((a) => HANGUL.test(a) && !hasJapanese(a)) : c.title; diff --git a/apps/server/src/answers/ja-reading.ts b/apps/server/src/answers/ja-reading.ts index a5da0e6..2738924 100644 --- a/apps/server/src/answers/ja-reading.ts +++ b/apps/server/src/answers/ja-reading.ts @@ -6,6 +6,12 @@ import { join } from 'node:path'; export const hasJapanese = (s: string) => /[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u.test(s) && !/\p{Script=Hangul}/u.test(s); +/** + * The name outside its brackets is Japanese: "夜に駆ける (밤에 달리다)" is, "몽(夢)" and "Good bye-bye (グッバイバイ)" are not + * (a Korean/English name with a Japanese or 한자 alias). + */ +export const japaneseName = (s: string) => hasJapanese(s.replace(/[([{([【「『][^)\]})]】」』]*[)\]})]】」』]/g, ' ')); + export type JaReader = (texts: string[]) => Promise<(string | null)[]>; export const readJapanese: JaReader = async (texts) => { diff --git a/apps/server/src/songs/title-review.ts b/apps/server/src/songs/title-review.ts index 5161494..2682eb1 100644 --- a/apps/server/src/songs/title-review.ts +++ b/apps/server/src/songs/title-review.ts @@ -6,7 +6,7 @@ * charts keep finding the song by its source name. A row whose song was edited since it was made is not applied. */ import type { Database } from 'bun:sqlite'; -import { hasJapanese } from '../answers/ja-reading'; +import { japaneseName } from '../answers/ja-reading'; import { songAnswersBatch, type AnswerOptions } from '../answers'; export type TitleReviewKind = 'title' | 'answers' | 'japanese' | 'check'; @@ -85,7 +85,7 @@ export async function buildTitleReviews( return; } const notes = a.note ? [a.note] : []; - const kind: TitleReviewKind = a.note?.includes('확인 필요') ? 'check' : hasJapanese(s.title) || hasJapanese(s.artist) ? 'japanese' : renamed ? 'title' : 'answers'; + const kind: TitleReviewKind = a.note?.includes('확인 필요') ? 'check' : japaneseName(s.title) || japaneseName(s.artist) ? 'japanese' : renamed ? 'title' : 'answers'; const status = opts.review || kind === 'japanese' || kind === 'check' ? 'pending' : 'auto'; save.run(s.id, kind, status, s.title, s.artist, a.title, a.artist, JSON.stringify(ta), JSON.stringify(aa), notes.join(' · ') || null, now); if (status === 'auto') { diff --git a/apps/server/src/title-review.test.ts b/apps/server/src/title-review.test.ts index ce6e301..067f899 100644 --- a/apps/server/src/title-review.test.ts +++ b/apps/server/src/title-review.test.ts @@ -92,3 +92,20 @@ test('관리자 API: list, apply a kind, skip; guests may not', async () => { await s.stop(); } }); + +test('new songs: a Japanese title with a Korean bracket ("夜に駆ける (밤에 달리다)") still waits as 일본어 곡; "몽(夢)" is a Korean song', async () => { + const db = openDb(tempDbPath()); + const c = new Catalog(db); + const [ja] = c.upsert({ title: '夜に駆ける (밤에 달리다)', artists: [{ name: 'YOASOBI' }], source: 't', ref: '1' }); + const [ko] = c.upsert({ title: '몽(夢)', artists: [{ name: '가수' }], source: 't', ref: '2' }); + const r = await buildTitleReviews(db, { wiki: async () => new Map() }); + expect(r).toMatchObject({ pending: 1, auto: 1 }); + const rows = listTitleReviews(db, {}).rows; + expect(rows).toHaveLength(1); + expect(rows[0]).toMatchObject({ songId: ja, kind: 'japanese', status: 'pending', newTitle: '밤에 달리다' }); + const title = (id: number) => db.query<{ title: string }, [number]>('SELECT title FROM songs WHERE id = ?').get(id)!.title; + expect(title(ja!)).toBe('夜に駆ける (밤에 달리다)'); + // the Korean song was applied at once, keeping its title and the 한자 as an answer + expect(title(ko!)).toBe('몽'); + expect(db.query<{ alias: string }, [number]>("SELECT alias FROM song_aliases WHERE song_id = ? AND part = 'title'").all(ko!).map((x) => x.alias)).toContain('夢'); +});