我开发了一个从文本中提取护照号码的简单工具(例如,输入 – ‘one hundred thirty five thirty five zero zero’,输出 – 1353500)
但是,如何过滤掉像’ok’、’mhm’这样的无关词汇呢?
例如,人类可能会说’ok it is 1353500’,而机器人可能会从’ok’、’it’、’is’中提取一些毫无意义的数字,这是不可取的。问题是如何忽略这些非数字词汇?
回答:
这些基本上是停用词。要删除它们,你需要下载nltk包,其中包含了所有英语停用词
from nltk.corpus import stopwordsw = stopwords.words('english')#假设data是一个包含你句子的字符串for word in w: if word in data: data.replace(word,'')