nltk 中的函数 bigrams 返回以下消息,
即使导入了 nltk 并且它的其他功能仍在运行。有任何想法吗?谢谢。
>>> import nltk
>>> nltk.download()
showing info http://www.nltk.org/nltk_data/
True
>>> from nltk import bigrams
>>> bigrams(['more', 'is', 'said', 'than', 'done'])
<generator object bigrams at 0x0000000002E64240>
请您参考如下方法:
bigrams 函数返回了一个“生成器”对象;这是一种 Python 数据类型,类似于列表,但只在需要时创建其元素。如果要将生成器实现为列表,则需要将其显式转换为列表:
>>> list(bigrams(['more', 'is', 'said', 'than', 'done']))
[('more', 'is'), ('is', 'said'), ('said', 'than'), ('than', 'done')]
