Skip to content

Commit e0deb5b

Browse files
committed
Swedish en/ett fix
Upon deeper testing of fractions and units in Swedish it was found that the number 1 was erroneously spoken as neuter gendered ("ett" rather than "en"). This fix solves all cases except when there is a mixed fraction followed by a unit (e.g. 1 1/3 m should read "en och en tredjedels meter" but is currently read "ett och en tredjedels meter"), which I can't figure out how to fix.
1 parent a03f674 commit e0deb5b

11 files changed

Lines changed: 125 additions & 77 deletions

File tree

Rules/Languages/sv/ClearSpeak_Rules.yaml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
- T: "per" # phrase('5 meters 'per' second)
117117
- test:
118118
if: "*[2]='t'"
119-
then: [T: "time"]
119+
then: [T: "timme"]
120120
else:
121121
- x: "*[2]"
122122

@@ -151,15 +151,22 @@
151151
) ]"
152152
replace:
153153
- test:
154-
- if: "not($UnitNode)"
154+
- if: "not($UnitNode)"
155155
then:
156-
- x: "*[1]"
157-
- x: "ToOrdinal(*[2], true(), $IsPlural)" # extra args specify fractional ordinal and whether it is plural
156+
- test:
157+
if: "*[1]=1"
158+
then: [T: "en"]
159+
else: [x: "*[1]"]
160+
- x: "ToOrdinal(*[2], true(), $IsPlural)" # extra args specify fractional ordinal and whether it is plural
158161
# unit follows the fraction -- special cases
159162
- else:
160163
- test:
161-
if: "$NeuterUnitFollows and (*[1]=1 or ($IsMixedFraction and preceding-sibling::*[2][.=1]))"
162-
then: [T: "ett"]
164+
- if: "*[1]=1 or ($IsMixedFraction and preceding-sibling::*[2][.=1])"
165+
then:
166+
- test:
167+
if: "$NeuterUnitFollows"
168+
then: [T: "ett"]
169+
else: [T: "en"]
163170
else: [x: "*[1]"]
164171
- test:
165172
- if: "*[1]=1 and *[2]=2"
@@ -171,6 +178,7 @@
171178
then: [x: "DefinitionValue(*[2], 'Speech', 'OrdinalFractionalDenominatorsForUnits')"]
172179
else: [x: "*[2]", CT: "dels"] # this is wrong but shouldn't occur normally -- need to write a function to compute cardinal numbers as words
173180

181+
174182
- name: fraction-over-simple
175183
tag: fraction
176184
match:

Rules/Languages/sv/SharedRules/default.yaml

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,50 @@
196196
- x: "*[last()]"
197197
# - t: "power" # phrase(5 raised to the second 'power' equals 25)
198198

199+
# - name: default
200+
# tag: munder
201+
# match: "."
202+
# replace:
203+
# - test:
204+
# if: "not(IsNode(*[1], 'leaf'))"
205+
# then: [T: "kommenterat uttryck"] # phrase(phrase(x 'modified' with y above it)
206+
# - x: "*[1]"
207+
# - pause: short
208+
# - T: "med kommentar under" # phrase(x 'with' z below it)
209+
# - pause: short
210+
# - x: "*[2]"
211+
# - pause: short
212+
# - T: "slut kommentar" # phrase(x with z 'below' it)
213+
199214
- name: default
200215
tag: munder
201216
match: "."
202217
replace:
203-
- test:
204-
if: "not(IsNode(*[1], 'leaf'))"
205-
then: [T: "kommenterat uttryck"] # phrase(phrase(x 'modified' with y above it)
206-
- x: "*[1]"
207-
- pause: short
208-
- T: "med kommentar under" # phrase(x 'with' z below it)
209-
- pause: short
210-
- x: "*[2]"
211-
- pause: short
212-
- T: "slut kommentar" # phrase(x with z 'below' it)
218+
- with:
219+
variables:
220+
# true if the comment contains ⏟ or ︸ (also if inside mrow or surrounded by whitespace)
221+
- HasBrace: "contains(normalize-space(string(*[2])), '⏟') or contains(normalize-space(string(*[2])), '︸')"
222+
replace:
223+
- test:
224+
if: "$HasBrace"
225+
then:
226+
# The base is always read
227+
- x: "*[1]"
228+
- pause: short
229+
# Read the brace (good for navigation) but no framing phrases
230+
- x: "*[2]"
231+
else:
232+
# Frame phrase in the beginning if the base is not leaf
233+
- test:
234+
if: "not(IsNode(*[1], 'leaf'))"
235+
then: [T: "kommenterat uttryck"]
236+
- x: "*[1]"
237+
- pause: short
238+
- T: "med kommentar under"
239+
- pause: short
240+
- x: "*[2]"
241+
- pause: short
242+
- T: "slut kommentar"
213243

