-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from rhasspy/synesthesiam-20241024-multiple-rul…
…esets Use all available rulesets for formatting purposes
- Loading branch information
Showing
13 changed files
with
253 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,48 @@ | ||
from unicode_rbnf import RbnfEngine, RulesetName | ||
from unicode_rbnf import RbnfEngine, FormatPurpose | ||
|
||
|
||
def test_english(): | ||
engine = RbnfEngine.for_language("en") | ||
|
||
assert engine.format_number(7) == "seven" | ||
assert engine.format_number(15) == "fifteen" | ||
assert engine.format_number(42) == "forty-two" | ||
assert engine.format_number(100) == "one hundred" | ||
assert engine.format_number(143) == "one hundred forty-three" | ||
assert engine.format_number(1000) == "one thousand" | ||
assert engine.format_number(1234) == "one thousand two hundred thirty-four" | ||
assert engine.format_number(3144) == "three thousand one hundred forty-four" | ||
assert engine.format_number(10000) == "ten thousand" | ||
assert engine.format_number(83145) == "eighty-three thousand one hundred forty-five" | ||
assert engine.format_number(100000) == "one hundred thousand" | ||
assert engine.format_number(7).text == "seven" | ||
assert engine.format_number(15).text == "fifteen" | ||
assert engine.format_number(42).text == "forty-two" | ||
assert engine.format_number(100).text == "one hundred" | ||
assert engine.format_number(143).text == "one hundred forty-three" | ||
assert engine.format_number(1000).text == "one thousand" | ||
assert engine.format_number(1234).text == "one thousand two hundred thirty-four" | ||
assert engine.format_number(3144).text == "three thousand one hundred forty-four" | ||
assert engine.format_number(10000).text == "ten thousand" | ||
assert ( | ||
engine.format_number(683146) | ||
engine.format_number(83145).text | ||
== "eighty-three thousand one hundred forty-five" | ||
) | ||
|
||
assert engine.format_number(100000).text == "one hundred thousand" | ||
assert ( | ||
engine.format_number(683146).text | ||
== "six hundred eighty-three thousand one hundred forty-six" | ||
) | ||
assert engine.format_number(1000000) == "one million" | ||
assert engine.format_number(10000000) == "ten million" | ||
assert engine.format_number(100000000) == "one hundred million" | ||
assert engine.format_number(1000000000) == "one billion" | ||
|
||
assert engine.format_number(1000000).text == "one million" | ||
assert engine.format_number(10000000).text == "ten million" | ||
assert engine.format_number(100000000).text == "one hundred million" | ||
assert engine.format_number(1000000000).text == "one billion" | ||
|
||
# Special rules | ||
assert engine.format_number(-1) == "minus one" | ||
assert engine.format_number(float("nan")) == "not a number" | ||
assert engine.format_number(float("inf")) == "infinite" | ||
assert engine.format_number(-1).text == "minus one" | ||
assert engine.format_number(float("nan")).text == "not a number" | ||
assert engine.format_number(float("inf")).text == "infinite" | ||
|
||
# Fractions | ||
assert ( | ||
engine.format_number(3.14, ruleset_name=RulesetName.CARDINAL) | ||
== "three point fourteen" | ||
) | ||
assert ( | ||
engine.format_number("5.3", ruleset_name=RulesetName.CARDINAL) | ||
== "five point three" | ||
) | ||
assert engine.format_number(3.14).text == "three point fourteen" | ||
assert engine.format_number("5.3").text == "five point three" | ||
|
||
# Ordinals | ||
assert engine.format_number(20, ruleset_name=RulesetName.ORDINAL) == "twentieth" | ||
assert engine.format_number(30, ruleset_name=RulesetName.ORDINAL) == "thirtieth" | ||
assert engine.format_number(99, ruleset_name=RulesetName.ORDINAL) == "ninety-ninth" | ||
assert engine.format_number(11, ruleset_name=RulesetName.ORDINAL) == "eleventh" | ||
assert engine.format_number(20, FormatPurpose.ORDINAL).text == "twentieth" | ||
assert engine.format_number(30, FormatPurpose.ORDINAL).text == "thirtieth" | ||
assert engine.format_number(99, FormatPurpose.ORDINAL).text == "ninety-ninth" | ||
assert engine.format_number(11, FormatPurpose.ORDINAL).text == "eleventh" | ||
|
||
# Years | ||
assert ( | ||
engine.format_number(1999, ruleset_name=RulesetName.YEAR) | ||
== "nineteen ninety-nine" | ||
) | ||
assert engine.format_number(1999, FormatPurpose.YEAR).text == "nineteen ninety-nine" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
from unicode_rbnf import RbnfEngine, RulesetName | ||
from unicode_rbnf import RbnfEngine | ||
|
||
|
||
def test_french(): | ||
engine = RbnfEngine.for_language("fr") | ||
assert engine.format_number(88) == "quatre-vingt-huit" | ||
assert engine.format_number(88).text == "quatre-vingt-huit" | ||
|
||
# All genders | ||
assert set(engine.format_number(1).text_by_ruleset.values()) == { | ||
"un", | ||
"une", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.3.0 | ||
2.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
from pathlib import Path | ||
|
||
from .engine import RbnfEngine, RulesetName | ||
from .engine import FormatOptions, FormatPurpose, FormatResult, RbnfEngine | ||
|
||
_DIR = Path(__file__).parent | ||
|
||
__version__ = (_DIR / "VERSION").read_text(encoding="utf-8").strip() | ||
|
||
__all__ = [ | ||
"__version__", | ||
"FormatOptions", | ||
"FormatPurpose", | ||
"FormatResult", | ||
"RbnfEngine", | ||
"RulesetName", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.