Skip to content

Commit eeff1f5

Browse files
Fix pluralization of Norwegian mixed number fractions
Correctly apply pluralization of mixed numbers without an explicit following unit. Introduce `IsPluralNoUnit` to ensure the fraction's numerator dictates the plural form, resolving cases like "2 tredjedeler".
1 parent 7cc8826 commit eeff1f5

4 files changed

Lines changed: 52 additions & 2 deletions

File tree

‎Rules/Languages/nb/ClearSpeak_Rules.yaml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
- "*[2][self::m:mn][not(contains(., $DecimalSeparators)) and (2<= text() and text()<=10)]" # NORWEGIAN: Removed $ClearSpeak_Fractions='Ordinal', cause the pattern for ordinal fractions is not right.
145145
variables:
146146
- IsPlural: "not(*[1]=1 or preceding-sibling::*[1][self::m:mo and .='\u2064'])" # '\u2064' is invisible plus and is used in mixed fractions
147+
- IsPluralNoUnit: "not(*[1]=1)" # mixed numbers without following units should pluralize on numerator
147148
# set right level for the location of the common fraction/mixed fraction
148149
- IsMixedFraction: "preceding-sibling::*[1][.='\u2064']"
149150
- UnitSibling: "IfThenElse($IsMixedFraction, .., .)"
@@ -169,7 +170,7 @@
169170
- if: "not($UnitNode)"
170171
then:
171172
- x: "*[1]"
172-
- x: "ToOrdinal(*[2], true(), $IsPlural)" # extra args specify fractional ordinal and whether it is plural
173+
- x: "ToOrdinal(*[2], true(), $IsPluralNoUnit)" # extra args specify fractional ordinal and whether it is plural
173174
# unit follows the fraction -- special cases
174175
- else:
175176
- test:

‎Rules/Languages/nb/SimpleSpeak_Rules.yaml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
- "*[2][self::m:mn][not(contains(., $DecimalSeparators)) and 2<= text() and text()<=10]"
7777
variables:
7878
- IsPlural: "not(*[1]=1 or preceding-sibling::*[1][self::m:mo and .='\u2064'])" # '\u2064' is invisible plus and is used in mixed fractions
79+
- IsPluralNoUnit: "not(*[1]=1)" # mixed numbers without following units should pluralize on numerator
7980
- UnitSibling: "IfThenElse(preceding-sibling::*[1][.='\u2064'], .., .)"
8081
# set the potential unit node -- otherwise set it to a empty node set (use a made up name)
8182
- UnitNodeLocation: "IfThenElse($UnitSibling/..[self::m:mrow and count(*)=3 and *[2][.='\u2062']],
@@ -99,7 +100,7 @@
99100
- if: "not($UnitNode)"
100101
then:
101102
- x: "*[1]"
102-
- x: "ToOrdinal(*[2], true(), $IsPlural)" # extra args specify fractional ordinal and whether it is plural
103+
- x: "ToOrdinal(*[2], true(), $IsPluralNoUnit)" # extra args specify fractional ordinal and whether it is plural
103104
# unit follows the fraction -- special cases
104105
- else:
105106
- test:

‎tests/Languages/nb/ClearSpeak/mfrac.rs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,27 @@ fn binomial() -> Result<()> {
311311
return Ok(());
312312

313313
}
314+
315+
#[test]
316+
fn mixed_number_1() -> Result<()> {
317+
let expr = r#"
318+
<math>
319+
<mn>1</mn>
320+
<mfrac><mn>2</mn><mn>3</mn></mfrac>
321+
</math>"#;
322+
test("nb", "ClearSpeak", expr, "1 og 2 tredjedeler")?;
323+
return Ok(());
324+
325+
}
326+
327+
#[test]
328+
fn mixed_number_2() -> Result<()> {
329+
let expr = r#"
330+
<math>
331+
<mn>2</mn>
332+
<mfrac><mn>4</mn><mn>4</mn></mfrac>
333+
</math>"#;
334+
test("nb", "ClearSpeak", expr, "2 og 4 fjerdedeler")?;
335+
return Ok(());
336+
337+
}

‎tests/Languages/nb/SimpleSpeak/mfrac.rs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,27 @@ fn binomial_non_simple_top_and_bottom() -> Result<()> {
354354
return Ok(());
355355

356356
}
357+
358+
#[test]
359+
fn mixed_number_1() -> Result<()> {
360+
let expr = r#"
361+
<math>
362+
<mn>1</mn>
363+
<mfrac><mn>2</mn><mn>3</mn></mfrac>
364+
</math>"#;
365+
test("nb", "SimpleSpeak", expr, "1 og 2 tredjedeler")?;
366+
return Ok(());
367+
368+
}
369+
370+
#[test]
371+
fn mixed_number_2() -> Result<()> {
372+
let expr = r#"
373+
<math>
374+
<mn>2</mn>
375+
<mfrac><mn>4</mn><mn>4</mn></mfrac>
376+
</math>"#;
377+
test("nb", "SimpleSpeak", expr, "2 og 4 fjerdedeler")?;
378+
return Ok(());
379+
380+
}

0 commit comments

Comments
 (0)