Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/angry-ravens-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"es-hangul": patch
---

fix: 사이시옷 단어 모음 추가
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
export const 사이시옷_에외사항_목록: Record<string, string> = {
베갯잇: '베갠닏',
깻잎: '깬닙',
나뭇잎: '나문닙',
도리깻열: '도리깬녈',
뒷윷: '뒨뉻',
};

export const 단일어_예외사항_단어모음: Record<string, string> = {
전역: '저녁',
};
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,14 @@ describe('standardizePronunciation', () => {
});

describe('예외사항은 정의된 단어 모음에서 반환한다', () => {
it('사이시옷 예외사항 단어는 단어모음에서 찾아 반환한다', () => {
expect(standardizePronunciation('베갯잇')).toBe('베갠닏');
expect(standardizePronunciation('깻잎')).toBe('깬닙');
expect(standardizePronunciation('나뭇잎')).toBe('나문닙');
expect(standardizePronunciation('도리깻열')).toBe('도리깬녈');
expect(standardizePronunciation('뒷윷')).toBe('뒨뉻');
});

it('파생어/합성어 예외사항 단어는 단어모음에서 찾아 반환한다', () => {
expect(standardizePronunciation('전역')).toBe('저녁');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isNotUndefined, joinString } from '@/_internal';
import { isHangulAlphabet, isHangulCharacter } from '@/_internal/hangul';
import { combineCharacter } from '@/core/combineCharacter';
import { disassembleCompleteCharacter } from '@/core/disassembleCompleteCharacter';
import { 단일어_예외사항_단어모음 } from './exceptionWords.constants';
import { 단일어_예외사항_단어모음, 사이시옷_에외사항_목록 } from './exceptionWords.constants';
import {
transform12th,
transform13And14th,
Expand All @@ -27,6 +27,30 @@ type NotHangul = {
syllable: string;
};

type ExceptionChecker = (hangul: string) => string | undefined;

const createExceptionChecker =
(exceptionMap: Record<string, string>): ExceptionChecker =>
(hangul: string) =>
exceptionMap[hangul];

const exceptionCheckers: ExceptionChecker[] = [
createExceptionChecker(사이시옷_에외사항_목록),
createExceptionChecker(단일어_예외사항_단어모음),
];

const findFirstException = (hangul: string): string | null => {
for (const checker of exceptionCheckers) {
const result = checker(hangul);

if (isNotUndefined(result)) {
return result;
}
}

return null;
};

/**
* 주어진 한글 문자열을 표준 발음으로 변환합니다.
* @param hangul 한글 문자열을 입력합니다.
Expand All @@ -39,8 +63,10 @@ export function standardizePronunciation(hangul: string, options: Options = { ha
return '';
}

if (hangul in 단일어_예외사항_단어모음) {
return 단일어_예외사항_단어모음[hangul];
const exceptionResult = findFirstException(hangul);

if (exceptionResult) {
return exceptionResult;
}

const processSyllables = (syllables: Syllable[], phrase: string, options: Options) =>
Expand Down