Skip to content

Commit fb63d74

Browse files
authored
Merge pull request #7 from aynumosir/kana-release
Prepare kana feature for release
2 parents a2c73e0 + feec0a4 commit fb63d74

File tree

12 files changed

+216
-16
lines changed

12 files changed

+216
-16
lines changed

.github/workflows/python.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
with:
2525
target: x86_64
2626
args: --release --out dist --find-interpreter --manifest-path ./ainu-utils-python/Cargo.toml
27-
# sccache: 'true'
27+
sccache: 'true'
2828
manylinux: auto
2929

3030
- name: pytest

ainu-utils-js/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ainu-utils-js"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2021"
55
description = "A collection of utilities for the Ainu language"
66
license = "MIT"

ainu-utils-python/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ainu-utils-python"
3-
version = "0.2.1"
3+
version = "0.3.0"
44
edition = "2021"
55

66
[lib]

ainu-utils-python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ features = ["pyo3/extension-module"]
99
name = "ainu-utils"
1010
description = "A collection of utility for with the Ainu language"
1111
requires-python = ">=3.8"
12-
version = "0.2.1"
12+
version = "0.3.0"
1313
license = "MIT"
1414

1515
[project.optional-dependencies]

ainu-utils-python/tests/test_tokenize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def test_tokenize():
77

88

99
def test_tokenize_with_whitespace():
10-
result = ainu_utils.segment("irankarapte. e=iwanke ya?", keep_whitespace=True)
10+
result = ainu_utils.tokenize("irankarapte. e=iwanke ya?", keep_whitespace=True)
1111
assert result == ["irankarapte", ".", " ", "e=", "iwanke", " ", "ya", "?"]
1212

1313

ainu-utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ainu-utils"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2021"
55
description = "A collection of utilities for the Ainu language"
66
license = "MIT"

ainu-utils/src/kana/sets.rs renamed to ainu-utils/src/kana/constants.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ pub static VOWELS: Lazy<HashSet<char>> = Lazy::new(|| {
77
});
88

99
pub static CONSONANTS: Lazy<HashSet<char>> = Lazy::new(|| {
10-
let items = ['k', 's', 't', 'c', 'n', 'h', 'p', 'm', 'y', 'r', 'w'];
10+
let items = [
11+
'k', 'g', 's', 'z', 't', 'd', 'c', 'j', 'n', 'h', 'p', 'b', 'f', 'm', 'y', 'r', 'w',
12+
];
1113
items.iter().cloned().collect()
1214
});
1315

ainu-utils/src/kana/kana.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use super::sets::{CONSONANTS, SPECIAL_CONSONANTS, SYMBOLS, VOWELS};
2-
use super::tables::{TABLE_1, TABLE_2, TABLE_3};
1+
use super::constants::{CONSONANTS, SPECIAL_CONSONANTS, SYMBOLS, VOWELS};
2+
use super::linking::link;
3+
use super::maps::{TABLE_1, TABLE_2, TABLE_3};
34
use diacritics::remove_diacritics;
45

