【发布时间】:2016-06-08 03:24:59
【问题描述】:
我是 nltk 的新手,我正在使用 python。 我将字符串作为 Bigrams 的输入。当我展示这个项目时。我把每个字符都当作一个词。
import nltk
string = "Batman Superman"
bigram = nltk.bigrams(string)
print bigram.item()
[('B','a'),('a','t'),('t','m'),('m','a'),('a','n'),('n',' '),(' ','S'),
('S','u'),('u','p'),('p','e'),('e','r'),('r','m')('m','a'),('a','n')]
但我希望输出为 [('Batman','Superman')] 请告诉我如何仅将字符串作为输入来获得此输出 Bigrams 函数但不将列表作为输入。
【问题讨论】:
-
你必须先标记你的字符串。参考here
标签: python