allo-media / text2num

Parse and convert numbers written in French, English, Spanish, Portuguese, German and Catalan into their digit representation.
https://text2num.readthedocs.io
MIT License
102 stars 47 forks source link

[FR] french ordinals throwing errors #84

Closed gweber2 closed 1 year ago

gweber2 commented 1 year ago

Hi,

french ordinals throw errors although they are dealt with in the code, is there a mistake or am i doing something wrong?

thank you


ValueError Traceback (most recent call last)

in ----> 1 text2num("premier", "fr")

/usr/local/lib/python3.8/dist-packages/text_to_num/transforms.py in text2num(text, lang, relaxed) 85 tokens = list(dropwhile(lambda x: x in language.ZERO, text.split())) 86 if not all(num_parser.push(word, ahead) for word, ahead in look_ahead(tokens)): ---> 87 raise ValueError("invalid literal for text2num: {}".format(repr(text))) 88 89 return num_parser.value

ValueError: invalid literal for text2num: 'premier'

rtxm commented 1 year ago

text2num only convert valid intergers. Premier is not an integer. What you want is alpha2digit:

>>> alpha2digit("premier", "fr", ordinal_threshold=0)
"1er"