Skip to content

Conversation

@diyung0
Copy link
Contributor

@diyung0 diyung0 commented Oct 26, 2025

한국 점자 규정 제47항: 분수 표기 지원

한국 점자 규정 제47항의 분수 표기 규칙을 구현했습니다.

제47항 분수는 분수표 ⠌(12)을 사용하여 분모, 분수표, 분자 순으로 적고, 대분수는 정수와 분수를 붙여 적는다.
[붙임] 분수를 표시하는 빗금(/)은⠸⠌(5612)으로 적고, 순서는 묵자를 따른다.

1. 새로운 모듈: fraction.rs

인코딩 함수

  • encode_fraction(numerator, denominator): 일반 분수 (분모→12→분자)
    • 예: 3/4[60][4][12][60][3]
  • encode_fraction_in_context(numerator, denominator): 문맥 내 분수 (분자→56-12→분모)
    • 예: 숫자 뒤 2/3[60][2][56][12][60][3]
  • encode_mixed_fraction(whole, numerator, denominator): 대분수
    • 예: 3 1/6[60][3][60][6][12][60][1]

파싱 함수

  • parse_latex_fraction(s): LaTeX 형식 파싱
    • $\frac{3}{4}$(None, "3", "4")
    • $3\frac{1}{6}$(Some("3"), "1", "6")
  • parse_unicode_fraction(c): 유니코드 분수 파싱 (NFKD 분해)
    • ("2", "3")
  • is_unicode_fraction(c): 유니코드 분수 문자 판별

2. CharType 확장

Fraction(char),  // 유니코드 분수 문자 타입 추가

3. Encoder 로직 추가

LaTeX 분수 처리

if word.starts_with('$') && word.ends_with('$') {
    if let Some((whole, num, den)) = fraction::parse_latex_fraction(word) {
        // 대분수 또는 일반 분수 인코딩
    }
}

숫자 뒤 분수 처리

정규식 r#"^(\d+)/(\d+)#"으로 패턴 감지 후:

  • 날짜(12/25, 1/4~1/8): 일반 처리
  • 진짜 분수(2/3): encode_fraction_in_context() 사용

유니코드 분수 처리

CharType::Fraction(c) => {
    if let Some((num_str, den_str)) = fraction::parse_unicode_fraction(c) {
        result.extend(fraction::encode_fraction(&num_str, &den_str)?);
    }
}

4. 의존성 추가

regex = "1"                       # 텍스트 패턴 매칭 및 추출 (숫자/슬래시 패턴 감지용)
once_cell = "1"                   # 정규식 컴파일 결과 캐싱
unicode-normalization = "0.1.20"  # 유니코드 정규 분해(NFKD)를 통한 호환 문자 변환 (⅔ → 2⁄3)

* 지원하는 분수 형식

형식 예시 출력
LaTeX 분수 $\frac{3}{4}$ ⠼⠙⠌⠼⠉
LaTeX 대분수 $3\frac{1}{6}$ ⠼⠉⠼⠋⠌⠼⠁
유니코드 분수 ⠼⠃⠸⠌⠼⠉
문맥 내 분수 표면의 2/3는 ...⠼⠃⠸⠌⠼⠉...

* 테스트 결과

image

@changeset-bot
Copy link

changeset-bot bot commented Oct 26, 2025

⚠️ No Changeset found

Latest commit: 9fa3949

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Comment on lines 72 to 86
'½' => Some((1, 2)),
'⅓' => Some((1, 3)),
'⅔' => Some((2, 3)),
'¼' => Some((1, 4)),
'¾' => Some((3, 4)),
'⅕' => Some((1, 5)),
'⅖' => Some((2, 5)),
'⅗' => Some((3, 5)),
'⅘' => Some((4, 5)),
'⅙' => Some((1, 6)),
'⅚' => Some((5, 6)),
'⅛' => Some((1, 8)),
'⅜' => Some((3, 8)),
'⅝' => Some((5, 8)),
'⅞' => Some((7, 8)),
Copy link
Contributor

Choose a reason for hiding this comment

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

자음 모음을 분리하듯...뭔가.. 뭔가 방법이 없을까요?
이 방법은 모든 상황을 처리할 수 없습니다

Copy link
Contributor Author

@diyung0 diyung0 Oct 27, 2025

Choose a reason for hiding this comment

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

unicode-normalization 크레이트를 추가하여 유니코드 분수 문자를 일반적으로 처리할 수 있도록 구현했습니다. NFKD 정규화를 통해 , ¾ 등의 분수 문자를 2⁄3, 3⁄4로 분해하여 분자와 분모를 추출합니다.
(https://docs.rs/unicode-normalization/latest/unicode_normalization/)

Comment on lines 51 to 53
let mut result = Vec::new();

result.push(60);
Copy link
Contributor

Choose a reason for hiding this comment

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

기본적으로 안고 시작하는게 좋겠어요
vec![60]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let mut result = vec![60];로 시작하도록 수정했습니다!

@codecov
Copy link

codecov bot commented Oct 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
libs/braillify/src/char_struct.rs 97.05% <100.00%> (+0.18%) ⬆️
libs/braillify/src/fraction.rs 100.00% <100.00%> (ø)
libs/braillify/src/lib.rs 89.40% <100.00%> (+1.42%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@diyung0 diyung0 changed the title [WIP] 47항 분수 처리 추가 한국 점자 규정 제47항: 분수 표기 지원 Oct 27, 2025
@diyung0 diyung0 requested a review from owjs3901 October 27, 2025 05:39
@owjs3901
Copy link
Contributor

테스트 코드만 추가해주심 좋을 것 같습니다!

@diyung0
Copy link
Contributor Author

diyung0 commented Oct 28, 2025

테스트 코드만 추가해주심 좋을 것 같습니다!

@owjs3901 네 테스트 코드 추가했습니다. 확인 부탁드립니다!

@owjs3901 owjs3901 merged commit 4f1c478 into dev-five-git:main Oct 28, 2025
2 checks passed
@diyung0 diyung0 deleted the fraction-test branch October 28, 2025 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants