Search code examples
pythonfrench

How to convert French words to integers?


Other questions have been answered regarding converting English words to numbers, particularly using the library w2n or other custom algorithms.

However I don't know how to convert French (or generically speaking, any language's) words to integers, such as:

>>> word_to_number('quarante-quatre')
44

I'm not a fluent speaker of French, but it's certainly not just trying to translate the words in https://github.com/akshaynagpal/w2n/blob/master/word2number/w2n.py right?


Solution

  • just googled a bit and found a very similarly named project called text2num that:

    provides functions and parser classes for:

    • parsing numbers expressed as words in French and convert them to integer values;

    their demo:

    from text_to_num import text2num
    text2num('quatre-vingt-quinze')
    

    gives 95 back, which seems about right