Skip to content

Commit d298ab2

Browse files
authored
Merge pull request #41 from dev-five-git/fix-test-case-check-en
Fix test case and checking en
2 parents 5a85b31 + 28f6aea commit d298ab2

7 files changed

Lines changed: 45 additions & 37 deletions

File tree

libs/braillify/src/lib.rs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ impl Encoder {
8181
} else {
8282
let word_chars = word.chars().collect::<Vec<char>>();
8383
let word_len = word_chars.len();
84+
// 단어 전체가 대문자인지 확인(타 언어인 경우 반드시 false)
8485
let is_all_uppercase = word_chars.iter().all(|c| c.is_uppercase());
8586
let has_korean_char = word_chars
8687
.iter()
@@ -127,9 +128,12 @@ impl Encoder {
127128

128129
if self.english_indicator && i > 0 && !c.is_ascii_alphabetic() {
129130
// 제31항 국어 문장 안에 그리스 문자가 나올 때에는 그 앞에 로마자표 ⠴을 적고 그 뒤에 로마자 종료표 ⠲을 적는다
130-
if self.is_english && !['"', ')', '('].contains(c) {
131+
if self.is_english {
132+
// 제33항 「통일영어점자 규정」과 「한글 점자」의 점형이 다른 문장 부호(, : ; ―)가 로마자와 한글 사이에 나올 때에는 로마자 종료표를 적지 않고 문장 부호는 「한글 점자」에 따라 적는다.
131133
// 제34항 로마자가 따옴표나 괄호 등으로 묶일 때에는 로마자 종료표를 적지 않는다.
132-
result.push(50);
134+
if !['"', ')', '('].contains(c) && ![',', ':', ';', '―'].contains(c) {
135+
result.push(50);
136+
}
133137
}
134138
self.is_english = false;
135139
}
@@ -253,9 +257,11 @@ impl Encoder {
253257
) {
254258
result.push(code);
255259
*skip_count = len;
256-
} else if let Some((code, len)) = rule_en_10_4(
257-
&word_chars[i..].iter().collect::<String>().to_lowercase(),
258-
) {
260+
} else if !is_all_uppercase
261+
&& let Some((code, len)) = rule_en_10_4(
262+
&word_chars[i..].iter().collect::<String>().to_lowercase(),
263+
)
264+
{
259265
result.push(code);
260266
*skip_count = len;
261267
} else {
@@ -298,18 +304,14 @@ impl Encoder {
298304
result.push(if c == '\n' { 255 } else { 0 });
299305
}
300306
CharType::MathSymbol(c) => {
301-
if i > 0
302-
&& word_chars[..i]
303-
.iter()
304-
.any(|c| (0xAC00 <= *c as u32 && *c as u32 <= 0xD7A3))
305-
{
307+
if i > 0 && word_chars[..i].iter().any(|c| utils::is_korean_char(*c)) {
306308
result.push(0);
307309
}
308310
result.extend(math_symbol_shortcut::encode_char_math_symbol_shortcut(c)?);
309311
if i < word_len - 1 {
310312
let mut korean = vec![];
311313
for wc in word_chars[i..].iter() {
312-
if 0xAC00 <= *wc as u32 && *wc as u32 <= 0xD7A3 {
314+
if utils::is_korean_char(*wc) {
313315
korean.push(*wc);
314316
} else if !korean.is_empty() {
315317
break;
@@ -339,14 +341,14 @@ impl Encoder {
339341
&& !(remaining_words
340342
.first()
341343
.is_some_and(|w| w.chars().all(|c| c.is_ascii_alphabetic())))
342-
{
343-
// 28항 [붙임] 로마자가 한 글자만 대문자일 때에는 대문자 기호표 ⠠을 그 앞에 적고, 단어 전체가 대문자이거나 두 글자 이상 연속해서 대문자일 때에는 대문자 단어표
344-
// ⠠⠠을 그 앞에 적는다. 세 개 이상의 연속된 단어가 모두 대문자일 때에는 첫 단어
345-
// 앞에 대문자 구절표 ⠠⠠⠠을 적고, 마지막 단어 뒤에 대문자 종료표 ⠠⠄을 적는다.
346-
result.push(32);
347-
result.push(4);
348-
self.triple_big_english = false; // Reset after adding terminator
349-
}
344+
{
345+
// 28항 [붙임] 로마자가 한 글자만 대문자일 때에는 대문자 기호표 ⠠을 그 앞에 적고, 단어 전체가 대문자이거나 두 글자 이상 연속해서 대문자일 때에는 대문자 단어표
346+
// ⠠⠠을 그 앞에 적는다. 세 개 이상의 연속된 단어가 모두 대문자일 때에는 첫 단어
347+
// 앞에 대문자 구절표 ⠠⠠⠠을 적고, 마지막 단어 뒤에 대문자 종료표 ⠠⠄을 적는다.
348+
result.push(32);
349+
result.push(4);
350+
self.triple_big_english = false; // Reset after adding terminator
351+
}
350352
if !remaining_words.is_empty() {
351353
if self.english_indicator
352354
&& !remaining_words[0]
@@ -385,11 +387,10 @@ impl Encoder {
385387

386388
pub fn encode(text: &str) -> Result<Vec<u8>, String> {
387389
// 한국어가 존재할 경우 english_indicator 가 true 가 됩니다.
388-
let english_indicator = text.split(' ').filter(|word| !word.is_empty()).any(|word| {
389-
word.chars().any(|c| {
390-
(c as u32 >= 0x3131 && c as u32 <= 0x3163) || (0xAC00 <= c as u32 && c as u32 <= 0xD7A3)
391-
})
392-
});
390+
let english_indicator = text
391+
.split(' ')
392+
.filter(|word| !word.is_empty())
393+
.any(|word| word.chars().any(utils::is_korean_char));
393394

394395
let mut encoder = Encoder::new(english_indicator);
395396
let mut result = Vec::new();
@@ -540,7 +541,7 @@ mod test {
540541
let mut total = 0;
541542
let mut failed = 0;
542543
let mut failed_cases = Vec::new();
543-
let mut file_stats = std::collections::HashMap::new();
544+
let mut file_stats = std::collections::BTreeMap::new();
544545
let files = dir
545546
.map(|entry| entry.unwrap().path())
546547
.filter(|path| path.extension().unwrap_or_default() == "csv")
@@ -587,7 +588,10 @@ mod test {
587588
for (line_num, result) in reader.into_records().enumerate() {
588589
total += 1;
589590
file_total += 1;
590-
let error = format!("CSV 레코드를 읽는 중 오류 발생: {:?} at {}", result, line_num);
591+
let error = format!(
592+
"CSV 레코드를 읽는 중 오류 발생: {:?} at {}",
593+
result, line_num
594+
);
591595
let record = result.expect(&error);
592596
let input = &record[0];
593597
let expected = record[2].replace(" ", "⠀");

libs/braillify/src/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ pub fn has_choseong_o(ch: char) -> bool {
2828
false
2929
}
3030

31+
pub fn is_korean_char(c: char) -> bool {
32+
(c as u32 >= 0x3131 && c as u32 <= 0x3163) || (0xAC00 <= c as u32 && c as u32 <= 0xD7A3)
33+
}
34+
3135
#[cfg(test)]
3236
mod test {
3337
use super::*;

test_cases/rule_33.csv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
"우리나라 기차에는 KTX, 새마을호, 무궁화호 등이 있다.","m""oc""<`@o;<ncz`0,,ktx""`,re<!`ju""`em@m7jvju`i{7o`o/i4",13162191635082148352995305232325304516032231735460263716017138135426392637010425421021121050,⠍⠐⠕⠉⠐⠣⠀⠈⠕⠰⠣⠝⠉⠵⠀⠴⠠⠠⠅⠞⠭⠐⠀⠠⠗⠑⠣⠮⠚⠥⠐⠀⠑⠍⠈⠍⠶⠚⠧⠚⠥⠀⠊⠪⠶⠕⠀⠕⠌⠊⠲
1+
"우리나라 기차에는 KTX, 새마을호, 무궁화호 등이 있다.","M""OC""< @O;<NCZ 0,,KTX"" ,RE<!JU"" EM@M7JVJU I[7O O/I4",1316219163508214835299530523232530451603223173546263716017138135426392637010425421021121050,⠍⠐⠕⠉⠐⠣⠀⠈⠕⠰⠣⠝⠉⠵⠀⠴⠠⠠⠅⠞⠭⠐⠀⠠⠗⠑⠣⠮⠚⠥⠐⠀⠑⠍⠈⠍⠶⠚⠧⠚⠥⠀⠊⠪⠶⠕⠀⠕⠌⠊⠲
22

3-
WHO: 세계 보건 기구,"0,,who""1`,n@/`~u@)`@o@m",52323258192116203229812024378620821813,⠴⠠⠠⠺⠓⠕⠐⠴⠠⠠⠺⠓⠕⠐⠂⠀⠠⠝⠈⠌⠀⠘⠥⠈⠾⠀⠈⠕⠈⠍
3+
WHO: 세계 보건 기구,"0,,who""1`,n@/`~u@)`@o@m",52323258192116203229812024378620821813,⠴⠠⠠⠺⠓⠕⠐⠂⠀⠠⠝⠈⠌⠀⠘⠥⠈⠾⠀⠈⠕⠈⠍
44

5-
"오동근, 1998a, 1998b; 이진영, 2001, p. 109","ui=@z"`#aiih0a1`#aiih;b;2`o.q`}"`#bjja"`0p4`#aji",3710638531606011010195212060110101948348602140310591606032626116052155006012610,⠥⠊⠿⠈⠵⠐⠀⠼⠁⠊⠊⠓⠴⠁⠂⠀⠼⠁⠊⠊⠓⠰⠃⠰⠆⠀⠕⠨⠟⠻⠐⠀⠼⠃⠚⠚⠁⠐⠀⠴⠏⠲⠀⠼⠁⠚⠊
5+
"오동근, 1998a, 1998b; 이진영, 2001, p. 109","UI=@Z"" #AIIH0A1 #AIIH;B;2 O.Q]"" #BJJA" 0P4 #AJI",371063853160601101019521206011010194834860214031591606032626116052155006012610,⠥⠊⠿⠈⠵⠐⠀⠼⠁⠊⠊⠓⠴⠁⠂⠀⠼⠁⠊⠊⠓⠰⠃⠰⠆⠀⠕⠨⠟⠻⠐⠀⠼⠃⠚⠚⠁⠐⠀⠴⠏⠲⠀⠼⠁⠚⠊
66

77
Hedy Lamarr―미국의 여배우이자 와이파이 기술을 발명한 발명가,"0,h$y`,lam>r--eo@maw`:~rmo.`vo`d<o`@o,&!`~1e}j3`~1e}$",52321943610327113282336361721813158049242313214003921025352108213247460242175926180242175943,⠴⠠⠓⠫⠽⠀⠠⠇⠁⠍⠜⠗⠤⠤⠑⠕⠈⠍⠁⠺⠀⠱⠘⠗⠍⠕⠨⠀⠧⠕⠀⠙⠣⠕⠀⠈⠕⠠⠯⠮⠀⠘⠂⠑⠻⠚⠒⠀⠘⠂⠑⠻⠫

test_cases/rule_48.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
원주율은 약 3.14 이다.,^<mr,15184013412538281860950125211050,⠏⠒⠨⠍⠩⠂⠵⠈⠜⠁⠈⠼⠉⠲⠁⠙⠕⠊⠲
1+
원주율은 약 3.14이다.,p3.m%1z >a #c4adoi4,15184013412530281060950125211050,⠏⠒⠨⠍⠩⠂⠵⠀⠜⠁⠀⠼⠉⠲⠁⠙⠕⠊⠲

test_cases/rule_51.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
일시: 2006년 2월 28일 13시,"o1,o""1`#bjjf`c*`#bp1`#bho1`#ac,o",21232211628603262611893386031528603192128601903221,⠕⠂⠠⠕⠐⠂⠼⠃⠚⠚⠋⠈⠉⠡⠈⠼⠃⠏⠂⠼⠃⠓⠕⠂⠼⠁⠉⠠⠕
1+
일시: 2006년 2월 28일 13시,"o1,o""1 #bjjf c* #bp1 #bho1 #ac,o",2123221162060326261109330603152060319212060193221,⠕⠂⠠⠕⠐⠂⠼⠃⠚⠚⠋⠀⠉⠡⠀⠼⠃⠏⠂⠼⠃⠓⠕⠂⠼⠁⠉⠠⠕

test_cases/rule_51_b2.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
오전 10:20,u.)`#aj"1#bj,37406286012616260326,⠥⠨⠾⠼⠁⠚⠐⠂⠼⠃⠚
1+
오전 10:20,U.) #AJ"1#BJ,37406206012616260326,⠥⠨⠾⠼⠁⠚⠐⠂⠼⠃⠚
22

3-
요한 3:16,+j3`#c"1#af,442618860916260111,⠬⠚⠒⠼⠉⠐⠂⠼⠁⠋
3+
요한 3:16,+J3 #C"1#AF,442618060916260111,⠬⠚⠒⠼⠉⠐⠂⠼⠁⠋
44

55
청군:백군,;]@g"1^ra@g,485982716224231827,⠰⠻⠈⠛⠐⠂⠘⠗⠁⠈⠛

test_cases/rule_52.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
강 나루 건너서 / 밀밭길을 // 구름에 달 가듯이 / 가는 나그네,"$7`c""m`@)cs,s`_/`eo1~8@o1!````_/_/`@m""{5n`i1`$i{'o`_/`$cz`c@{`cn",435489161388629143214856128172122438821246888805612561288131642342981028431042421856128439538984280929,⠫⠶⠉⠐⠍⠈⠈⠾⠉⠎⠠⠎⠈⠸⠌⠈⠑⠕⠂⠘⠦⠈⠕⠂⠮⠈⠈⠈⠈⠀⠸⠌⠸⠌⠈⠈⠍⠐⠪⠢⠝⠈⠊⠂⠈⠫⠊⠪⠄⠕⠈⠸⠌⠈⠫⠉⠵⠉⠈⠪⠈⠀⠉⠝
1+
강 나루 건너서 / 밀밭길을 // 구름에 달 가듯이 / 가는 나그네,"$7`c""m`@)cs,s`_/`eo1~8@o1! _/_/`@m""{5n`i1`$i{'o`_/`$cz`c@{cn",435409161308629143214056120172122438821246056125612081316423429010204310424210561204395309842929,⠫⠶⠉⠐⠍⠀⠈⠾⠉⠎⠠⠎⠀⠸⠌⠀⠑⠕⠂⠘⠦⠈⠕⠂⠮⠀⠸⠌⠸⠌⠀⠈⠍⠐⠪⠢⠝⠀⠊⠂⠀⠫⠊⠪⠄⠕⠀⠸⠌⠀⠫⠉⠵⠉⠈⠪⠉⠝
22

3-
먹이다/먹히다,e?oi_/e?joi,1757211056121757262110,⠑⠹⠕⠊⠸⠌⠑⠹⠚⠕⠊
3+
먹이다/먹히다,E?OI_/E?JOI,1757211056121757262110,⠑⠹⠕⠊⠸⠌⠑⠹⠚⠕⠊
44

5-
착한 사람 / 악한 사람,";<aj3`l""<5`_/`<aj3`l""<5",48351261887163534856128351261887163534,⠰⠣⠁⠚⠒⠇⠐⠣⠢⠈⠸⠌⠈⠣⠁⠚⠒⠇⠐⠣⠢
5+
착한 사람 / 악한 사람,";<AJ3 L""<5 _/ <AJ3 L""<5",48351261807163534056120351261807163534,⠰⠣⠁⠚⠒⠇⠐⠣⠢⠀⠸⠌⠀⠣⠁⠚⠒⠇⠐⠣⠢
66

7-
1,000원/개,"#a1jjjp3_/@r,601226262615185612823",⠼⠁⠂⠚⠚⠚⠏⠒⠸⠌⠈⠗
7+
"1,000원/개",#A1JJJP3_/@R,601226262615185612823,⠼⠁⠂⠚⠚⠚⠏⠒⠸⠌⠈⠗

0 commit comments

Comments
 (0)