将文本数字转换成字符串中的数字的小库;自定义的
text2digits-custom的Python项目详细描述
免责声明和确认
此代码从https://github.com/ShailChoksi/text2digits派生 他是源代码的原始作者和维护者。感谢您的贡献。 这是一个定制的fork,用于特定的用例,在原始repo的基础上进行小的更改。在
安装
pip3 install text2digits_custom
使用
只有Python 3!在
^{pr2}$它可以处理各种短语。口语/非正式和正式语言:
"A random string" -> 'A random string'
"I am thirty six years old with a child that is four. I would like to get him four cars!" -> 'I am 36 years old with a child that is 4. I would like to get him 4 cars!'
"I was born in twenty ten" -> 'I was born in 2010'
"I was born in nineteen sixty four" -> 'I was born in 1964'
"I am the fourth cousin" -> 'I am the 4 cousin'
"I am twenty nine" -> 'I am 29'
"it was twenty ten and was negative thirty seven degrees" -> 'it was 2010 and was negative 37 degrees'
"thirty twenty one" -> '3021'
"one thousand six hundred sixty six" -> '1666'
"one thousand and six hundred and sixty six" -> '1666'
"sixteen sixty six" -> '1666'
"eleven hundred twelve" -> '1112'
"Sixteen and seven" -> '16 and 7'
"twenty ten and twenty one" -> '2010 and 21'
"I was born in nineteen ninety two and am twenty six years old!" -> 'I was born in 1992 and am 26 years old!'
"three forty five" -> '345'
如果使用Alexa/Lex将音频转换为文本,并且必须将文本转换为数字,我发现这很有用。在
改进/问题
- 仍然需要添加对十进制数的支持
- 需要添加对负数的支持
致谢
我在这里大量使用了SO答案中的代码:https://stackoverflow.com/questions/493174/is-there-a-way-to-convert-number-words-to-integers 不断改进
- 项目
标签: