use crate::Normalizer;
pub fn free_text() -> Normalizer {
Normalizer::new()
.newline_unify()
.invisible_remove()
.kana_fullwidth()
.ascii_halfwidth()
.space_unify()
.space_collapse()
.newline_collapse()
.trim_lines()
}
pub fn search_key() -> Normalizer {
Normalizer::new()
.invisible_remove()
.kana_fullwidth()
.ascii_halfwidth()
.ascii_lowercase()
.hyphen_unify()
.prolonged_sound_collapse()
.space_unify()
.space_collapse()
.ja_space_remove_aggressive()
.trim_lines()
}
pub fn neologdn() -> Normalizer {
Normalizer::new()
.with_replacements(&[("“", "\""), ("”", "\""), ("’", "'"), ("‘", "`")])
.kana_fullwidth()
.tilde_remove()
.hyphen_unify()
.ascii_halfwidth()
.space_unify()
.space_collapse()
.ja_space_remove_aggressive()
.prolonged_sound_collapse()
.trim_lines()
}
pub fn neologdn_keep_spaces() -> Normalizer {
Normalizer::new()
.with_replacements(&[("“", "\""), ("”", "\""), ("’", "'"), ("‘", "`")])
.kana_fullwidth()
.tilde_remove()
.hyphen_unify()
.ascii_halfwidth()
.space_unify()
.space_collapse()
.prolonged_sound_collapse()
.trim_lines()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn free_text_basic() {
let n = free_text();
assert_eq!(n.apply("123\u{3000}ABC\r\nガギ "), "123 ABC\nガギ");
}
#[test]
fn search_key_folding() {
let n = search_key();
assert_eq!(n.apply("Rust 入門\u{3000}ガイド"), "rust入門ガイド");
}
#[test]
fn neologdn_readme_examples() {
let n = neologdn();
assert_eq!(n.apply("PRML 副 読 本"), "PRML副読本");
assert_eq!(n.apply("Coding the Matrix"), "Coding the Matrix");
assert_eq!(
n.apply("南アルプスの 天然水 スパークリング レモン レモン一絞り"),
"南アルプスの天然水スパークリングレモンレモン一絞り"
);
assert_eq!(n.apply("検索 エンジン 自作 入門 を 買いました!!!"),
"検索エンジン自作入門を買いました!!!");
}
#[test]
fn neologdn_symbols() {
let n = neologdn();
assert_eq!(n.apply("スーパーーーー"), "スーパー");
assert_eq!(n.apply("お~い"), "おい");
}
}