Skip to content

Commit

Permalink
Merge pull request #8 from aynumosir/fix-edge-cases
Browse files Browse the repository at this point in the history
fix: Fix edge cases for kana converter
  • Loading branch information
neet authored Nov 1, 2024
2 parents 419917a + a6a09d8 commit 1dbc58e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
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

0 comments on commit 1dbc58e

Please sign in to comment.