Skip to content
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
70 changes: 28 additions & 42 deletions Rules/Languages/ja/ClearSpeak_Rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,25 +252,20 @@
- bookmark: "*[2]/@id"
- test:
if: "*[2][.='2']"
then: [t: "スクエア"] # phrase(25 equals 5 'squared')
else: [t: "キューブド"] # phrase(625 equals 5 'cubed')
then: [t: "の 2 乗"] # phrase(25 equals 5 'squared')
else: [t: "の 3 乗"] # phrase(625 equals 5 'cubed')

- name: function-power
tag: power
match:
- "following-sibling::*[1][self::m:mo][.='⁡']" #invisible function apply
replace:
- test:
if: "$Verbosity!='Terse'"
then: [ot: ""] # phrase('the' third power of 2)
- x: "*[1]"
- t: "の" # phrase(the third 'power of' 6)
- bookmark: "*[2]/@id"
- test:
if: "*[2][self::m:mn][not(contains(., '.'))]"
then: [x: "ToOrdinal(*[2])"]
else: [x: "*[2]"]
- t: "パワーの" # phrase(the third 'power of' 6)
- x: "*[2]"
- t: "乗" # phrase(the third 'power of' 6)
- pause: short
- x: "*[1]"

- name: AfterPower-nested
tag: power
Expand All @@ -279,19 +274,20 @@
- "*[2][self::m:power or self::m:power or self::m:mrow[m:power]]"
replace:
- x: "*[1]"
- t: "緊急事態に育つ" # phrase(5 'raised to the exponent' x plus 1)
- t: "の上付き" # phrase(5 'raised to the exponent' x plus 1)
- pause: short
- x: "*[2]"
- pause: short
- t: "エンド指数" # phrase(5 raised to the exponent x plus 1 'end exponent')
- t: "上付き終了" # phrase(5 raised to the exponent x plus 1 'end exponent')

- name: AfterPower-default
tag: power
match: "$ClearSpeak_Exponents = 'AfterPower'"
replace:
- x: "*[1]"
- t: "力に育つ" # phrase(x is 'raised to the power' 4)
- t: "" # phrase(x is 'raised to the power' 4)
- x: "*[2]"
- t: "乗" # phrase(x is raised to the 'power' 4)
- pause: short

- name: squared
Expand All @@ -300,29 +296,24 @@
replace:
- x: "*[1]"
- bookmark: "*[2]/@id"
- t: "スクエア" # phrase(7 'squared' equals 49)
- t: "の 2 乗" # phrase(7 'squared' equals 49)

- name: cubed
tag: power
match: "*[2][self::m:mn][.='3'] and $ClearSpeak_Exponents = 'Auto'"
replace:
- x: "*[1]"
- bookmark: "*[2]/@id"
- t: "キューブド" # phrase(5 'cubed' equals 125)
- t: "の 3 乗" # phrase(5 'cubed' equals 125)

- name: simple-integer
tag: power
match: "*[2][self::m:mn][not(contains(., '.'))]"
replace:
- x: "*[1]"
- t: "の" # phrase(2 raised 'to the' power 7)
- test:
if: "*[2][.>0]"
then: [x: "ToOrdinal(*[2])"]
else: [x: "*[2]"]
- test:
if: "$ClearSpeak_Exponents != 'Ordinal'"
then: [t: "パワー"] # phrase(2 raised to the 'power' 7)
- x: "*[2]"
- t: "乗" # phrase(2 raised to the 'power' 7)

- name: simple-negative-integer
tag: power
Expand All @@ -334,9 +325,7 @@
- x: "*[1]"
- t: "の" # phrase(2 raised 'to the' power 7)
- x: "*[2]"
- test:
if: "$ClearSpeak_Exponents != 'Ordinal'"
then: [t: "パワー"] # phrase(2 raised to the 'power' 7)
- t: "乗" # phrase(2 raised to the 'power' 7)

- name: simple-var
tag: power
Expand All @@ -345,10 +334,7 @@
- x: "*[1]"
- t: "の" # phrase(3 raised 'to the' power 7)
- x: "*[2]"
- pronounce: [text: "-th", ipa: "θ", sapi5: "th", eloquence: "T"]
- test:
if: "$ClearSpeak_Exponents != 'Ordinal'"
then: [t: "パワー"] # phrase(2 raised to the 'power' 7)
- t: "乗" # phrase(2 raised to the 'power' 7)

