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
72 changes: 38 additions & 34 deletions Rules/Languages/ja/SharedRules/general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -574,12 +574,12 @@
variables: [IsColumnSilent: true()]
match: "count(*)=1 and *[self::m:mtr][count(*) = 1]"
replace:
- ot: "" # phrase('the' 1 by 1 matrix M)
- t: "1 かける 1" # phrase(the '1 by 1' matrix)
- OT: "" # phrase('the' 1 by 1 matrix M)
- T: "1 かける 1" # phrase(the '1 by 1' matrix)
- test:
if: "self::m:determinant" # just need to check the first bracket since we know it must be (, [, or |
then: [t: "行列式"] # phrase(the 2 by 2 'determinant'))
else: [t: "行列"] # phrase(the 2 by 2 'matrix')
then: [T: "行列式"] # phrase(the 2 by 2 'determinant'))
else: [T: "行列"] # phrase(the 2 by 2 'matrix')

- T: "成分" # phrase(the 2 by 2 matrix 'with entry' x)
- x: "*[1]/*"
Expand All @@ -590,11 +590,11 @@
# select all the non-zero entries -- if there are none of them, then it is a zero matrix
match: "not( */*/*[not(self::m:mn and .= 0)] )"
replace:
- t: "" # phrase('the' 1 by 2 matrix M)
- T: "" # phrase('the' 1 by 2 matrix M)
- x: count(*)
- t: "かける" # phrase(the 1 'by' 2 matrix)
- T: "かける" # phrase(the 1 'by' 2 matrix)
- x: count(*[self::m:mtr][1]/*)
- t: "零行列" # phrase(the 2 by 2 'zero matrix')
- T: "零行列" # phrase(the 2 by 2 'zero matrix')
- pause: long

- name: identity-matrix
Expand All @@ -605,11 +605,11 @@
- "not( */*[count(preceding-sibling::*) = count(../preceding-sibling::*)]/*[not(self::m:mn and .= 1)] ) and " # on-diagonal
- "not( */*[count(preceding-sibling::*) != count(../preceding-sibling::*)]/*[not(self::m:mn and .= 0)] )" # off-diagonal
replace:
- t: "" # phrase('the' 1 by 2 matrix M)
- T: "" # phrase('the' 1 by 2 matrix M)
- x: count(*)
- t: "かける" # phrase(the 1 'by' 2 matrix)
- T: "かける" # phrase(the 1 'by' 2 matrix)
- x: count(*[self::m:mtr][1]/*)
- t: "単位行列" # phrase(the 2 by 2 'identity matrix')
- T: "単位行列" # phrase(the 2 by 2 'identity matrix')
- pause: long

- name: diagonal-matrix
Expand All @@ -622,11 +622,11 @@
- " [count(../preceding-sibling::*)!=count(../../preceding-sibling::*)]"
- " )"
replace:
- t: "" # phrase('the' 1 by 2 matrix)
- T: "" # phrase('the' 1 by 2 matrix)
- x: count(*)
- t: "かける" # phrase(the 1 'by' 2 matrix)
- T: "かける" # phrase(the 1 'by' 2 matrix)
- x: count(*[self::m:mtr][1]/*)
- t: "対角行列" # phrase(the 2 by 2 'diagonal matrix')
- T: "対角行列" # phrase(the 2 by 2 'diagonal matrix')
- pause: long
- insert:
# this lists the diagonal 'mtd's to be read, and they say "column nnn" before reading the contents
Expand All @@ -646,9 +646,9 @@
- count(*)<=3 and # at least two rows
- IsNode(*/*/*,'simple') # IsNode() returns true if all the nodes are simple
replace:
- t: "" # phrase('the' 2 by 2 matrix M)
- T: "" # phrase('the' 2 by 2 matrix M)
- x: count(*)
- T: "かける 1 列" # phrase(the 2 'by 1 column' matrix)
- T: "かける 1" # phrase(the 2 'by 1 column' matrix)
- test:
if: "$ClearSpeak_Matrix = 'Vector' or $ClearSpeak_Matrix = 'EndVector'"
then: [T: "ベクトル"] # phrase(the 2 by 2 'vector')
Expand All @@ -664,14 +664,14 @@
then: [T: "ベクトル終了"] # phrase(the 2 column 'vector')
else: [T: "行列終了"] # phrase(the 2 by 2 'matrix')

- name: default-column-matrix
- name: default-column-matrix # audit-ignore: ends with ベクトル終了 for EndVector, as the other row and column rules do (en says "end matrix" here)
tag: matrix
variables: [IsColumnSilent: true()]
match: "*[self::m:mtr][count(*) = 1]"
replace:
- t: "" # phrase('the' 2 by 2 matrix M)
- T: "" # phrase('the' 2 by 2 matrix M)
- x: "count(*)"
- T: "かける 1 列" # phrase(the 2 'by 1 column' matrix)
- T: "かける 1" # phrase(the 2 'by 1 column' matrix)
- test:
if: "$ClearSpeak_Matrix = 'Vector' or $ClearSpeak_Matrix = 'EndVector'"
then: [T: "ベクトル"] # phrase(the 2 column 'vector')
Expand All @@ -680,7 +680,11 @@
- x: "*" # select the rows (mtr)
- test:
if: "$ClearSpeak_Matrix = 'EndMatrix' or $ClearSpeak_Matrix = 'EndVector'"
then: [T: "行列終了"] # phrase(the 'end of matrix' has been reached)
then:
- test:
if: $ClearSpeak_Matrix = 'EndVector'
then: [T: "ベクトル終了"] # phrase(the 2 by 1 'vector')
else: [T: "行列終了"] # phrase(the 'end of matrix' has been reached)

- name: 1x2-or-3-matrix
tag: matrix
Expand All @@ -691,9 +695,9 @@
- count(*[1]/*)<=3 and # at least two cols
- IsNode(*/*/*,'simple') # IsNode() returns true if all the nodes are simple
replace:
- t: "1 かける" # phrase('the 1 by' 2 matrix)
- T: "1 かける" # phrase('the 1 by' 2 matrix)
- x: count(*/*)
- t: "行" # phrase(the 1 by 4 'row' matrix)
- T: "" # phrase(the 1 by 4 'row' matrix)
- test:
if: "$ClearSpeak_Matrix = 'Vector' or $ClearSpeak_Matrix = 'EndVector'"
then: [T: "ベクトル"] # phrase('the 1 by' 2 row 'vector')
Expand All @@ -714,9 +718,9 @@
variables: [IsColumnSilent: "$SpeechStyle = 'ClearSpeak' and $ClearSpeak_Matrix = 'SilentColNum'"]
match: "count(*)=1" # one row
replace:
- t: "1 かける" # phrase('the 1 by' 2 matrix)
- T: "1 かける" # phrase('the 1 by' 2 matrix)
- x: "count(*/*)"
- t: "行" # phrase(the 1 by 2 'row' matrix)
- T: "" # phrase(the 1 by 2 'row' matrix)
- test:
if: "$ClearSpeak_Matrix = 'Vector' or $ClearSpeak_Matrix = 'EndVector'"
then: [T: "ベクトル"] # phrase(the 2 by 1 'vector')
Expand All @@ -741,18 +745,18 @@
- IsNode(*/*/*,'simple') # IsNode() returns true if all the nodes are simple
variables: [IsColumnSilent: "$SpeechStyle = 'SimpleSpeak' or ($SpeechStyle = 'ClearSpeak' and $ClearSpeak_Matrix != 'SpeakColNum')"]
replace:
- t: "" # phrase('the' 1 by 2 matrix M)
- T: "" # phrase('the' 1 by 2 matrix M)
- x: count(*)
- t: "かける" # phrase(the 1 'by' 2 matrix)
- T: "かける" # phrase(the 1 'by' 2 matrix)
- x: count(*[self::m:mtr][1]/*)
- test:
if: "self::m:determinant"
then: [t: "行列式"] # phrase(the 2 by 2 'determinant')
then: [T: "行列式"] # phrase(the 2 by 2 'determinant')
else:
- test:
if: "@columnlines and (contains(normalize-space(@columnlines), 'solid') or contains(normalize-space(@columnlines), 'dashed'))"
then: [t: "拡大行列"] # phrase(the 2 by 2 'augmented matrix')
else: [t: "行列"] # phrase(the 2 by 2 'matrix')
then: [T: "拡大行列"] # phrase(the 2 by 2 'augmented matrix')
else: [T: "行列"] # phrase(the 2 by 2 'matrix')
- pause: long
- x: "*"
- test:
Expand All @@ -769,18 +773,18 @@
variables: [IsColumnSilent: "$SpeechStyle = 'ClearSpeak' and $ClearSpeak_Matrix = 'SilentColNum'"]
match: "."
replace:
- t: "" # phrase('the' 1 by 2 matrix M)
- T: "" # phrase('the' 1 by 2 matrix M)
- x: "count(*)"
- t: "かける" # phrase(the 1 'by' 2 matrix)
- T: "かける" # phrase(the 1 'by' 2 matrix)
- x: "count(*[self::m:mtr][1]/*)"
- test:
if: "self::m:determinant"
then: [t: "行列式"] # phrase(the 2 by 2 'determinant')
then: [T: "行列式"] # phrase(the 2 by 2 'determinant')
else:
- test:
if: "@columnlines and (contains(normalize-space(@columnlines), 'solid') or contains(normalize-space(@columnlines), 'dashed'))"
then: [t: "拡大行列"] # phrase(the 2 by 2 'augmented matrix')
else: [t: "行列"] # phrase(the 2 by 2 'matrix')
then: [T: "拡大行列"] # phrase(the 2 by 2 'augmented matrix')
else: [T: "行列"] # phrase(the 2 by 2 'matrix')
- pause: long
- x: "*"
- test:
Expand Down Expand Up @@ -811,7 +815,7 @@
replace:
- insert:
nodes: "*"
replace: [t: "かける", pause: auto] # phrase(3 'by' 5 matrix)
replace: [T: "かける", pause: auto] # phrase(3 'by' 5 matrix)

- name: chemistry-msup
tag: [chemical-formula]
Expand Down
12 changes: 6 additions & 6 deletions Rules/Languages/ja/SharedRules/linear-algebra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
- test:
if: "$Verbosity='Verbose'"
then:
- t: "" # phrase('the' square root of 25 equals 5)
- t: "行列式" # phrase(the 'determinant' of a matrix)
- T: "" # phrase('the' square root of 25 equals 5)
- T: "行列式" # phrase(the 'determinant' of a matrix)
- test:
if: "$Verbosity!='Terse'"
then:
- t: "の" # phrase(systems 'of' linear equations)
- T: "の" # phrase(systems 'of' linear equations)
- x: "*[1]"
- test:
if: "not(IsNode(*[1], 'simple')) and $Impairment = 'Blindness'"
then: [t: "末端の 行列式"] # phrase('end determinant' of a matrix)
then: [T: "行列式終了"] # phrase('end determinant' of a matrix)


- name: subscripted-norm
Expand All @@ -26,11 +26,11 @@
- test:
if: "$Verbosity='Verbose'"
then:
- t: "" # phrase('the' square root of 25 equals 5)
- T: "" # phrase('the' square root of 25 equals 5)
- x: "*[2]"
- T: "ノルム" # phrase(the 'norm' can be a measure of distance)
- test:
if: "$Verbosity!='Terse'"
then:
- t: "の" # phrase(systems 'of' linear equations)
- T: "の" # phrase(systems 'of' linear equations)
- x: "*[1]"
8 changes: 4 additions & 4 deletions Rules/Languages/ja/overview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
- "*[2][self::m:mtable] and"
- "(IsBracketed(., '(', ')') or IsBracketed(., '[', ']') or IsBracketed(., '|', '|'))"
replace:
- t: ""
- T: ""
- x: count(*[2]/*)
- t: "かける"
- T: "かける"
- x: count(*[2]/*[self::m:mtr][1]/*)
- test:
if: "*[1][.='|']" # just need to check the first bracket since we know it must be (, [, or |
then: [t: "行列式"]
else: [t: "行列"]
then: [T: "行列式"]
else: [T: "行列"]

- name: overview-default
tag: mtable
Expand Down
90 changes: 86 additions & 4 deletions tests/Languages/ja/ja.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,59 @@ fn statistics_mode() -> Result<()> {
}

/// A matrix is 行列, not the loanword マトリクス, and the dimension separator is
/// かける, not によって ("by means of").
/// かける, not によって ("by means of"). A row matrix was "1 かける 2 行 行列": the
/// size already says it is one row, and 行 standing alone is read クダリ or アルキ
/// by Open JTalk, so the extra word is gone.
#[test]
fn matrix_terminology() -> Result<()> {
let expr = "<math><mrow><mo>[</mo><mtable><mtr><mtd><mn>1</mn></mtd><mtd><mn>2</mn></mtd></mtr></mtable><mo>]</mo></mrow></math>";
test("ja", "ClearSpeak", expr, "1 かける 2 行 行列; 1, 2")?;
test("ja", "ClearSpeak", expr, "1 かける 2 行列; 1, 2")?;
return Ok(());
}

fn mat(rows: &[&[&str]], open: &str, close: &str, attrs: &str) -> String {
let rows: String = rows.iter()
.map(|r| format!("<mtr>{}</mtr>", r.iter().map(|c| format!("<mtd>{c}</mtd>")).collect::<String>()))
.collect();
format!("<math><mrow><mo>{open}</mo><mtable {attrs}>{rows}</mtable><mo>{close}</mo></mrow></math>")
}

/// The matrix rules not covered above say the size as m かける n too: the special
/// matrices, a matrix too big for the short form, and the one-row and one-column
/// forms (which no longer add 行 or 列 before 行列 or ベクトル). A long column read
/// as a vector ends with ベクトル終了, like the short column and row forms.
#[test]
fn matrix_sizes() -> Result<()> {
let (n0, n1, n2, n3, n4) = ("<mn>0</mn>", "<mn>1</mn>", "<mn>2</mn>", "<mn>3</mn>", "<mn>4</mn>");
let x2 = "<msup><mi>x</mi><mn>2</mn></msup>";
test("ja", "SimpleSpeak", &mat(&[&[n0, n0], &[n0, n0]], "[", "]", ""), "2 かける 2 零行列")?;
test("ja", "SimpleSpeak", &mat(&[&[n1, n0, n0], &[n0, n1, n0], &[n0, n0, n1]], "(", ")", ""),
"3 かける 3 単位行列")?;
test_prefs("ja", "SimpleSpeak", vec![("Verbosity", "Terse")],
&mat(&[&[n2, n0, n0], &[n0, n1, n0], &[n0, n0, x2]], "(", ")", ""),
"3 かける 3 対角行列; 列 1; 2; 列 2; 1; 列 3; x の 2 乗")?;
test("ja", "ClearSpeak", &mat(&[&[n1, n2, n3, n4], &[n4, n3, n2, n1]], "(", ")", ""),
"2 かける 4 行列; 行 1; 列 1; 1, 列 2; 2, 列 3; 3, 列 4; 4; 行 2; 列 1; 4, 列 2; 3, 列 3; 2, 列 4; 1")?;
test("ja", "ClearSpeak", &mat(&[&[n1, n2, n3, n4], &[n4, n3, n2, n1]], "(", ")", "columnlines='none none solid'"),
"2 かける 4 拡大行列; 行 1; 列 1; 1, 列 2; 2, 列 3; 3, 列区切り, 列 4; 4; 行 2; 列 1; 4, 列 2; 3, 列 3; 2, 列区切り, 列 4; 1")?;
test("ja", "SimpleSpeak", &mat(&[&[n1], &[n2], &[n3]], "(", ")", ""), "3 かける 1 行列; 1; 2; 3")?;
let column = mat(&[&[n1], &[n2], &[n3], &[n4]], "(", ")", "");
let row = mat(&[&[n1, n2, n3, n4]], "(", ")", "");
test("ja", "ClearSpeak", &column, "4 かける 1 行列; 行 1; 1; 行 2; 2; 行 3; 3; 行 4; 4")?;
test("ja", "ClearSpeak", &row, "1 かける 4 行列; 列 1; 1, 列 2; 2, 列 3; 3, 列 4; 4")?;
// ClearSpeak_Matrix stays set for the rest of this test, so the Vector cases come last.
test_ClearSpeak("ja", "ClearSpeak_Matrix", "Vector", &column,
"4 かける 1 ベクトル; 行 1; 1; 行 2; 2; 行 3; 3; 行 4; 4")?;
test_ClearSpeak("ja", "ClearSpeak_Matrix", "Vector", &row,
"1 かける 4 ベクトル; 列 1; 1, 列 2; 2, 列 3; 3, 列 4; 4")?;
test_ClearSpeak("ja", "ClearSpeak_Matrix", "EndMatrix", &column,
"4 かける 1 行列; 行 1; 1; 行 2; 2; 行 3; 3; 行 4; 4; 行列終了")?;
test_ClearSpeak("ja", "ClearSpeak_Matrix", "EndVector", &column,
"4 かける 1 ベクトル; 行 1; 1; 行 2; 2; 行 3; 3; 行 4; 4; ベクトル終了")?;
test_ClearSpeak("ja", "ClearSpeak_Matrix", "EndMatrix", &row,
"1 かける 4 行列; 列 1; 1, 列 2; 2, 列 3; 3, 列 4; 4; 行列終了")?;
test_ClearSpeak("ja", "ClearSpeak_Matrix", "EndVector", &row,
"1 かける 4 ベクトル; 列 1; 1, 列 2; 2, 列 3; 3, 列 4; 4; ベクトル終了")?;
return Ok(());
}

Expand Down Expand Up @@ -869,7 +917,7 @@ fn column_vector_end_vector() -> Result<()> {
<mtr><mtd><mn>3</mn></mtd></mtr>
</mtable></mrow><mo>)</mo></mrow></math>";
test_ClearSpeak("ja", "ClearSpeak_Matrix", "EndVector",
expr, "3 かける 1 列 ベクトル; 1; 2; 3; ベクトル終了")?;
expr, "3 かける 1 ベクトル; 1; 2; 3; ベクトル終了")?;
return Ok(());
}

Expand All @@ -882,7 +930,7 @@ fn row_vector_and_matrix_end_markers() -> Result<()> {
<mtr><mtd><mn>1</mn></mtd><mtd><mn>2</mn></mtd></mtr>
</mtable></mrow><mo>]</mo></mrow></math>";
test_ClearSpeak("ja", "ClearSpeak_Matrix", "EndVector",
row, "1 かける 2 行 ベクトル; 1, 2; ベクトル終了")?;
row, "1 かける 2 ベクトル; 1, 2; ベクトル終了")?;
let square = "<math display='block'>
<mrow><mo>(</mo><mrow><mtable>
<mtr><mtd><mn>2</mn></mtd><mtd><mn>1</mn></mtd></mtr>
Expand Down Expand Up @@ -953,6 +1001,20 @@ fn determinant_end_marker() -> Result<()> {
return Ok(());
}

/// The other determinant forms: one entry, a table too big for the short form,
/// and the determinant of a single expression, whose end marker was 末端の 行列式
/// ("the terminal determinant") and is now 行列式終了 like the others.
#[test]
fn determinant_sizes_and_scalar_end_marker() -> Result<()> {
let (n1, n2, n3, n4) = ("<mn>1</mn>", "<mn>2</mn>", "<mn>3</mn>", "<mn>4</mn>");
test("ja", "ClearSpeak", &mat(&[&["<mi>x</mi>"]], "|", "|", ""), "1 かける 1 行列式 成分 x")?;
test("ja", "ClearSpeak", &mat(&[&[n1, n2, n3, n4], &[n4, n3, n2, n1]], "|", "|", ""),
"2 かける 4 行列式; 行 1; 列 1; 1, 列 2; 2, 列 3; 3, 列 4; 4; 行 2; 列 1; 4, 列 2; 3, 列 3; 2, 列 4; 1")?;
let scalar = "<math><mrow intent='determinant($a)'><mrow arg='a'><mi>x</mi><mo>+</mo><mi>y</mi></mrow></mrow></math>";
test("ja", "ClearSpeak", scalar, "行列式 の x プラス y 行列式終了")?;
return Ok(());
}

/// LiteralSpeak reads what is written, and Japanese writes the denominator
/// first: 3/4 is "4 分の 3". "3 分の 4" is the other number, 4/3.
#[test]
Expand Down Expand Up @@ -985,6 +1047,26 @@ fn overview_fraction_is_denominator_first() -> Result<()> {
return Ok(());
}

/// The overview rules say a matrix size the same way as the full speech.
#[test]
fn overview_matrix_size() -> Result<()> {
let (n1, n2, n3, n4) = ("<mn>1</mn>", "<mn>2</mn>", "<mn>3</mn>", "<mn>4</mn>");
for (expr, expected) in [
(mat(&[&[n1, n2], &[n3, n4]], "(", ")", ""), "2 かける 2 行列"),
(mat(&[&[n1, n2], &[n3, n4]], "|", "|", ""), "2 かける 2 行列式"),
(mat(&[&[n1, n2, n3], &[n3, n4, n1]], "[", "]", ""), "2 かける 3 行列"),
] {
set_rules_dir(abs_rules_dir_path())?;
set_preference("Language", "ja")?;
set_preference("SpeechStyle", "SimpleSpeak")?;
set_preference("Verbosity", "Medium")?;
set_mathml(&expr)?;
let spoken = get_overview_text()?;
assert_eq!(expected, spoken.trim_end_matches([' ', ',', ';']), "overview of {expr}");
}
return Ok(());
}

/// A strike names its direction and then the mark. 対角形 ("diagonal shape") does
/// not say which diagonal, and クロスアウト is the English "cross out".
#[test]
Expand Down
Loading