Skip to content

Commit

Permalink
Merge pull request #102 from Kakadus/fix-hundred-addition
Browse files Browse the repository at this point in the history
[DE] fix hundred addition
  • Loading branch information
rtxm authored Nov 28, 2023
2 parents 6d173a8 + 16f91bd commit 95b983d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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

0 comments on commit 95b983d

Please sign in to comment.