Skip to content
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
47 changes: 42 additions & 5 deletions src/dict/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,13 +1332,50 @@ fn handle_inflection_sense_en(source: Lang, entry: &WordEntry, sense: &Sense, ir
}

fn normalize_orthography(source: Lang, word: &str) -> String {
const ARABIC_DIACRITICS: [char; 16] = [
'\u{0618}', '\u{0619}', '\u{061A}', '\u{064B}', '\u{064C}', '\u{064D}', '\u{064E}',
'\u{064F}', '\u{0650}', '\u{0651}', '\u{0652}', '\u{0653}', '\u{0654}', '\u{0655}',
'\u{0656}', '\u{0670}',
];
match source {
Lang::Grc | Lang::La | Lang::Ru => {
// Normalize to NFD and drop combining accents
word.nfd()
.filter(|c| !('\u{0300}'..='\u{036F}').contains(c))
.collect()
Lang::Ar | Lang::Fa => word
.chars()
.filter(|c| !ARABIC_DIACRITICS.contains(c))
.collect(),
Lang::La | Lang::Ang | Lang::Sga | Lang::Grc | Lang::Ro | Lang::It | Lang::Id => word
.nfd()
.filter(|c| !('\u{0300}'..='\u{036F}').contains(c))
.collect::<String>()
.nfc()
.collect(),
Lang::Tl => word
.nfd()
.filter(|c| !('\u{0300}'..='\u{036F}').contains(c) && *c != '-' && *c != '\'')
.collect::<String>()
.nfc()
.collect(),
Lang::Sh => {
let mut last_base: Option<char> = None;
let filtered: String = word
.nfd()
.filter(|&c| {
if ('\u{0300}'..='\u{036F}').contains(&c) {
!matches!(
last_base,
Some(
'a' | 'e' | 'i' | 'o' | 'u' | 'r' | 'A' | 'E' | 'I' | 'O'
| 'U' | 'R'
)
)
} else {
last_base = Some(c);
true
}
})
.collect();
filtered.nfc().collect()
}
Lang::Uk | Lang::Ru => word.replace('\u{0301}', ""),
_ => word.to_string(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/dict/fa/en/temp-main/dict/term_bank_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
""
],
[
"پارسی",
"پارْسی",
"",
"non-lemma",
"",
0,
Expand Down
16 changes: 8 additions & 8 deletions tests/dict/ru/en/temp-main/dict/term_bank_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
""
],
[
"снежныи",
"снежный",
"сне́жный",
"non-lemma",
"",
Expand All @@ -74,7 +74,7 @@
""
],
[
"снеговои",
"снеговой",
"снегово́й",
"non-lemma",
"",
Expand Down Expand Up @@ -284,8 +284,8 @@
""
],
[
"простынеи",
"простынёй",
"",
"non-lemma",
"",
0,
Expand Down Expand Up @@ -335,7 +335,7 @@
""
],
[
"побелевшии",
"побелевший",
"побеле́вший",
"non-lemma",
"",
Expand Down Expand Up @@ -488,7 +488,7 @@
""
],
[
"побелеи",
"побелей",
"побеле́й",
"non-lemma",
"",
Expand All @@ -505,7 +505,7 @@
""
],
[
"побелеите",
"побелейте",
"побеле́йте",
"non-lemma",
"",
Expand Down Expand Up @@ -642,7 +642,7 @@
""
],
[
"зимнии",
"зимний",
"зи́мний",
"non-lemma",
"",
Expand Down Expand Up @@ -751,7 +751,7 @@
""
],
[
"зимнеи",
"зимней",
"зи́мней",
"non-lemma",
"",
Expand Down
10 changes: 5 additions & 5 deletions tests/dict/ru/ru/temp-main/dict/term_bank_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@
""
],
[
"продолжаи",
"продолжай",
"продолжа́й",
"non-lemma",
"",
Expand All @@ -363,7 +363,7 @@
""
],
[
"продолжаите",
"продолжайте",
"продолжа́йте",
"non-lemma",
"",
Expand All @@ -380,7 +380,7 @@
""
],
[
"продолжающии",
"продолжающий",
"продолжа́ющий",
"non-lemma",
"",
Expand All @@ -397,7 +397,7 @@
""
],
[
"продолжавшии",
"продолжавший",
"продолжа́вший",
"non-lemma",
"",
Expand All @@ -414,7 +414,7 @@
""
],
[
"продолжаемыи",
"продолжаемый",
"продолжа́емый",
"non-lemma",
"",
Expand Down