python nltk 中的函数 'bigrams' 不工作
The function 'bigrams' in python nltk not working
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
返回了一个"generator"对象;这是一个 Python 数据类型,类似于列表,但只在需要时创建其元素。如果要将生成器实现为列表,则需要将其显式转换为列表:
>>> list(bigrams(['more', 'is', 'said', 'than', 'done']))
[('more', 'is'), ('is', 'said'), ('said', 'than'), ('than', 'done')]
<generator object bigrams at 0x0000000002E64240>
当此说明出现时,表示您的双字母组已创建并可以显示了。现在,如果您想让它们显示,只需将您的指令输入为:
list(bigrams(['more', 'is', 'said', 'than', 'done']))
这意味着你需要二元组作为列表形式的输出,你将得到:
[('more', 'is'), ('is', 'said'), ('said', 'than'), ('than', 'done')]
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
返回了一个"generator"对象;这是一个 Python 数据类型,类似于列表,但只在需要时创建其元素。如果要将生成器实现为列表,则需要将其显式转换为列表:
>>> list(bigrams(['more', 'is', 'said', 'than', 'done']))
[('more', 'is'), ('is', 'said'), ('said', 'than'), ('than', 'done')]
<generator object bigrams at 0x0000000002E64240>
当此说明出现时,表示您的双字母组已创建并可以显示了。现在,如果您想让它们显示,只需将您的指令输入为:
list(bigrams(['more', 'is', 'said', 'than', 'done']))
这意味着你需要二元组作为列表形式的输出,你将得到:
[('more', 'is'), ('is', 'said'), ('said', 'than'), ('than', 'done')]