将文本数字转换成字符串中的数字的小库;自定义的

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 不断改进

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
来自Oozie Java Jobs的电子邮件   泛型Java映射。具有有界通配符的getOrDefault   java如何制作定制的Swing容器?   java断言使用正则表达式重新启动响应体   安卓 java正则表达式查找字符串中的所有空格   java循环语法不起作用   使用spring4@Transactional时,java事务不起作用   java三桨乒乓球命中检测   java Camera 2 Api错误不拍照的错误   java使用ServletContext从war外部读取Hibernate属性   性能如何禁用Java垃圾回收器?   如何通过MySQL触发器执行外部java函数?   使用Ecfbittorent下载torrent时出现java NegativeArraySizeException   java Android arraylist因迭代而崩溃   MyBatis中的java Delete查询没有删除任何内容