mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-05-26 12:55:16 -07:00
fix(character-dictionary): add surname honorifics for Japanese localized aliases (#87)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
export const ANILIST_GRAPHQL_URL = 'https://graphql.anilist.co';
|
||||
export const ANILIST_REQUEST_DELAY_MS = 2000;
|
||||
export const CHARACTER_IMAGE_DOWNLOAD_DELAY_MS = 250;
|
||||
export const CHARACTER_DICTIONARY_FORMAT_VERSION = 17;
|
||||
export const CHARACTER_DICTIONARY_FORMAT_VERSION = 18;
|
||||
export const CHARACTER_DICTIONARY_MERGED_TITLE = 'SubMiner Character Dictionary';
|
||||
|
||||
export const HONORIFIC_SUFFIXES = [
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { buildNameTerms } from './term-building';
|
||||
import type { CharacterRecord } from './types';
|
||||
|
||||
function characterRecord(overrides: Partial<CharacterRecord>): CharacterRecord {
|
||||
return {
|
||||
id: 136073,
|
||||
role: 'primary',
|
||||
firstNameHint: 'Chi-Yul',
|
||||
fullName: 'Chi-Yul Song',
|
||||
lastNameHint: 'Song',
|
||||
nativeName: '송치율',
|
||||
alternativeNames: [],
|
||||
bloodType: '',
|
||||
birthday: null,
|
||||
description: '',
|
||||
imageUrl: null,
|
||||
age: '',
|
||||
sex: '',
|
||||
voiceActors: [],
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
test('buildNameTerms adds surname honorifics from Japanese localized aliases', () => {
|
||||
const terms = buildNameTerms(
|
||||
characterRecord({
|
||||
alternativeNames: ['Isao Mabuchi (馬渕勲)', 'Chi-Yeol (송치열)'],
|
||||
}),
|
||||
);
|
||||
|
||||
assert.ok(terms.includes('馬渕勲'));
|
||||
assert.ok(terms.includes('馬渕勲さん'));
|
||||
assert.ok(terms.includes('馬渕'));
|
||||
assert.ok(terms.includes('馬渕さん'));
|
||||
assert.ok(!terms.includes('송치'));
|
||||
});
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
addRomanizedKanaAliases,
|
||||
buildReading,
|
||||
buildReadingFromRomanized,
|
||||
containsKanji,
|
||||
hasKanaOnly,
|
||||
isRomanizedName,
|
||||
splitJapaneseName,
|
||||
@@ -39,6 +40,25 @@ function expandRawNameVariants(rawName: string): string[] {
|
||||
return [...variants];
|
||||
}
|
||||
|
||||
function isJapaneseNameSplitCandidate(name: string): boolean {
|
||||
const compact = name.replace(/[\s\u3000・・·•]/g, '');
|
||||
return (
|
||||
containsKanji(compact) && /^[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff々〆ヵヶー]+$/.test(compact)
|
||||
);
|
||||
}
|
||||
|
||||
function addJapaneseNameParts(character: CharacterRecord, name: string, terms: Set<string>): void {
|
||||
if (!isJapaneseNameSplitCandidate(name)) return;
|
||||
|
||||
const nameParts = splitJapaneseName(name, character.firstNameHint, character.lastNameHint);
|
||||
if (nameParts.family) {
|
||||
terms.add(nameParts.family);
|
||||
}
|
||||
if (nameParts.given) {
|
||||
terms.add(nameParts.given);
|
||||
}
|
||||
}
|
||||
|
||||
export function buildNameTerms(character: CharacterRecord): string[] {
|
||||
const base = new Set<string>();
|
||||
const romanizedBase = new Set<string>();
|
||||
@@ -73,6 +93,10 @@ export function buildNameTerms(character: CharacterRecord): string[] {
|
||||
target.add(part);
|
||||
}
|
||||
}
|
||||
|
||||
if (target === base) {
|
||||
addJapaneseNameParts(character, name, base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user