【发布时间】:2021-09-07 09:54:10
【问题描述】:
我想通过计算二元组来分析文本。不幸的是,我的文本中有很多重复的单词(例如:hello hello),我不想被视为二元组。
我的代码如下:
b = nltk.collocations.BigramCollocationFinder.from_words('this this is is a a test test'.split())
b.ngram_fd.keys()
返回:
>> dict_keys([('this', 'this'), ('this', 'is'), ('is', 'is'), ('is', 'a'), ('a', 'a'), ('a', 'test'), ('test', 'test')])
但我希望输出为:
>> [('a', 'test'), ('is', 'a'), ('this', 'is')]
你有什么建议,也使用不同的库吗? 预先感谢您的任何帮助。 弗朗西斯卡
【问题讨论】:
标签: python nltk word-cloud countvectorizer