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: Fix edge cases for kana converter #8

Merged
merged 1 commit into from
Nov 1, 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
11 changes: 8 additions & 3 deletions ainu-utils/src/kana/kana.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::constants::{CONSONANTS, SPECIAL_CONSONANTS, VOWELS};
use super::linking::link;
use super::maps::{TABLE_1, TABLE_2};
use super::symbols::symbols;
use super::symbols::map_symbols;
use unicode_normalization::char::is_combining_mark;
use unicode_normalization::UnicodeNormalization;

Expand All @@ -20,7 +20,7 @@ pub fn to_kana(input: &str) -> String {

input = normalize(input);
input = link(input);
input = symbols(input);
input = map_symbols(input);

let chars: Vec<char> = input.chars().collect();

Expand All @@ -43,7 +43,7 @@ pub fn to_kana(input: &str) -> String {

if CONSONANTS.contains(&current) {
if let Some(&next) = next {
if current == next && current != 'n' {
if current == next && !['n', 'y', 'w'].contains(&current) {
kana.push_str(TABLE_1.get("t").unwrap());
index += 1;
continue;
Expand Down Expand Up @@ -75,6 +75,11 @@ pub fn to_kana(input: &str) -> String {
}
}

if '\'' == current {
index += 1;
continue;
}

kana.push(current);
index += 1;
}
Expand Down
11 changes: 11 additions & 0 deletions ainu-utils/src/kana/kana_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,14 @@ fn test_k_prefix() {
fn test_diacritics() {
assert_eq!(to_kana("kamúy"), "カムイ")
}

#[test]
fn test_yy_and_ww() {
assert_eq!(to_kana("kamuyyukar"), "カムイユカㇻ");
assert_eq!(to_kana("eawwo"), "エアウウォ");
}

#[test]
fn test_glottal_stop() {
assert_eq!(to_kana("hioy'oy"), "ヒオイオイ");
}
5 changes: 2 additions & 3 deletions ainu-utils/src/kana/symbols.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
static SYMBOLS: [(&str, &str); 16] = [
static SYMBOLS: [(&str, &str); 15] = [
("-", ""),
("=", ""),
(" ", " "),
Expand All @@ -13,11 +13,10 @@ static SYMBOLS: [(&str, &str); 16] = [
(".", "。"),
("!", "!"),
("?", "?"),
("'", ""),
("`", ""),
];

pub fn symbols(input: String) -> String {
pub fn map_symbols(input: String) -> String {
let mut input = input;

for (from, to) in SYMBOLS.iter() {
Expand Down
Loading