diff --git a/Rules/Languages/de/SharedRules/general.yaml b/Rules/Languages/de/SharedRules/general.yaml index 4058dd43..c0cbaaed 100644 --- a/Rules/Languages/de/SharedRules/general.yaml +++ b/Rules/Languages/de/SharedRules/general.yaml @@ -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(*) diff --git a/Rules/Languages/en/SharedRules/general.yaml b/Rules/Languages/en/SharedRules/general.yaml index aece2074..d6feca1d 100644 --- a/Rules/Languages/en/SharedRules/general.yaml +++ b/Rules/Languages/en/SharedRules/general.yaml @@ -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(*) diff --git a/Rules/Languages/nb/SharedRules/general.yaml b/Rules/Languages/nb/SharedRules/general.yaml index 7f0ef37f..f5babe07 100644 --- a/Rules/Languages/nb/SharedRules/general.yaml +++ b/Rules/Languages/nb/SharedRules/general.yaml @@ -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) diff --git a/tests/Languages/de/mtable.rs b/tests/Languages/de/mtable.rs index 472e5868..f542a4e5 100644 --- a/tests/Languages/de/mtable.rs +++ b/tests/Languages/de/mtable.rs @@ -1144,3 +1144,48 @@ fn single_line_with_label() -> Result<()> { return Ok(()); */ + +#[test] +fn identity_matrix() -> Result<()> { + let expr = " + [ + + 100 + 010 + 001 + + ] + "; + test("de", "SimpleSpeak", expr, "die 3 mal 3 identitätsmatrix")?; + Ok(()) +} + +#[test] +fn identity_matrix_false_positive_negative_one() -> Result<()> { + let expr = " + [ + + 10 + 0-1 + + ] + "; + 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 = " + [ + + 10 + 00 + + ] + "; + test_prefs("de", "SimpleSpeak", vec![("Verbosity", "Terse")], + expr, "die 2 mal 2 diagonalmatrix; spalte 1; 1")?; + Ok(()) +} diff --git a/tests/Languages/en/mtable.rs b/tests/Languages/en/mtable.rs index 0207d6c0..f3c51174 100644 --- a/tests/Languages/en/mtable.rs +++ b/tests/Languages/en/mtable.rs @@ -1125,6 +1125,36 @@ fn identity_matrix() -> Result<()> { return Ok(()); } +#[test] +fn identity_matrix_false_positive_negative_one() -> Result<()> { + let expr = " + [ + + 10 + 0-1 + + ] + "; + 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 = " + [ + + 10 + 00 + + ] + "; + 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 = " diff --git a/tests/Languages/nb/mtable.rs b/tests/Languages/nb/mtable.rs index 3449a06d..a9f74b4d 100644 --- a/tests/Languages/nb/mtable.rs +++ b/tests/Languages/nb/mtable.rs @@ -1118,6 +1118,36 @@ fn identity_matrix() -> Result<()> { return Ok(()); } +#[test] +fn identity_matrix_false_positive_negative_one() -> Result<()> { + let expr = " + [ + + 10 + 0-1 + + ] + "; + 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 = " + [ + + 10 + 00 + + ] + "; + test_prefs("nb", "SimpleSpeak", vec![("Verbosity", "Terse")], + expr, "2 ganger 2 diagonalmatrise; kolonne 1; 1")?; + Ok(()) +} + #[test] fn diagonal_matrix() -> Result<()> { let expr = "