Skip to content

Commit

Permalink
FIX: Replace each big prefix multiple times. (#9)
Browse files Browse the repository at this point in the history
If a big prefix (million, hundred, thousand) occurs more than once in a
string, only its first occurence gets replaced with the corresponding number. Fixed that.
  • Loading branch information
jaidevd authored Mar 25, 2021
1 parent f15855e commit b179988
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion numerizer/numerizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def _repl_big_prefixes(m):
except IndexError:
repl = str(v)
return repl
s = re.sub(pat, _repl_big_prefixes, s, count=1)
s = re.sub(pat, _repl_big_prefixes, s)
s = andition(s)
return s

Expand Down
17 changes: 15 additions & 2 deletions test_numerize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from numerizer import numerize
from numerizer import numerizer as num
numerize = num.numerize


def test_init():
Expand All @@ -12,7 +13,7 @@ def test_case_insensitive():
assert numerize('Ninety Nine') == '99'


def test_hyenated():
def test_hyphenated():
assert numerize('forty-two') == '42'


Expand Down Expand Up @@ -209,3 +210,15 @@ def test_bias_fractional():
# bias='fractional')
# assert 'the 1st second 1/3' == numerize('the first second third',
# bias='fractional')


def test_numerize_big_prefixes():
s = "two hundred and twenty five thousand seven hundred"
s = num.preprocess(s)
s = num.numerize_numerals(s)
assert num.numerize_big_prefixes(s) == '<num>225700'


def test_misc():
assert numerize(
'two hundred twenty five thousand seven hundred and fifty-five') == '225755'

0 comments on commit b179988

Please sign in to comment.