# match nested exponent, where the nested exponent is has the power 2 or 3 (n below)
# [xxx]^n, - [xxx]^n, [xxx] var^n, -[xxx] var^n
Expand All @@ -373,9 +359,9 @@
- " ]"
replace:
- x: "*[1]"
- t: "に上げられた" # phrase(x 'raised to the' second power)
- t: "の上付き" # phrase(x 'raised to the' second power)
- x: "*[2]"
- t: "パワー" # phrase(x raised to the second 'power')
- t: "上付き終了" # phrase(x raised to the second 'power')

- # - [xxx]^n
name: nested-negative-squared-or-cubed
Expand All @@ -394,9 +380,9 @@
- " ]"
replace:
- x: "*[1]"
- t: "に上げられた" # phrase(x 'raised to the' second power)
- t: "の上付き" # phrase(x 'raised to the' second power)
- x: "*[2]"
- t: "パワー" # phrase(x raised to the second 'power')
- t: "上付き終了" # phrase(x raised to the second 'power')

- # [xxx] var^n
name: nested-var-squared-or-cubed
Expand All @@ -417,9 +403,9 @@
- " ]"
replace:
- x: "*[1]"
- t: "に上げられた" # phrase(x 'raised to the' second power)
- t: "の上付き" # phrase(x 'raised to the' second power)
- x: "*[2]"
- t: "パワー" # phrase(x raised to the second 'power')
- t: "上付き終了" # phrase(x raised to the second 'power')

- # -[xxx] var^n
name: nested-negative-var-squared-or-cubed
Expand All @@ -442,30 +428,30 @@
- " ]"
replace:
- x: "*[1]"
- t: "に上げられた" # phrase(x 'raised to the' second power)
- t: "の上付き" # phrase(x 'raised to the' second power)
- x: "*[2]"
- t: "パワー" # phrase(x raised to the second 'power')
- t: "上付き終了" # phrase(x raised to the second 'power')

- name: default-exponent-power
tag: power
match: # directly a superscript or an mrow that contains a superscript
- "*[2][self::m:power or self::m:power or self::m:mrow[m:power]]"
replace:
- x: "*[1]"
- t: "緊急事態に育つ" # phrase(x is 'raised to the exponent')
- t: "の上付き" # phrase(x is 'raised to the exponent')
- pause: short
- x: "*[2]"
- pause: short
- t: "エンド指数" # phrase(and now 'end exponent' has been reached)
- t: "上付き終了" # phrase(and now 'end exponent' has been reached)

- name: default
tag: power
match: "."
replace:
- x: "*[1]"
- t: "に上げられた" # phrase(x 'raised to the' second power)
- t: "の上付き" # phrase(x 'raised to the' second power)
- x: "*[2]"
- t: "パワー" # phrase(x raised to the second 'power')
- t: "上付き終了" # phrase(x raised to the second 'power')

#
# Some rules on mrows
Expand Down
41 changes: 19 additions & 22 deletions Rules/Languages/ja/SimpleSpeak_Rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,19 @@
- bookmark: "*[2]/@id"
- test:
if: "*[2][.=2]"
then: [t: "スクエア"] # phrase(5 'squared' equals 25)
else: [t: "キューブド"] # phrase(5 'cubed' equals 125)
then: [t: "の 2 乗"] # phrase(5 'squared' equals 25)
else: [t: "の 3 乗"] # phrase(5 'cubed' equals 125)
- name: function-power
tag: power
match:
- "following-sibling::*[1][self::m:mo][.='⁡']" #invisible function apply
replace:
- test:
if: "$Verbosity!='Terse'"
then: [ot: ""] # # phrase('the' fourth power of 10)
- x: "*[1]"
- t: "の" # phrase(the fourth 'power of' 2)
- bookmark: "*[2]/@id"
- test:
if: "*[2][self::m:mn][not(contains(., '.'))]"
then: [x: "ToOrdinal(*[2])"]
else: [x: "*[2]"]
- t: "パワーの" # phrase(the fourth 'power of' 2)
- x: "*[2]"
- t: "乗" # phrase(the fourth 'power of' 2)
- pause: short
- x: "*[1]"

# non-function rules for power
- name: squared-or-cubed
Expand All @@ -200,19 +195,18 @@
- bookmark: "*[2]/@id"
- test:
if: "*[2][.=2]"
then: [t: "スクエア"] # phrase(5 'squared' equals 25)
else: [t: "キューブド"] # phrase(5 'cubed' equals 125)
then: [t: "の 2 乗"] # phrase(5 'squared' equals 25)
else: [t: "の 3 乗"] # phrase(5 'cubed' equals 125)

- name: simple-integer
tag: power
match: "*[2][self::m:mn][not(contains(., '.'))]"
replace:
- x: "*[1]"
- t: "の" # phrase(15 raised 'to the' second power equals 225)
- test:
if: "*[2][.>0]"
then: [x: "ToOrdinal(*[2])"]
else: [x: "*[2]"]
- x: "*[2]"
- t: "乗" # phrase(15 raised to the second 'power' equals 225)

