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

fix(data): Default dictionary fixes #615

Merged
merged 2 commits into from
Jul 15, 2024
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
52 changes: 23 additions & 29 deletions data/tsi.src
Original file line number Diff line number Diff line change
Expand Up @@ -9010,7 +9010,7 @@
亞洲國家 259 ㄧㄚˇ ㄓㄡ ㄍㄨㄛˊ ㄐㄧㄚ
亞洲地區 373 ㄧㄚˇ ㄓㄡ ㄉㄧˋ ㄑㄩ
亞洲大學 1 ㄧㄚˇ ㄓㄡ ㄉㄚˋ ㄒㄩㄝˊ
亞洲杯 13 ㄧㄚˇ ㄓㄡ ㄅㄟ
亞洲盃 13 ㄧㄚˇ ㄓㄡ ㄅㄟ
亞洲運動會 1 ㄧㄚˋ ㄓㄡ ㄩㄣˋ ㄉㄨㄥˋ ㄏㄨㄟˋ
亞熱帶 150 ㄧㄚˇ ㄖㄜˋ ㄉㄞˋ
亞熱帶地區 25 ㄧㄚˇ ㄖㄜˋ ㄉㄞˋ ㄉㄧˋ ㄑㄩ
Expand Down Expand Up @@ -11941,7 +11941,7 @@
供應國 38 ㄍㄨㄥ ㄧㄥˋ ㄍㄨㄛˊ
供應地 6 ㄍㄨㄥ ㄧㄥˋ ㄉㄧˋ
供應站 83 ㄍㄨㄥ ㄧㄥˋ ㄓㄢˋ
供應鍊 100 ㄍㄨㄥ ㄧㄥˋ ㄌㄧㄢˋ
供應鏈 100 ㄍㄨㄥ ㄧㄥˋ ㄌㄧㄢˋ
供暖 1 ㄍㄨㄥˋ ㄋㄨㄢˇ
供暖系統 0 ㄍㄨㄥˋ ㄋㄨㄢˇ ㄒㄧˋ ㄊㄨㄥˇ
供桌 19 ㄍㄨㄥˋ ㄓㄨㄛ
Expand Down Expand Up @@ -23526,7 +23526,6 @@
十萬分 14 ㄕˊ ㄨㄢˋ ㄈㄣˋ
十萬塊 1 ㄕˊ ㄨㄢˋ ㄎㄨㄞˋ
十萬火急 41 ㄕˊ ㄨㄢˋ ㄏㄨㄛˇ ㄐㄧˊ
十葉 1 ㄕˊ ㄧㄝˋ
十處 28 ㄕˊ ㄔㄨˋ
十號 277 ㄕˊ ㄏㄠˋ
十行 23 ㄕˊ ㄏㄤˊ
Expand Down Expand Up @@ -38970,6 +38969,7 @@
失傳 69 ㄕ ㄔㄨㄢˊ
失儀 3 ㄕ ㄧˊ
失利 248 ㄕ ㄌㄧˋ
失聯 0 ㄕ ㄌㄧㄢˊ
失勢 12 ㄕ ㄕˋ
失卻 13 ㄕ ㄑㄩㄝˋ
失去 2330 ㄕ ㄑㄩˋ
Expand Down Expand Up @@ -45040,7 +45040,6 @@
對帳 22 ㄉㄨㄟˋ ㄓㄤˋ
對待 589 ㄉㄨㄟˋ ㄉㄞˋ
對得起 53 ㄉㄨㄟˋ ㄉㄜ˙ ㄑㄧˇ
對心 32 ㄉㄨㄟˋ ㄒㄧㄣ
對應 710 ㄉㄨㄟˋ ㄧㄥˋ
對應性 2 ㄉㄨㄟˋ ㄧㄥˋ ㄒㄧㄥˋ
對成 31 ㄉㄨㄟˋ ㄔㄥˊ
Expand Down Expand Up @@ -52662,7 +52661,7 @@
復旦大學 61 ㄈㄨˋ ㄉㄢˋ ㄉㄚˋ ㄒㄩㄝˊ
復旦橋 2 ㄈㄨˋ ㄉㄢˋ ㄑㄧㄠˊ
復明 14 ㄈㄨˋ ㄇㄧㄥˊ
復查 94 ㄈㄨˋ ㄔㄚˊ
復查 148 ㄈㄨˋ ㄔㄚˊ
復校 62 ㄈㄨˋ ㄐㄧㄠˋ
復業 55 ㄈㄨˋ ㄧㄝˋ
復檢 0 ㄈㄨˋ ㄐㄧㄢˇ
Expand Down Expand Up @@ -52937,7 +52936,7 @@
徹夜 78 ㄔㄜˋ ㄧㄝˋ
徹夜不眠 7 ㄔㄜˋ ㄧㄝˋ ㄅㄨˋ ㄇㄧㄢˊ
徹夜進行 0 ㄔㄜˋ ㄧㄝˋ ㄐㄧㄣˋ ㄒㄧㄥˊ
徹底 1538 ㄔㄜˋ ㄉㄧˇ
徹底 108 ㄔㄜˋ ㄉㄧˇ
徹底性 1 ㄔㄜˋ ㄉㄧˇ ㄒㄧㄥˋ
徹底清除 21 ㄔㄜˋ ㄉㄧˇ ㄑㄧㄥ ㄔㄨˊ
徹底澄清 0 ㄔㄜˋ ㄉㄧˇ ㄔㄥˊ ㄑㄧㄥ
Expand Down Expand Up @@ -59275,7 +59274,6 @@
抄手 16 ㄔㄠ ㄕㄡˇ
抄抄 8 ㄔㄠ ㄔㄠ
抄書 5 ㄔㄠ ㄕㄨ
抄有 1 ㄔㄠ ㄧㄡˇ
抄本 61 ㄔㄠ ㄅㄣˇ
抄沒 2 ㄔㄠ ㄇㄛˋ
抄獲 1 ㄔㄠ ㄏㄨㄛˋ
Expand Down Expand Up @@ -60096,7 +60094,7 @@
抽汽 3 ㄔㄡ ㄑㄧˋ
抽油煙機 19 ㄔㄡ ㄧㄡˊ ㄧㄢ ㄐㄧ
抽泣 8 ㄔㄡ ㄑㄧˋ
抽煙 319 ㄔㄡ ㄧㄢ
抽煙 0 ㄔㄡ ㄧㄢ
抽煙室 0 ㄔㄡ ㄧㄢ ㄕˋ
抽獎 653 ㄔㄡ ㄐㄧㄤˇ
抽皺 0 ㄔㄡ ㄓㄡˋ
Expand All @@ -60119,7 +60117,7 @@
抽考 7 ㄔㄡ ㄎㄠˇ
抽脂 0 ㄔㄡ ㄓ
抽芽 3 ㄔㄡ ㄧㄚˊ
抽菸 0 ㄔㄡ ㄧㄢ
抽菸 319 ㄔㄡ ㄧㄢ
抽血 0 ㄔㄡ ㄒㄧㄝˇ
抽調 23 ㄔㄡ ㄉㄧㄠˋ
抽象 367 ㄔㄡ ㄒㄧㄤˋ
Expand Down Expand Up @@ -61134,6 +61132,7 @@
拼拼看 3 ㄆㄧㄣ ㄆㄧㄣ ㄎㄢˋ
拼會 0 ㄆㄧㄣ ㄏㄨㄟˋ
拼死 14 ㄆㄧㄣ ㄙˇ
拼死 14 ㄆㄢˋ ㄙˇ
拼死拼活 3 ㄆㄧㄣ ㄙˇ ㄆㄧㄣ ㄏㄨㄛˊ
拼法 31 ㄆㄧㄣ ㄈㄚˇ
拼湊 56 ㄆㄧㄣ ㄘㄡˋ
Expand Down Expand Up @@ -64595,7 +64594,6 @@
摩托化 0 ㄇㄛˊ ㄊㄨㄛ ㄏㄨㄚˋ
摩托船 1 ㄇㄛˊ ㄊㄨㄛ ㄔㄨㄢˊ
摩托車 20 ㄇㄛˊ ㄊㄨㄛ ㄔㄜ
摩拖車 20 ㄇㄛˊ ㄊㄨㄛ ㄔㄜ
摩拳擦掌 23 ㄇㄛˊ ㄑㄩㄢˊ ㄘㄚ ㄓㄤˇ
摩挲 3 ㄇㄛˊ ㄙㄨㄛ
摩搓 2 ㄇㄛˊ ㄘㄨㄛ
Expand Down Expand Up @@ -65114,7 +65112,7 @@
撫弄 18 ㄈㄨˇ ㄋㄨㄥˋ
撫心 2 ㄈㄨˇ ㄒㄧㄣ
撫恤 26 ㄈㄨˇ ㄒㄩˋ
撫恤金 11 ㄈㄨˇ ㄒㄩˋ ㄐㄧㄣ
撫卹金 11 ㄈㄨˇ ㄒㄩˋ ㄐㄧㄣ
撫愛 1 ㄈㄨˇ ㄞˋ
撫慰 122 ㄈㄨˇ ㄨㄟˋ
撫摩 2 ㄈㄨˇ ㄇㄛˊ
Expand Down Expand Up @@ -81453,7 +81451,7 @@
水銀槽 3 ㄕㄨㄟˇ ㄧㄣˊ ㄘㄠˊ
水銀燈 11 ㄕㄨㄟˇ ㄧㄣˊ ㄉㄥ
水銀計 0 ㄕㄨㄟˇ ㄧㄣˊ ㄐㄧˋ
水錶 27 ㄕㄨㄟˇ ㄅㄧㄠˇ
水錶 26 ㄕㄨㄟˇ ㄅㄧㄠˇ
水門 44 ㄕㄨㄟˇ ㄇㄣˊ
水門事件 6 ㄕㄨㄟˇ ㄇㄣˊ ㄕˋ ㄐㄧㄢˋ
水門案 19 ㄕㄨㄟˇ ㄇㄣˊ ㄢˋ
Expand Down Expand Up @@ -85730,7 +85728,6 @@
添上 23 ㄊㄧㄢ ㄕㄤˋ
添上來 0 ㄊㄧㄢ ㄕㄤˋ ㄌㄞˊ
添上去 0 ㄊㄧㄢ ㄕㄤˋ ㄑㄩˋ
添了 34 ㄊㄧㄢ ㄌㄜ˙
添些 3 ㄊㄧㄢ ㄒㄧㄝ
添來添去 0 ㄊㄧㄢ ㄌㄞˊ ㄊㄧㄢ ㄑㄩˋ
添個 7 ㄊㄧㄢ ㄍㄜ˙
Expand Down Expand Up @@ -88200,7 +88197,7 @@
澇 55 ㄌㄠˊ
澇災 10 ㄌㄠˊ ㄗㄞ
澈 278 ㄔㄜˋ
澈底 108 ㄔㄜˋ ㄉㄧˇ
澈底 1538 ㄔㄜˋ ㄉㄧˇ
澈悟 0 ㄔㄜˋ ㄨˋ
澉 0 ㄍㄢˇ
澊 0 ㄘㄨㄣ
Expand Down Expand Up @@ -96648,9 +96645,9 @@
番禺 8 ㄆㄢ ㄩˊ
番紅花 4 ㄈㄢ ㄏㄨㄥˊ ㄏㄨㄚ
番紅花色 0 ㄈㄢ ㄏㄨㄥˊ ㄏㄨㄚ ㄙㄜˋ
番茄 131 ㄈㄢ ㄑㄧㄝˊ
番茄汁 1 ㄈㄢ ㄑㄧㄝˊ ㄓ
番茄醬 12 ㄈㄢ ㄑㄧㄝˊ ㄐㄧㄤˋ
番茄 195 ㄈㄢ ㄑㄧㄝˊ
番茄汁 195 ㄈㄢ ㄑㄧㄝˊ ㄓ
番茄醬 28 ㄈㄢ ㄑㄧㄝˊ ㄐㄧㄤˋ
番薯 63 ㄈㄢ ㄕㄨˇ
番藷 0 ㄈㄢ ㄕㄨˇ
番號 35 ㄈㄢ ㄏㄠˋ
Expand Down Expand Up @@ -109582,7 +109579,7 @@
絥 0 ㄈㄨˊ
給 3677 ㄐㄧˇ
給 36776 ㄍㄟˇ
給予 3464 ㄍㄟˇ ㄩˇ
給予 428 ㄍㄟˇ ㄩˇ
給人 639 ㄍㄟˇ ㄖㄣˊ
給人以 9 ㄍㄟˇ ㄖㄣˊ ㄧˇ
給付 2064 ㄐㄧˇ ㄈㄨˋ
Expand All @@ -109596,7 +109593,7 @@
給水箱 0 ㄍㄟˇ ㄕㄨㄟˇ ㄒㄧㄤ
給獎 49 ㄍㄟˇ ㄐㄧㄤˇ
給糧 1 ㄍㄟˇ ㄌㄧㄤˊ
給與 428 ㄍㄟˇ ㄩˇ
給與 3464 ㄍㄟˇ ㄩˇ
給足 10 ㄍㄟˇ ㄗㄨˊ
給錢 31 ㄍㄟˇ ㄑㄧㄢˊ
絧 8 ㄊㄨㄥˊ
Expand Down Expand Up @@ -115342,7 +115339,6 @@
能讀能聽 1 ㄋㄥˊ ㄉㄨˊ ㄋㄥˊ ㄊㄧㄥ
能讀能說 0 ㄋㄥˊ ㄉㄨˊ ㄋㄥˊ ㄕㄨㄛ
能讀能講 0 ㄋㄥˊ ㄉㄨˊ ㄋㄥˊ ㄐㄧㄤˇ
能趕 20 ㄋㄥˊ ㄍㄢˇ
能跑 54 ㄋㄥˊ ㄆㄠˇ
能跑能跳 0 ㄋㄥˊ ㄆㄠˇ ㄋㄥˊ ㄊㄧㄠˋ
能退 9 ㄋㄥˊ ㄊㄨㄟˋ
Expand Down Expand Up @@ -121267,8 +121263,8 @@
蕃庶 0 ㄈㄢˊ ㄕㄨˋ
蕃殖 1 ㄈㄢˊ ㄓˊ
蕃茂 0 ㄈㄢˊ ㄇㄠˋ
蕃茄 195 ㄈㄢ ㄑㄧㄝˊ
蕃茄汁 195 ㄈㄢ ㄑㄧㄝˊ ㄓ
蕃茄 131 ㄈㄢ ㄑㄧㄝˊ
蕃茄汁 131 ㄈㄢ ㄑㄧㄝˊ ㄓ
蕃茄片 4 ㄈㄢ ㄑㄧㄝˊ ㄆㄧㄢˋ
蕃茄醬 27 ㄈㄢ ㄑㄧㄝˊ ㄐㄧㄤˋ
蕃薯 11133 ㄈㄢ ㄕㄨˇ
Expand Down Expand Up @@ -121698,7 +121694,6 @@
藍綠藻 12 ㄌㄢˊ ㄌㄩˋ ㄗㄠˇ
藍腹鷳 1 ㄌㄢˊ ㄈㄨˋ ㄒㄧㄢˊ
藍色 2017 ㄌㄢˊ ㄙㄜˋ
藍芽 0 ㄌㄢˊ ㄧㄚˊ
藍莓 32 ㄌㄢˊ ㄇㄟˊ
藍藍 81 ㄌㄢˊ ㄌㄢˊ
藍藻 45 ㄌㄢˊ ㄗㄠˇ
Expand Down Expand Up @@ -123009,7 +123004,7 @@
蜺 12 ㄋㄧˊ
蜻 58 ㄑㄧㄥ
蜻蛉 20 ㄑㄧㄥ ㄌㄧㄥˊ
蜻蜓 99 ㄑㄧㄥ ㄊㄧㄥˊ
蜻蜓 140 ㄑㄧㄥ ㄊㄧㄥˊ
蜻蜓點水 21 ㄑㄧㄥ ㄊㄧㄥˊ ㄉㄧㄢˇ ㄕㄨㄟˇ
蜼 1 ㄌㄟˇ
蜼 13 ㄨㄟˋ
Expand Down Expand Up @@ -125204,7 +125199,7 @@
複數 125 ㄈㄨˋ ㄕㄨˋ
複數形 2 ㄈㄨˋ ㄕㄨˋ ㄒㄧㄥˊ
複本 113 ㄈㄨˋ ㄅㄣˇ
複查 148 ㄈㄨˋ ㄔㄚˊ
複查 94 ㄈㄨˋ ㄔㄚˊ
複核 57 ㄈㄨˋ ㄏㄜˊ
複檢 158 ㄈㄨˋ ㄐㄧㄢˇ
複次 0 ㄈㄨˋ ㄘˋ
Expand Down Expand Up @@ -148582,7 +148577,7 @@
電蚊拍 10 ㄉㄧㄢˋ ㄨㄣˊ ㄆㄞ
電蚊香 10 ㄉㄧㄢˋ ㄨㄣˊ ㄒㄧㄤ
電衝 0 ㄉㄧㄢˋ ㄔㄨㄥ
電表 126 ㄉㄧㄢˋ ㄅㄧㄠˇ
電表 170 ㄉㄧㄢˋ ㄅㄧㄠˇ
電覆 0 ㄉㄧㄢˋ ㄈㄨˋ
電視 6092 ㄉㄧㄢˋ ㄕˋ
電視公司 99 ㄉㄧㄢˋ ㄕˋ ㄍㄨㄥ ㄙ
Expand Down Expand Up @@ -148643,7 +148638,7 @@
電鈴 24 ㄉㄧㄢˋ ㄌㄧㄥˊ
電銲 23 ㄉㄧㄢˋ ㄏㄢˋ
電鋸 17 ㄉㄧㄢˋ ㄐㄩˋ
電錶 170 ㄉㄧㄢˋ ㄅㄧㄠˇ
電錶 126 ㄉㄧㄢˋ ㄅㄧㄠˇ
電鍋 46 ㄉㄧㄢˋ ㄍㄨㄛ
電鍋爐 0 ㄉㄧㄢˋ ㄍㄨㄛ ㄌㄨˊ
電鍍 435 ㄉㄧㄢˋ ㄉㄨˋ
Expand Down Expand Up @@ -152647,7 +152642,7 @@
香草精 1 ㄒㄧㄤ ㄘㄠˇ ㄐㄧㄥ
香菇 324 ㄒㄧㄤ ㄍㄨ
香菜 38 ㄒㄧㄤ ㄘㄞˋ
香菸 110 ㄒㄧㄤ ㄧㄢ
香菸 180 ㄒㄧㄤ ㄧㄢ
香蕈 1 ㄒㄧㄤ ㄒㄩㄣˋ
香蕉 478 ㄒㄧㄤ ㄐㄧㄠ
香蕉冰 10 ㄒㄧㄤ ㄐㄧㄠ ㄅㄧㄥ
Expand Down Expand Up @@ -156724,7 +156719,6 @@
黏上來 0 ㄋㄧㄢˊ ㄕㄤˋ ㄌㄞˊ
黏上去 0 ㄋㄧㄢˊ ㄕㄤˋ ㄑㄩˋ
黏下去 0 ㄋㄧㄢˊ ㄒㄧㄚˋ ㄑㄩˋ
黏了 1 ㄋㄧㄢˊ ㄌㄜ˙
黏人 12 ㄋㄧㄢˊ ㄖㄣˊ
黏住 16 ㄋㄧㄢˊ ㄓㄨˋ
黏來黏去 0 ㄋㄧㄢˊ ㄌㄞˊ ㄋㄧㄢˊ ㄑㄩˋ
Expand Down
31 changes: 21 additions & 10 deletions tools/src/init_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,26 @@ use crate::flags;
#[derive(Debug)]
struct ParseError {
line_num: usize,
line: String,
source: anyhow::Error,
}