5-
fn normalize(input: &str) -> String {
6-
let mut input = input.to_string();
7-
6+
fn normalize(mut input: String) -> String {
87
input = input.to_lowercase();
98
input = input.replace("=", "");
109
input = remove_diacritics(&input).to_string();
@@ -13,7 +12,11 @@ fn normalize(input: &str) -> String {
1312
}
1413

1514
pub fn to_kana(input: &str) -> String {
16-
let input = normalize(input);
15+
let mut input = input.to_string();
16+
17+
input = normalize(input);
18+
input = link(input);
19+
1720
let chars: Vec<char> = input.chars().collect();
1821

1922
let mut kana = String::new();

ainu-utils/src/kana/kana_test.rs

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,134 @@ fn test_to_kana() {
1919
"アシㇼパ エキㇺネ パテㇰ キ ワ、 メノコ モンライケ エアイカㇷ゚。",
2020
"ケメイキ ネ ヤ、 イテセ ネ ヤ、 メノコ モンライケ エアイカㇷ゚ メノコ アナㇰ、 アイヌ ホク コㇿ カ エアイカㇷ゚。",
2121
"タネ シヌイェ クニ パハ ネ コㇿカ、 コパン。",
22-
"スgイモト ニㇱパ、 タン マッカチ エトゥン ワ エンコレ!",
22+
"スギモト ニㇱパ、 タン マッカチ エトゥン ワ エンコレ!",
2323
"タン クミッポホ クエポタラ ワ モシㇼ クホッパ カ コヤイクㇱ。",
2424
].join(" ")
2525
)
2626
}
27+
28+
#[test]
29+
fn test_dropping_h() {
30+
assert_eq!(to_kana("_hine"), "イネ")
31+
}
32+
33+
#[test]
34+
fn test_dropping_y() {
35+
assert_eq!(to_kana("_ya?"), "ア?")
36+
}
37+
38+
#[test]
39+
fn test_linking_h() {
40+
assert_eq!(to_kana("hawean __hi"), "ハウェアニ")
41+
}
42+
43+
#[test]
44+
fn test_linking_y() {
45+
assert_eq!(to_kana("nankor __ya?"), "ナンコラ?")
46+
}
47+
48+
#[test]
49+
fn test_linking_a() {
50+
assert_eq!(to_kana("cis _a cis _a"), "チサ チサ")
51+
}
52+
53+
#[test]
54+
fn test_linking_i() {
55+
assert_eq!(to_kana("oar _isam"), "オアリサㇺ")
56+
}
57+
58+
#[test]
59+
fn test_linking_u() {
60+
assert_eq!(to_kana("or _un"), "オルン")
61+
}
62+
63+
#[test]
64+
fn test_linking_e() {
65+
assert_eq!(to_kana("mat _etun"), "マテトゥン")
66+
}
67+
68+
#[test]
69+
fn test_linking_o() {
70+
assert_eq!(to_kana("pet _or _un"), "ペトルン")
71+
}
72+
73+
#[test]
74+
fn test_linking_and_dropping_a() {
75+
assert_eq!(to_kana("yaypuri ekira __ani"), "ヤイプリ エキラニ")
76+
}
77+
78+
#[test]
79+
fn test_linking_and_dropping_i() {
80+
assert_eq!(to_kana("puni __i"), "プニ")
81+
}
82+
83+
#[test]
84+
fn test_linking_and_dropping_u() {
85+
assert_eq!(to_kana("a=kotanu __un"), "アコタヌン")
86+
}
87+
88+
#[test]
89+
fn test_linking_and_dropping_e() {
90+
assert_eq!(to_kana("i=samake __en anu"), "イサマケン アヌ")
91+
}
92+
93+
#[test]
94+
fn test_linking_and_dropping_o() {
95+
// 実例なし。
96+
assert_eq!(to_kana("sapporo __or"), "サッポロㇿ")
97+
}
98+
99+
#[test]
100+
fn test_linking_r_n() {
101+
assert_eq!(to_kana("a=kor_ nispa"), "アコン ニㇱパ")
102+
}
103+
104+
#[test]
105+
fn test_linking_r_r() {
106+
assert_eq!(to_kana("kor_ rusuy"), "コン ルスイ")
107+
}
108+
109+
#[test]
110+
fn test_linking_r_t() {
111+
assert_eq!(to_kana("or_ ta"), "オッ タ")
112+
}
113+
114+
#[test]
115+
fn test_linking_r_c() {
116+
assert_eq!(to_kana("yar_ cise"), "ヤッ チセ")
117+
}
118+
119+
#[test]
120+
fn test_linking_n_s() {
121+
assert_eq!(to_kana("pon_ su"), "ポイ ス")
122+
}
123+
124+
#[test]
125+
fn test_linking_n_y() {
126+
assert_eq!(to_kana("pon_ yam"), "ポイ ヤㇺ")
127+
}
128+
129+
#[test]
130+
fn test_linking_n_w() {
131+
assert_eq!(to_kana("san _wa"), "サン マ")
132+
}
133+
134+
#[test]
135+
fn test_linking_m_w() {
136+
assert_eq!(to_kana("isam _wa"), "イサン マ")
137+
}
138+
139+
#[test]
140+
fn test_linking_p_w() {
141+
assert_eq!(to_kana("sap _wa"), "サッ パ")
142+
}
143+
144+
#[test]
145+
fn test_special_mp() {
146+
assert_eq!(to_kana("tampaku"), "タンパク")
147+
}
148+
149+
#[test]
150+
fn test_special_mm() {
151+
assert_eq!(to_kana("umma"), "ウンマ")
152+
}

ainu-utils/src/kana/linking.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// https://ainugo.nam.go.jp/pages/guide.html
2+
static LINKING: [(&str, &str); 26] = [
3+
("_h", ""),
4+
("_y", ""),
5+
(" __h", ""),
6+
(" __y", ""),
7+
(" _a", "a"),
8+
(" _i", "i"),
9+
(" _u", "u"),
10+
(" _e", "e"),
11+
(" _o", "o"),
12+
(" __a", ""),
13+
(" __i", ""),
14+
(" __u", ""),
15+
(" __e", ""),
16+
(" __o", ""),
17+
("r_ n", "n n"),
18+
("r_ r", "n r"),
19+
("r_ t", "t t"),
20+
("r_ c", "t c"),
21+
("n_ s", "y s"),
22+
("n_ y", "y y"),
23+
("n_ w", "u w"),
24+
("n _w", "n m"),
25+
// ("n _w", "n m"),
26+
("m _w", "n m"),
27+
("p _w", "t p"),
28+
("mp", "np"),
29+
("mm", "nm"),
30+
];
31+
32+
pub fn link(mut input: String) -> String {
33+
for (from, to) in LINKING.iter() {
34+
input = input.replace(from, to);
35+
}
36+
37+
input
38+
}

0 commit comments

Comments
 (0)