- name: simple-negative-integer
tag: power
match:
Expand All @@ -222,14 +216,16 @@
- x: "*[1]"
- t: "の" # phrase(15 raised 'to the' second power equals 225)
- x: "*[2]"
- t: "乗" # phrase(15 raised to the second 'power' equals 225)

- name: simple-var
tag: power
match: "*[2][self::m:mi][string-length(.)=1]"
replace:
- x: "*[1]"
- t: "の" # phrase(15 raised 'to the' second power equals 225)
- x: "*[2]"
- pronounce: [text: "-th", ipa: "θ", sapi5: "th", eloquence: "T"]
- t: "乗" # phrase(15 raised to the second 'power' equals 225)

- name: simple
tag: power
Expand All @@ -238,6 +234,7 @@
- x: "*[1]"
- t: "の" # phrase(15 raised 'to the' second power equals 225)
- x: "*[2]"
- t: "乗" # phrase(15 raised to the second 'power' equals 225)

- name: nested
# it won't end in "power" if the exponent is simple enough
Expand All @@ -251,13 +248,13 @@
- " ]"
replace:
- x: "*[1]"
- t: "に上げられた" # phrase(15 'raised to the' second power equals 225)
- t: "の上付き" # phrase(15 'raised to the' second power equals 225)
- x: "*[2]"
- pause: short
- test:
if: "$Impairment = 'Blindness'"
then:
- t: "エンド指数" # phrase(start 2 raised to the exponent 4 'end of exponent')
- t: "上付き終了" # phrase(start 2 raised to the exponent 4 'end of exponent')
- pause: short
else:
- pause: medium
Expand All @@ -267,9 +264,9 @@
match: "."
replace:
- x: "*[1]"
- t: "に上げられた" # phrase(15 'raised to the' second power equals 225)
- t: "の上付き" # phrase(15 'raised to the' second power equals 225)
- x: "*[2]"
- t: "パワー" # phrase(15 raised to the second 'power' equals 225)
- t: "上付き終了" # phrase(15 raised to the second 'power' equals 225)
- pause: short

#
Expand Down
42 changes: 40 additions & 2 deletions tests/Languages/ja/ja.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,49 @@ fn square_root() -> Result<()> {
return Ok(());
}

/// Verifies that a squared value uses the seeded Japanese exponent wording.
/// An exponent is read "<base> の <exponent> 乗"; 乗 closes it. Japanese has no
/// ordinal form here, so 2 is 2 and not "second".
#[test]
fn squared() -> Result<()> {
let expr = "<math><msup><mn>3</mn><mn>2</mn></msup></math>";
test("ja", "ClearSpeak", expr, "3 スクエア")?;
test("ja", "ClearSpeak", expr, "3 の 2 乗")?;
test("ja", "SimpleSpeak", expr, "3 の 2 乗")?;
return Ok(());
}

/// Same shape for a cube.
#[test]
fn cubed() -> Result<()> {
let expr = "<math><msup><mn>5</mn><mn>3</mn></msup></math>";
test("ja", "ClearSpeak", expr, "5 の 3 乗")?;
test("ja", "SimpleSpeak", expr, "5 の 3 乗")?;
return Ok(());
}

/// The pattern does not change for exponents above three.
#[test]
fn integer_exponent() -> Result<()> {
let expr = "<math><msup><mi>x</mi><mn>5</mn></msup></math>";
test("ja", "ClearSpeak", expr, "x の 5 乗")?;
test("ja", "SimpleSpeak", expr, "x の 5 乗")?;
return Ok(());
}

/// A variable exponent is read the same way (English adds "-th" here; Japanese does not).
#[test]
fn variable_exponent() -> Result<()> {
let expr = "<math><msup><mi>x</mi><mi>n</mi></msup></math>";
test("ja", "ClearSpeak", expr, "x の n 乗")?;
test("ja", "SimpleSpeak", expr, "x の n 乗")?;
return Ok(());
}

/// A complex exponent is read as a superscript instead, with an explicit close:
/// 「の上付き … 上付き終了」. Reading it as 乗 would end a nested exponent 「… 乗 乗」.
#[test]
fn complex_exponent() -> Result<()> {
let expr = "<math><msup><mi>x</mi><mrow><mi>y</mi><mo>+</mo><mn>1</mn></mrow></msup></math>";
test("ja", "SimpleSpeak", expr, "x の上付き y プラス 1 上付き終了")?;
return Ok(());
}

Expand Down