python nltk中的功能"bigrams"不起作用 [英] The function 'bigrams' in python nltk not working

查看:115
本文介绍了python nltk中的功能"bigrams"不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自nltk的bigrams函数返回以下消息,

The function bigrams from nltk is returning the following message,

即使已导入nltk,并且其他功能正在运行.有任何想法吗?谢谢.

even though nltk is imported and other functions from it are working. Any ideas? Thanks.

>>> 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,但仅在需要时创建其元素.如果要将生成器实现为列表,则需要将其显式转换为列表:

The function bigrams has returned a "generator" object; this is a Python data type which is like a List but which only creates its elements as they are needed. If you want to realise a generator as a list, you need to explicitly cast it as a list:

>>> list(bigrams(['more', 'is', 'said', 'than', 'done']))
[('more', 'is'), ('is', 'said'), ('said', 'than'), ('than', 'done')]

这篇关于python nltk中的功能"bigrams"不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