Skip to main content
 首页 » 编程设计

python之如何将法语单词转换为整数

2024年11月01日10mfryf

有关将英语单词转换为数字的其他问题已得到解答,特别是使用库 w2n或其他自定义算法。

但是我不知道如何将法语(或一般来说,任何语言的)单词转换为整数,例如:

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

我的法语不是很流利,但它肯定不只是试图翻译 https://github.com/akshaynagpal/w2n/blob/master/word2number/w2n.py 中的文字。对吧?

请您参考如下方法:

只是用谷歌搜索了一下,发现了一个名称非常相似的项目,名为 text2num那:

provides functions and parser classes for:

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

他们的演示:

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

返回 95,这似乎是正确的