python - 从自由文本中提取购物 list

标签 python nlp nltk

我正在寻找一个 python 库/算法/论文来从自由文本中提取杂货列表。

例如:

"One salad and two beers"

应转换为:

{'salad':1, 'beer': 2}

最佳答案

In [1]: from word2number import w2n
In [2]: print w2n.word_to_num("One")
1
In [3]: print w2n.word_to_num("Two")
2
In [4]: print w2n.word_to_num("Thirty five")
35

您可以使用此包和您可以根据需要实现的其他内容转换为数字。

安装这个包。

pip install word2number

更新

你可以这样实现。

from word2number import w2n
result = {}
input = "One salad and two beers"
b = input.split()
for i in b:
    if type(w2n.word_to_num(i)) is int:
        result[b[b.index(i)+1]] = w2n.word_to_num(i)

结果

{'beers': 2, 'salad': 1}

关于python - 从自由文本中提取购物 list ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38419395/

相关文章:

python - 使用 Python 从 epub 中提取文本

Python NLTK Ngrams 错误

python - Cygwin 上的 Pyscripter

nlp - 给定 100,000 个单词到音素的映射,如何在音素边界上分割原始单词?

c# - 基于词频的最大编辑距离和建议

python - NLTK wordnet 接口(interface)中的第 0 个同义词集

python - 如何在 Anaconda 中安装 nltk_contrib

PyCharm 上的 python3 导入问题

Java什么都不做

python - 将逻辑门转换为 cnf python