fn parse_error(line_num: usize) -> ParseError {
fn parse_error(line_num: usize, line: &str) -> ParseError {
ParseError {
line_num,
line: line.to_string(),
source: anyhow::anyhow!("Invalid format. Use the --csv flag to enable CSV parsing."),
}
}

impl Display for ParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Parsing failed at line {}", self.line_num + 1)
write!(
f,
"Parsing failed at line {}: {}",
self.line_num + 1,
self.line
)
}
}

Expand All @@ -39,12 +46,16 @@ impl Error for ParseError {
}

trait IntoParseError<T> {
fn parse_error(self, line_num: usize) -> std::result::Result<T, ParseError>;
fn parse_error(self, line_num: usize, line: &str) -> std::result::Result<T, ParseError>;
}

impl<T> IntoParseError<T> for Result<T> {
fn parse_error(self, line_num: usize) -> std::result::Result<T, ParseError> {
self.map_err(|source| ParseError { line_num, source })
fn parse_error(self, line_num: usize, line: &str) -> std::result::Result<T, ParseError> {
self.map_err(|source| ParseError {
line_num,
line: line.to_string(),
source,
})
}
}

Expand Down Expand Up @@ -115,19 +126,19 @@ fn parse_line(
let phrase = line
.split(delimiter)
.next()
.ok_or(parse_error(line_num))?
.ok_or(parse_error(line_num, line))?
.trim_matches('"');

let freq: u32 = match phrase.chars().count() {
1 if !keep_word_freq => 0,
_ => line
.split(delimiter)
.nth(1)
.ok_or(parse_error(line_num))?
.ok_or(parse_error(line_num, line))?
.trim_matches('"')
.parse()
.context("Unable to parse frequency")
.parse_error(line_num)?,
.parse_error(line_num, line)?,
};

let mut syllables = vec![];
Expand All @@ -146,10 +157,10 @@ fn parse_line(
.insert(
Bopomofo::try_from(c)
.context("parsing bopomofo")
.parse_error(line_num)?,
.parse_error(line_num, line)?,
)
.with_context(|| format!("Parsing syllables {}", syllable_str))
.parse_error(line_num)?;
.parse_error(line_num, line)?;
}
syllables.push(syllable_builder.build());
}
Expand Down
Loading