【发布时间】:2016-10-05 16:26:39
【问题描述】:
我正在尝试生成给定句子的二元列表,例如,如果我输入,
To be or not to be
我要程序生成
to be, be or, or not, not to, to be
我尝试了以下代码,但只是给了我
<generator object bigrams at 0x0000000009231360>
这是我的代码:
import nltk
bigrm = nltk.bigrams(text)
print(bigrm)
那么我怎样才能得到我想要的呢?我想要一个像上面这样的单词组合的列表(to be, be or, or not, not to, to be)。
【问题讨论】:
-
试试:
list(bigrm) -
只是因为我喜欢代码:Here 是一个不错的独立于 NLTK 的 bigram-oneliner。