Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DE] fix hundred addition #102

Merged
merged 2 commits into from
Nov 28, 2023
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
14 changes: 14 additions & 0 deletions tests/test_text_to_num_de.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def test_text2num_zeroes(self):
self.assertRaises(ValueError, text2num, "fünfzignullzwei", "de")
self.assertRaises(ValueError, text2num, "fünfzigdreinull", "de")

def test_text2num_hundred_addition(self):
self.assertRaises(ValueError, text2num, "achtundachtzig dreihundert", "de")
self.assertRaises(ValueError, text2num, "zwanzig dreihundert", "de")
self.assertRaises(ValueError, text2num, "zwei zwölfhundert", "de")

def test_alpha2digit_integers(self):
source = "fünfundzwanzig Kühe, zwölf Hühner und einhundertfünfundzwanzig kg Kartoffeln."
expected = "25 Kühe, 12 Hühner und 125 kg Kartoffeln."
Expand Down Expand Up @@ -306,3 +311,12 @@ def test_ordinals_false_positives(self):
source = "Dies ist eine Liste oder die Einkaufsliste."
expected = source
self.assertEqual(alpha2digit(source, "de"), expected)

def test_hundred_addition(self):
source = "Zahlen wie vierzig fünfhundert Tausend zweiundzwanzig hundert sind gut."
expected = "Zahlen wie 40 500022 100 sind gut."
self.assertEqual(alpha2digit(source, "de"), expected)

source = "achtundachtzig sieben hundert, acht und achtzig siebenhundert, achtundachtzig sieben hundert, acht und achtzig sieben hundert"
expected = "88 700, 88 700, 88 700, 88 700"
self.assertEqual(alpha2digit(source, "de"), expected)
2 changes: 2 additions & 0 deletions text_to_num/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ def parse(self, text: str) -> bool:
elif (ng[hundred_index - 1] in self.lang.UNITS) or (
ng[hundred_index - 1] in self.lang.STENS
):
if hundred_index - 2 >= 0 and ng[hundred_index - 2] not in self.lang.MULTIPLIERS:
raise ValueError("invalid {} without multiplier: {}".format(STATIC_HUNDRED, repr(ng)))
multiplier = German.NUMBER_DICT_GER[ng[hundred_index - 1]]
equation += "(" + str(multiplier) + " * 100)"
equation_results.append(multiplier * 100)
Expand Down