【发布时间】:2020-10-09 10:11:19
【问题描述】:
我最近一直在开发一个程序,我想添加一个功能来接收用户语音,例如“显示我接下来五(或 5)天的日程安排”或类似的内容,然后提取数字“五或 5”作为数字并在代码的不同部分使用它来从谷歌日历请求数据,谷歌部分大部分已完成,但我如何获取它来提取诸如“五”之类的数字或基于字母的数字,我早些时候在环顾四周时发现了这段代码,它只返回真或假,我不知道如何让它返回实际数字,非常感谢您的帮助!
import nltk
text = "Is there a one two three in there?"
def existence_of_numeric_data(text):
text=nltk.word_tokenize(text)
pos = nltk.pos_tag(text)
count = 0
for i in range(len(pos)):
word , pos_tag = pos[i]
if pos_tag == 'CD':
return True
return False
print(existence_of_numeric_data(text))
有没有办法让这个版本以整数格式发布数字?比如说
字符串显示“显示我接下来五天的日程安排” 它会将数字“5”作为单独的整数返回
【问题讨论】:
标签: python numbers integer nltk