Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 한글 문장과 문자가 담긴 배열을 인자로 받아 규칙에 맞게 합성하는 assemble 함수 추가 #64

Merged
merged 17 commits into from
Apr 22, 2024

Conversation

evan-moon
Copy link
Member

@evan-moon evan-moon commented Apr 19, 2024

Overview

#18 에서 이슈레이징되었던 한글 문장과 문자가 담긴 배열을 인자로 받아 규칙에 맞게 합성하는 assemble 함수, 그리고 한글 문장의 마지막 글자의 홑받침 여부를 판단하는 hasSingleBatchim를 추가합니다.

assembleHangul(['아버지가', ' ', '방ㅇ', 'ㅔ ', '들ㅇ', 'ㅓ갑니다']); // 아버지가 방에 들어갑니다
assembleHangul(['아버지가', ' ', '방에 ', '들어갑니다']); // 아버지가 방에 들어갑니다
assembleHangul(['ㅇ', 'ㅏ', 'ㅂ', 'ㅓ', 'ㅈ', 'ㅣ']); // 아버지
hasSingleBatchim('갑') // true
hasSingleBatchim('값') // false
hasSingleBatchim('토') // false

기타 변경사항

  • _internal 모듈을 Directory로 변경하고, 내부에서만 사용할 한글 도메인의 함수를 추가하였습니다.
  • _internal 모듈에 문자열을 합성하는 joinString, 공백 문자열 여부를 판단하는 isBlank, throw 행위를 추상화하기 위한 assert 함수가 추가되었습니다.
  • src/chosungIncludes.ts 내에서 사용하고 있지 않은 모듈 디펜던시를 제거하였습니다.

PR Checklist

  • I read and included theses actions below
  1. I have read the Contributing Guide
  2. I have written documents and tests, if needed.

@evan-moon evan-moon self-assigned this Apr 19, 2024
Copy link

changeset-bot bot commented Apr 19, 2024

🦋 Changeset detected

Latest commit: d791949

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Apr 19, 2024

@evan-moon is attempting to deploy a commit to the Toss Team on Vercel.

A member of the Team first needs to authorize it.

@evan-moon evan-moon added the enhancement New feature or request label Apr 19, 2024
Copy link

netlify bot commented Apr 19, 2024

Deploy Preview for es-hangul ready!

Name Link
🔨 Latest commit 71f8a33
🔍 Latest deploy log https://app.netlify.com/sites/es-hangul/deploys/662229cbc7948100082866bd
😎 Deploy Preview https://deploy-preview-64--es-hangul.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +6 to +18
export function joinString(...args: string[]) {
return args.join('');
}

export function isBlank(character: string) {
return /^\s$/.test(character);
}

export default function assert(condition: boolean, errorMessage?: string): asserts condition {
if (condition === false) {
throw new Error(errorMessage ?? 'Invalid condition');
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excludeLastElement 함수를 제외한 나머지가 이번에 추가된 함수들입니다.

`Invalid next character: ${nextCharacter}. Next character must be one of the chosung, jungsung, or jongsung.`
);

const sourceJamo = disassembleHangulToGroups(source)[0];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disassembleHangulToGroups('각') = [['ㄱ', 'ㅏ', 'ㄱ']]처럼 2차원 배열로 반환되기 때문에 바깥쪽 Array를 벗겨내어 ['ㄱ', 'ㅏ', 'ㄱ']과 같은 1차원 배열로 변경합니다.

하나의 한글 문자를 분해하는 disassembleCompleteHangulCharacter 함수는 "각"처럼 완성된 한글 문자가 아닌 경우를 처리하지 못 하기 때문에 disassembleHangulToGroups를 사용하였습니다.

Comment on lines +88 to +91
const needLinking = canBeChosung(lastJamo) && canBeJungsung(nextCharacter);
if (needLinking) {
return linkHangulCharacters(source, nextCharacter);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

마지막 자모가 초성이 될 수 있는 문자이고 다음 입력 문자가 모음이면 연음법칙을 적용합니다.

Comment on lines +93 to +94
const fixConsonant = curriedCombineHangulCharacter;
const combineJungsung = fixConsonant(restJamos[0]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source가 자음과 모음이 합성된 한글 문자이니, sourceJamos의 첫 알파벳은 자음으로 확정됩니다. (만약 모음이 첫 원소라면 source의 length가 1일 수 없음)

이제 자음 1개 + 모음 1개로 이루어진, 받침이 없는 문자에 대한 대응을 시작합니다.

Comment on lines +107 to +111
const lastConsonant = lastJamo;

if (hasSingleBatchim(source) && canBeJongsung(`${lastConsonant}${nextCharacter}`)) {
return combineJongsung(`${lastConsonant}${nextCharacter}`);
}
Copy link
Member Author

@evan-moon evan-moon Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이미 처음부터 받침을 가지고 있던 문자가 입력되었다면

  1. 연음법칙
  2. "홑받침 -> 겹받침"으로 변경
  3. 규칙에 위배되면 그냥 join

3개 케이스만 대응하면 됩니다. 연음법칙은 최상단에서 대응했으니, 겹받침을 생성하는 규칙만 적용해주면 됩니다.

okinawaa
okinawaa previously approved these changes Apr 21, 2024
Copy link
Member

@okinawaa okinawaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

많은 PR 작업해주시느라 수고하셨습니다!!

src/utils.ts Outdated
Comment on lines 44 to 49
export function hasSingleBatchim(str: string) {
const lastChar = str[str.length - 1]!;
const disassembled = disassembleHangul(lastChar);

return hasBatchim(lastChar) && disassembled.length === 3;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function hasSingleBatchim(str: string) {
const lastChar = str[str.length - 1]!;
const disassembled = disassembleHangul(lastChar);
return hasBatchim(lastChar) && disassembled.length === 3;
}
export function hasSingleBatchim(str: string) {
const lastChar = str[str.length - 1]!;
if (!hasBatchim(lastChar)) return false;
const disassembled = disassembleHangul(lastChar);
return disassembled.length === 3;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

받침이 없는 경우는 early return을 해주는 건 어떤가요?!
퍼포먼스에 큰 영향은 없을 것 같긴하네요.. ㅎㅎ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인지 부하를 줄일 수 있으니 가독성에는 좋은 영향이 있을 것 같습니다 ㅎㅎ 반영하고 핑 드릴게요 🙏

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@okinawaa 59f0379 에서 반영완료하였습니다

@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (main@b420276). Click here to learn what that means.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #64   +/-   ##
=======================================
  Coverage        ?   98.96%           
=======================================
  Files           ?       12           
  Lines           ?      193           
  Branches        ?       43           
=======================================
  Hits            ?      191           
  Misses          ?        2           
  Partials        ?        0           

Copy link
Member

@okinawaa okinawaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨어요!!

@okinawaa okinawaa merged commit ed33cd9 into toss:main Apr 22, 2024
1 of 2 checks passed
@github-actions github-actions bot mentioned this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants