-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
257: normalize Ð and Đ into d r=ManyTheFish a=ngdbao # Pull Request ## Related issue Fixes issue [#<245>](#245) ## What does this PR do? - Add Vietnamese normalizer ## PR checklist Please check if your PR fulfills the following requirements: - [ x ] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [ x ] Have you read the contributing guidelines? - [ x ] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: ngdbao <[email protected]>
- Loading branch information
Showing
3 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use super::{CharNormalizer, CharOrStr}; | ||
use crate::Script; | ||
use crate::Token; | ||
|
||
pub struct VietnameseNormalizer; | ||
|
||
impl CharNormalizer for VietnameseNormalizer { | ||
fn normalize_char(&self, c: char) -> Option<CharOrStr> { | ||
match c { | ||
'Ð' | 'Đ' | 'đ' => Some("d".to_string().into()), // not only Vietnamese, but also many European countries use these letters | ||
_ => None, | ||
} | ||
} | ||
|
||
fn should_normalize(&self, token: &Token) -> bool { | ||
token.script == Script::Latin && token.lemma.chars().any(is_should_normalize) | ||
} | ||
} | ||
|
||
fn is_should_normalize(c: char) -> bool { | ||
matches!(c, 'Ð' | 'Đ' | 'đ') | ||
} |