Skip to content

Commit ec26b5f

Browse files
po4tionokinawaa
andauthored
fix: 사이시옷 단어 모음 추가 (#350)
* fix: 사이시옷 단어 모음 추가 * fix: test 문구 수정 * standardizePronunciation 예외사항 로직 개선 * 최선의 경우, 빅오를 O(n)에서 O(1)로 개선 * Create angry-ravens-perform.md --------- Co-authored-by: 박찬혁 <[email protected]>
1 parent d329225 commit ec26b5f

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

.changeset/angry-ravens-perform.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"es-hangul": patch
3+
---
4+
5+
fix: 사이시옷 단어 모음 추가
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
export const 사이시옷_에외사항_목록: Record<string, string> = {
2+
베갯잇: '베갠닏',
3+
깻잎: '깬닙',
4+
나뭇잎: '나문닙',
5+
도리깻열: '도리깬녈',
6+
뒷윷: '뒨뉻',
7+
};
8+
19
export const 단일어_예외사항_단어모음: Record<string, string> = {
210
전역: '저녁',
311
};

src/pronunciation/standardizePronunciation/standardizePronunciation.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,14 @@ describe('standardizePronunciation', () => {
364364
});
365365

366366
describe('예외사항은 정의된 단어 모음에서 반환한다', () => {
367+
it('사이시옷 예외사항 단어는 단어모음에서 찾아 반환한다', () => {
368+
expect(standardizePronunciation('베갯잇')).toBe('베갠닏');
369+
expect(standardizePronunciation('깻잎')).toBe('깬닙');
370+
expect(standardizePronunciation('나뭇잎')).toBe('나문닙');
371+
expect(standardizePronunciation('도리깻열')).toBe('도리깬녈');
372+
expect(standardizePronunciation('뒷윷')).toBe('뒨뉻');
373+
});
374+
367375
it('파생어/합성어 예외사항 단어는 단어모음에서 찾아 반환한다', () => {
368376
expect(standardizePronunciation('전역')).toBe('저녁');
369377
});

src/pronunciation/standardizePronunciation/standardizePronunciation.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { isNotUndefined, joinString } from '@/_internal';
22
import { isHangulAlphabet, isHangulCharacter } from '@/_internal/hangul';
33
import { combineCharacter } from '@/core/combineCharacter';
44
import { disassembleCompleteCharacter } from '@/core/disassembleCompleteCharacter';
5-
import { 단일어_예외사항_단어모음 } from './exceptionWords.constants';
5+
import { 단일어_예외사항_단어모음, 사이시옷_에외사항_목록 } from './exceptionWords.constants';
66
import {
77
transform12th,
88
transform13And14th,
@@ -27,6 +27,30 @@ type NotHangul = {
2727
syllable: string;
2828
};
2929

30+
type ExceptionChecker = (hangul: string) => string | undefined;
31+
32+
const createExceptionChecker =
33+
(exceptionMap: Record<string, string>): ExceptionChecker =>
34+
(hangul: string) =>
35+
exceptionMap[hangul];
36+
37+
const exceptionCheckers: ExceptionChecker[] = [
38+
createExceptionChecker(사이시옷_에외사항_목록),
39+
createExceptionChecker(단일어_예외사항_단어모음),
40+
];
41+
42+
const findFirstException = (hangul: string): string | null => {
43+
for (const checker of exceptionCheckers) {
44+
const result = checker(hangul);
45+
46+
if (isNotUndefined(result)) {
47+
return result;
48+
}
49+
}
50+
51+
return null;
52+
};
53+
3054
/**
3155
* 주어진 한글 문자열을 표준 발음으로 변환합니다.
3256
* @param hangul 한글 문자열을 입력합니다.
@@ -39,8 +63,10 @@ export function standardizePronunciation(hangul: string, options: Options = { ha
3963
return '';
4064
}
4165

42-
if (hangul in 단일어_예외사항_단어모음) {
43-
return 단일어_예외사항_단어모음[hangul];
66+
const exceptionResult = findFirstException(hangul);
67+
68+
if (exceptionResult) {
69+
return exceptionResult;
4470
}
4571

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

0 commit comments

Comments
 (0)