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
10 changes: 4 additions & 6 deletions Rules/Languages/de/SharedRules/general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +571,11 @@

- name: identity-matrix
tag: matrix
# select all the non-zero entries...if they are not on the diagonal, or are != 1
# if there are any of them, then this isn't an identity matrix
# every diagonal entry must be a literal 1, and every off-diagonal entry must be a literal 0
match:
- "count(*) = count(*[1]/*) and "
- "not( */*/*[not(self::m:mn and .= 0)]"
- " [count(../preceding-sibling::*)!=count(../../preceding-sibling::*) or .!= 1]"
- " )"
- "count(*) = count(*[1]/*) and " # matrix is square
- "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: "die" # phrase('the' 1 by 2 matrix M)
- x: count(*)
Expand Down
10 changes: 4 additions & 6 deletions Rules/Languages/en/SharedRules/general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,11 @@

- name: identity-matrix
tag: matrix
# select all the non-zero entries...if they are not on the diagonal, or are != 1
# if there are any of them, then this isn't an identity matrix
# every diagonal entry must be a literal 1, and every off-diagonal entry must be a literal 0
match:
- "count(*) = count(*[1]/*) and "
- "not( */*/*[not(self::m:mn and .= 0)]"
- " [count(../preceding-sibling::*)!=count(../../preceding-sibling::*) or .!= 1]"
- " )"
- "count(*) = count(*[1]/*) and " # matrix is square
- "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: "the" # phrase('the' 1 by 2 matrix M)
- x: count(*)
Expand Down
10 changes: 4 additions & 6 deletions Rules/Languages/nb/SharedRules/general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -686,13 +686,11 @@

- name: identity-matrix
tag: matrix
# select all the non-zero entries...if they are not on the diagonal, or are != 1
# if there are any of them, then this isn't an identity matrix
# every diagonal entry must be a literal 1, and every off-diagonal entry must be a literal 0
match:
- "count(*) = count(*[1]/*) and "
- "not( */*/*[not(self::m:mn and .= 0)]"
- " [count(../preceding-sibling::*)!=count(../../preceding-sibling::*) or .!= 1]"
- " )"
- "count(*) = count(*[1]/*) and " # matrix is square
- "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:
- x: count(*)
- T: "ganger" # phrase(the 1 'by' 2 matrix)
Expand Down
45 changes: 45 additions & 0 deletions tests/Languages/de/mtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,3 +1144,48 @@ fn single_line_with_label() -> Result<()> {
return Ok(());

*/

#[test]
fn identity_matrix() -> Result<()> {
let expr = "<math>
<mo>[</mo>
<mtable>
<mtr><mtd><mn>1</mn></mtd><mtd><mn>0</mn></mtd><mtd><mn>0</mn></mtd></mtr>
<mtr><mtd><mn>0</mn></mtd><mtd><mn>1</mn></mtd><mtd><mn>0</mn></mtd></mtr>
<mtr><mtd><mn>0</mn></mtd><mtd><mn>0</mn></mtd><mtd><mn>1</mn></mtd></mtr>
</mtable>
<mo>]</mo>
</math>";
test("de", "SimpleSpeak", expr, "die 3 mal 3 identitätsmatrix")?;
Ok(())
}

#[test]
fn identity_matrix_false_positive_negative_one() -> Result<()> {
let expr = "<math>
<mo>[</mo>
<mtable>
<mtr><mtd><mn>1</mn></mtd><mtd><mn>0</mn></mtd></mtr>
<mtr><mtd><mn>0</mn></mtd><mtd><mn>-1</mn></mtd></mtr>
</mtable>
<mo>]</mo>
</math>";
test_prefs("de", "SimpleSpeak", vec![("Verbosity", "Terse")],
expr, "die 2 mal 2 diagonalmatrix; spalte 1; 1; spalte 2; negativ 1")?;
Ok(())
}

#[test]
fn identity_matrix_false_positive_zero_diagonal() -> Result<()> {
let expr = "<math>
<mo>[</mo>
<mtable>
<mtr><mtd><mn>1</mn></mtd><mtd><mn>0</mn></mtd></mtr>
<mtr><mtd><mn>0</mn></mtd><mtd><mn>0</mn></mtd></mtr>
</mtable>
<mo>]</mo>
</math>";
test_prefs("de", "SimpleSpeak", vec![("Verbosity", "Terse")],
expr, "die 2 mal 2 diagonalmatrix; spalte 1; 1")?;
Ok(())
}
30 changes: 30 additions & 0 deletions tests/Languages/en/mtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,36 @@ fn identity_matrix() -> Result<()> {
return Ok(());
}

#[test]
fn identity_matrix_false_positive_negative_one() -> Result<()> {
let expr = "<math>
<mo>[</mo>
<mtable>
<mtr><mtd><mn>1</mn></mtd><mtd><mn>0</mn></mtd></mtr>
<mtr><mtd><mn>0</mn></mtd><mtd><mn>-1</mn></mtd></mtr>
</mtable>
<mo>]</mo>
</math>";
test_prefs("en", "SimpleSpeak", vec![("Verbosity", "Terse")],
expr, "the 2 by 2 diagonal matrix; column 1; 1; column 2; negative 1")?;
Ok(())
}

#[test]
fn identity_matrix_false_positive_zero_diagonal() -> Result<()> {
let expr = "<math>
<mo>[</mo>
<mtable>
<mtr><mtd><mn>1</mn></mtd><mtd><mn>0</mn></mtd></mtr>
<mtr><mtd><mn>0</mn></mtd><mtd><mn>0</mn></mtd></mtr>
</mtable>
<mo>]</mo>
</math>";
test_prefs("en", "SimpleSpeak", vec![("Verbosity", "Terse")],
expr, "the 2 by 2 diagonal matrix; column 1; 1")?;
Ok(())
}

#[test]
fn diagonal_matrix() -> Result<()> {
let expr = "<math>
Expand Down
30 changes: 30 additions & 0 deletions tests/Languages/nb/mtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,36 @@ fn identity_matrix() -> Result<()> {
return Ok(());
}

#[test]
fn identity_matrix_false_positive_negative_one() -> Result<()> {
let expr = "<math>
<mo>[</mo>
<mtable>
<mtr><mtd><mn>1</mn></mtd><mtd><mn>0</mn></mtd></mtr>
<mtr><mtd><mn>0</mn></mtd><mtd><mn>-1</mn></mtd></mtr>
</mtable>
<mo>]</mo>
</math>";
test_prefs("nb", "SimpleSpeak", vec![("Verbosity", "Terse")],
expr, "2 ganger 2 diagonalmatrise; kolonne 1; 1; kolonne 2; minus 1")?;
Ok(())
}

#[test]
fn identity_matrix_false_positive_zero_diagonal() -> Result<()> {
let expr = "<math>
<mo>[</mo>
<mtable>
<mtr><mtd><mn>1</mn></mtd><mtd><mn>0</mn></mtd></mtr>
<mtr><mtd><mn>0</mn></mtd><mtd><mn>0</mn></mtd></mtr>
</mtable>
<mo>]</mo>
</math>";
test_prefs("nb", "SimpleSpeak", vec![("Verbosity", "Terse")],
expr, "2 ganger 2 diagonalmatrise; kolonne 1; 1")?;
Ok(())
}

#[test]
fn diagonal_matrix() -> Result<()> {
let expr = "<math>
Expand Down
Loading