ShailChoksi / text2digits

Converts text such as "twenty three" to number/digit "23" in any sentence
MIT License
66 stars 22 forks source link

Ordinal followed by number handled incorrectly #30

Closed jatowler closed 3 years ago

jatowler commented 4 years ago

Consider the phrase, "The first seven cows."

Expected output: "The 1st 7 cows." Actual output:

add_ordinal_ending == True

>>> from text2digits import text2digits
>>> t2d = text2digits.Text2Digits(add_ordinal_ending=True)
>>> t2d.convert('The first seven cows')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/text2digits/text2digits.py", line 51, in convert
    text = self._parse(tokens)
  File "/usr/local/lib/python3.7/site-packages/text2digits/text2digits.py", line 130, in _parse
    text += token.ordinal_ending
TypeError: can only concatenate str (not "NoneType") to str

add_ordinal_ending == False

>>> from text2digits import text2digits
>>> t2d = text2digits.Text2Digits(add_ordinal_ending=False)
>>> t2d.convert('The first seven cows')
'The 17 cows'