214244
- name: diacriticals
215245
tag: mover

Rules/Languages/sv/SimpleSpeak_Rules.yaml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@
5959
- name: common-fraction
6060
tag: fraction
6161
match:
62-
- "*[1][self::m:mn][not(contains(., $DecimalSeparators)) and text()<20] and" #NORWEGIAN: Changed decimal point to $DecimalSeparators
63-
- "*[2][self::m:mn][not(contains(., $DecimalSeparators)) and 2<= text() and text()<=10]"
62+
- "($ClearSpeak_Fractions='Auto' or $ClearSpeak_Fractions='Ordinal' or $ClearSpeak_Fractions='EndFrac') and"
63+
- "*[1][self::m:mn][not(contains(., $DecimalSeparators)) and ($ClearSpeak_Fractions='Ordinal' or text()<20)] and" #NORWEGIAN: Changed decimal point to $DecimalSeparators
64+
- "*[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.
6465
variables:
65-
- IsPlural: "not(*[1]=1 or preceding-sibling::*[1][self::m:mo and .='\u2064'])" # '\u2064' is invisible plus and is used in mixed fractions
66-
- UnitSibling: "IfThenElse(preceding-sibling::*[1][.='\u2064'], .., .)"
66+
- IsPlural: "DEBUG(not(*[1]=1 or preceding-sibling::*[1][self::m:mo and .='\u2064']))" # '\u2064' is invisible plus and is used in mixed fractions
67+
# set right level for the location of the common fraction/mixed fraction
68+
- IsMixedFraction: "preceding-sibling::*[1][.='\u2064']"
69+
- UnitSibling: "IfThenElse($IsMixedFraction, .., .)"
6770
# set the potential unit node -- otherwise set it to a empty node set (use a made up name)
6871
- UnitNodeLocation: "IfThenElse($UnitSibling/..[self::m:mrow and count(*)=3 and *[2][.='\u2062']],
6972
$UnitSibling/following-sibling::*[2],
@@ -74,24 +77,31 @@
7477
$UnitNodeLocation[self::m:fraction[contains(@data-intent-property, ':unit:')]]/*[1])"
7578
# test the node for being a neuter unit
7679
# note: bias ha->hektar and Pa->Pascal, not si-prefix "a" (annum)
77-
- NeuterUnitFollows: "$UnitNode[DEBUG(IsInDefinition(., 'Speech', 'NeuterUnits')) or
80+
- NeuterUnitFollows: "$UnitNode[IsInDefinition(., 'Speech', 'NeuterUnits') or
7881
IsInDefinition(., 'Speech', 'NeuterUnitsWithoutPrefixes') or
7982
(string-length(.) >= 2 and
80-
.!='ha' and .!='Pa' and
83+
. != 'ha' and . != 'Pa' and
8184
DefinitionValue(substring(., 1, 1), 'Speech', 'SIPrefixes') != '' and
8285
IsInDefinition(substring(., 2), 'Speech', 'NeuterUnits') != ''
8386
) ]"
8487
replace:
8588
- test:
86-
- if: "not($UnitNode)"
89+
- if: "not($UnitNode)"
8790
then:
88-
- x: "*[1]"
89-
- x: "ToOrdinal(*[2], true(), $IsPlural)" # extra args specify fractional ordinal and whether it is plural
91+
- test:
92+
if: "*[1]=1"
93+
then: [T: "en"]
94+
else: [x: "*[1]"]
95+
- x: "ToOrdinal(*[2], true(), $IsPlural)" # extra args specify fractional ordinal and whether it is plural
9096
# unit follows the fraction -- special cases
9197
- else:
9298
- test:
93-
if: "*[1]=1 and $NeuterUnitFollows"
94-
then: [T: "ett"]
99+
- if: "*[1]=1 or ($IsMixedFraction and preceding-sibling::*[2][.=1])"
100+
then:
101+
- test:
102+
if: "$NeuterUnitFollows"
103+
then: [T: "ett"]
104+
else: [T: "en"]
95105
else: [x: "*[1]"]
96106
- test:
97107
- if: "*[1]=1 and *[2]=2"

tests/Languages/sv/ClearSpeak/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ fn explicit_times_none_superscript() -> Result<()> {
419419
<mfrac> <mn>1</mn><mn>2</mn></mfrac>
420420
<mo>)</mo></mrow></mrow>
421421
</mrow></math>";
422-
test("sv", "ClearSpeak", expr, "2 plus 1 halv")?;
422+
test("sv", "ClearSpeak", expr, "2 plus en halv")?;
423423
return Ok(());
424424

425425
}

tests/Languages/sv/ClearSpeak/mfrac.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn common_fraction_half() -> Result<()> {
99
let expr = "<math>
1010
<mfrac> <mn>1</mn> <mn>2</mn> </mfrac>
1111
</math>";
12-
test("sv", "ClearSpeak", expr, "1 halv")?;
12+
test("sv", "ClearSpeak", expr, "en halv")?;
1313
return Ok(());
1414

1515
}
@@ -79,7 +79,7 @@ fn mixed_number() -> Result<()> {
7979
<mn>3</mn>
8080
<mfrac> <mn>1</mn> <mn>2</mn> </mfrac>
8181
</math>";
82-
test("sv", "ClearSpeak", expr, "3 och 1 halv")?;
82+
test("sv", "ClearSpeak", expr, "3 och en halv")?;
8383
return Ok(());
8484

8585
}
@@ -91,7 +91,7 @@ fn explicit_mixed_number() -> Result<()> {
9191
<mo>&#x2064;</mo>
9292
<mfrac> <mn>1</mn> <mn>8</mn> </mfrac>
9393
</math>";
94-
test("sv", "ClearSpeak", expr, "3 och 1 åttondel")?;
94+
test("sv", "ClearSpeak", expr, "3 och en åttondel")?;
9595
return Ok(());
9696

9797
}
@@ -153,14 +153,14 @@ fn nested_simple_fractions() -> Result<()> {
153153
</mfrac>
154154
</mrow>
155155
</math>";
156-
test_prefs("sv", "ClearSpeak", vec![("ClearSpeak_Fractions", "Auto")], expr, ", division, 1 halv genom 2 tredjedelar, slut division")?;
157-
test_prefs("sv", "ClearSpeak", vec![("ClearSpeak_Fractions", "Ordinal")], expr, ", division, 1 halv genom 2 tredjedelar, slut division")?;
156+
test_prefs("sv", "ClearSpeak", vec![("ClearSpeak_Fractions", "Auto")], expr, ", division, en halv genom 2 tredjedelar, slut division")?;
157+
test_prefs("sv", "ClearSpeak", vec![("ClearSpeak_Fractions", "Ordinal")], expr, ", division, en halv genom 2 tredjedelar, slut division")?;
158158
test_prefs("sv", "ClearSpeak", vec![("ClearSpeak_Fractions", "Over")], expr, ", division; bråk, 1 genom 2, slut bråk, genom, bråk, 2 genom 3, slut bråk; slut division")?;
159159
test_prefs("sv", "ClearSpeak", vec![("ClearSpeak_Fractions", "FracOver")], expr,
160160
", division; bråk, 1 genom 2, slut bråk, genom, bråk, 2 genom 3, slut bråk; slut division")?;
161161
test_prefs("sv", "ClearSpeak", vec![("ClearSpeak_Fractions", "General")], expr,
162162
"division med täljaren division med täljaren 1; och nämnaren 2; och nämnaren division med täljaren 2; och nämnaren 3")?;
163-
test_prefs("sv", "ClearSpeak", vec![("ClearSpeak_Fractions", "EndFrac")], expr, ", division, 1 halv genom 2 tredjedelar, slut division")?;
163+
test_prefs("sv", "ClearSpeak", vec![("ClearSpeak_Fractions", "EndFrac")], expr, ", division, en halv genom 2 tredjedelar, slut division")?;
164164
test_prefs("sv", "ClearSpeak", vec![("ClearSpeak_Fractions", "GeneralEndFrac")], expr,
165165
"division med täljaren division med täljaren 1; och nämnaren 2; slut division; och nämnaren division med täljaren 2; och nämnaren 3; slut division; slut division")?;
166166
test_prefs("sv", "ClearSpeak", vec![("ClearSpeak_Fractions", "OverEndFrac")], expr,

tests/Languages/sv/ClearSpeak/mroot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ fn simple_fraction_power() -> Result<()> {
157157
<mfrac><mn>1</mn><mn>3</mn></mfrac>
158158
</mroot>
159159
</math>";
160-
test("sv", "ClearSpeak", expr, "roten av grad 1 tredjedel ur x")?;
160+
test("sv", "ClearSpeak", expr, "roten av grad en tredjedel ur x")?;
161161
return Ok(());
162162

163163
}

tests/Languages/sv/ClearSpeak/msup.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn simple_fraction_power() -> Result<()> {
118118
<mfrac><mn>1</mn><mn>3</mn></mfrac>
119119
</msup>
120120
</math>";
121-
test("sv", "ClearSpeak", expr, "x upphöjt till 1 tredjedel")?;
121+
test("sv", "ClearSpeak", expr, "x upphöjt till en tredjedel")?;
122122
return Ok(());
123123

124124
}
@@ -225,7 +225,7 @@ fn nested_number_times_squared() -> Result<()> {
225225
</msup>
226226
</mrow>
227227
</math>";
228-
test_prefs("sv", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Exponents", "Auto")], expr, "e upphöjt till 1 halv x kvadrat")?;
228+
test_prefs("sv", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Exponents", "Auto")], expr, "e upphöjt till en halv x kvadrat")?;
229229
return Ok(());
230230

231231
}
@@ -249,9 +249,9 @@ fn nested_negative_number_times_squared() -> Result<()> {
249249
</msup>
250250
</mrow>
251251
</math>";
252-
test_prefs("sv", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Exponents", "Auto")], expr, "e upphöjt till minus 1 halv x kvadrat")?;
253-
test_prefs("sv", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Exponents", "OrdinalPower")], expr, "e upphöjt till exponenten, minus 1 halv x upphöjt till 2; slut exponent")?;
254-
test_prefs("sv", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Exponents", "AfterPower")], expr, "e upphöjt till exponenten, minus 1 halv x upphöjt till 2; slut exponent")?;
252+
test_prefs("sv", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Exponents", "Auto")], expr, "e upphöjt till minus en halv x kvadrat")?;
253+
test_prefs("sv", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Exponents", "OrdinalPower")], expr, "e upphöjt till exponenten, minus en halv x upphöjt till 2; slut exponent")?;
254+
test_prefs("sv", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Exponents", "AfterPower")], expr, "e upphöjt till exponenten, minus en halv x upphöjt till 2; slut exponent")?;
255255
return Ok(());
256256

257257
}
@@ -353,13 +353,13 @@ fn nested_complex_power() -> Result<()> {
353353
</mrow>
354354
</math>";
355355
test_prefs("sv", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Exponents", "Auto")], expr,
356-
"e upphöjt till exponenten, minus 1 halv gånger; vänster-parentes; division med täljaren; x minus my; och nämnaren sigma; höger-parentes kvadrat, slut exponent")?;
356+
"e upphöjt till exponenten, minus en halv gånger; vänster-parentes; division med täljaren; x minus my; och nämnaren sigma; höger-parentes kvadrat, slut exponent")?;
357357
test_prefs("sv", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Exponents", "Ordinal")], expr,
358-
"e upphöjt till exponenten, minus 1 halv gånger; vänster-parentes; division med täljaren; x minus my; och nämnaren sigma; höger-parentes upphöjt till 2; slut exponent")?;
358+
"e upphöjt till exponenten, minus en halv gånger; vänster-parentes; division med täljaren; x minus my; och nämnaren sigma; höger-parentes upphöjt till 2; slut exponent")?;
359359
test_prefs("sv", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Exponents", "OrdinalPower")], expr,
360-
"e upphöjt till exponenten, minus 1 halv gånger; vänster-parentes; division med täljaren; x minus my; och nämnaren sigma; höger-parentes upphöjt till 2; slut exponent")?;
360+
"e upphöjt till exponenten, minus en halv gånger; vänster-parentes; division med täljaren; x minus my; och nämnaren sigma; höger-parentes upphöjt till 2; slut exponent")?;
361361
test_prefs("sv", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Exponents", "AfterPower")], expr,
362-
"e upphöjt till exponenten, minus 1 halv gånger; vänster-parentes; division med täljaren; x minus my; och nämnaren sigma; höger-parentes upphöjt till 2; slut exponent")?;
362+
"e upphöjt till exponenten, minus en halv gånger; vänster-parentes; division med täljaren; x minus my; och nämnaren sigma; höger-parentes upphöjt till 2; slut exponent")?;
363363
return Ok(());
364364

365365
}

tests/Languages/sv/SimpleSpeak/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ fn no_times_sqrt() -> Result<()> {
314314
<mfrac> <mn>1</mn><mn>2</mn></mfrac>
315315
<mo>)</mo></mrow></mrow>
316316
</mrow></math>";
317-
test("sv", "SimpleSpeak", expr, "2 plus 1 halv")?;
317+
test("sv", "SimpleSpeak", expr, "2 plus en halv")?;
318318
return Ok(());
319319

320320
}

tests/Languages/sv/SimpleSpeak/mfrac.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn common_fraction_half() -> Result<()> {
99
let expr = "<math>
1010
<mfrac> <mn>1</mn> <mn>2</mn> </mfrac>
1111
</math>";
12-
test("sv", "SimpleSpeak", expr, "1 halv")?;
12+
test("sv", "SimpleSpeak", expr, "en halv")?;
1313
return Ok(());
1414

1515
}
@@ -158,7 +158,7 @@ fn mixed_number() -> Result<()> {
158158
<mn>3</mn>
159159
<mfrac> <mn>1</mn> <mn>2</mn> </mfrac>
160160
</math>";
161-
test("sv", "SimpleSpeak", expr, "3 och 1 halv")?;
161+
test("sv", "SimpleSpeak", expr, "3 och en halv")?;
162162
return Ok(());
163163

164164
}
@@ -170,7 +170,7 @@ fn explicit_mixed_number() -> Result<()> {
170170
<mo>&#x2064;</mo>
171171
<mfrac> <mn>1</mn> <mn>8</mn> </mfrac>
172172
</math>";
173-
test("sv", "SimpleSpeak", expr, "3 och 1 åttondel")?;
173+
test("sv", "SimpleSpeak", expr, "3 och en åttondel")?;
174174
return Ok(());
175175

176176
}
@@ -232,7 +232,7 @@ fn nested_simple_fractions() -> Result<()> {
232232
</mfrac>
233233
</mrow>
234234
</math>";
235-
test("sv", "SimpleSpeak", expr, "division, 1 halv, genom, 2 tredjedelar, slut division")?;
235+
test("sv", "SimpleSpeak", expr, "division, en halv, genom, 2 tredjedelar, slut division")?;
236236
return Ok(());
237237

238238
}

tests/Languages/sv/SimpleSpeak/msup.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn simple_fraction_power() -> Result<()> {
102102
<mfrac><mn>1</mn><mn>3</mn></mfrac>
103103
</msup>
104104
</math>";
105-
test("sv", "SimpleSpeak", expr, "x upphöjt till 1 tredjedel")?;
105+
test("sv", "SimpleSpeak", expr, "x upphöjt till en tredjedel")?;
106106
return Ok(());
107107

108108
}
@@ -205,7 +205,7 @@ fn nested_number_times_squared() -> Result<()> {
205205
</msup>
206206
</mrow>
207207
</math>";
208-
test("sv", "SimpleSpeak", expr, "e upphöjt till 1 halv x kvadrat")?;
208+
test("sv", "SimpleSpeak", expr, "e upphöjt till en halv x kvadrat")?;
209209
return Ok(());
210210

211211
}
@@ -229,7 +229,7 @@ fn nested_negative_number_times_squared() -> Result<()> {
229229
</msup>
230230
</mrow>
231231
</math>";
232-
test("sv", "SimpleSpeak", expr, "e upphöjt till minus 1 halv x kvadrat")?;
232+
test("sv", "SimpleSpeak", expr, "e upphöjt till minus en halv x kvadrat")?;
233233
return Ok(());
234234

235235
}
@@ -355,7 +355,7 @@ fn nested_complex_power() -> Result<()> {
355355
</msup>
356356
</mrow>
357357
</math>";
358-
test("sv", "SimpleSpeak", expr, "e upphöjt till minus 1 halv gånger; vänster-parentes; division, x minus my, genom sigma, slut division; höger-parentes kvadrat")?;
358+
test("sv", "SimpleSpeak", expr, "e upphöjt till minus en halv gånger; vänster-parentes; division, x minus my, genom sigma, slut division; höger-parentes kvadrat")?;
359359
return Ok(());
360360

361361
}

0 commit comments

Comments
 (0)