问题
i tried to retrieve collocations with NLTK, yet i get an error. I used built-in gutenberg corpus
I wrote:
alice = nltk.corpus.gutenberg.fileids()[7]
al = nltk.corpus.gutenberg.words(alice)
al_text = nltk.Text(al)
al_text.collocations(25)
i got:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-16-a6905d575410> in <module>
----> 1 al_text.collocations(25)
C:\ProgramData\Anaconda3\lib\site-packages\nltk\text.py in collocations(self, num, window_size)
442
443 collocation_strings = [
--> 444 w1 + " " + w2 for w1, w2 in self.collocation_list(num, window_size)
445 ]
446 print(tokenwrap(collocation_strings, separator="; "))
C:\ProgramData\Anaconda3\lib\site-packages\nltk\text.py in <listcomp>(.0)
442
443 collocation_strings = [
--> 444 w1 + " " + w2 for w1, w2 in self.collocation_list(num, window_size)
445 ]
446 print(tokenwrap(collocation_strings, separator="; "))
ValueError: too many values to unpack (expected 2)
However, when i use i.e other functions that uses nltk,tetx():
al_text.concordance('Beautiful', width=39, lines=50)
Everything works correctly.
Does anyone know where is a problem? I tried using different numbers, etc, yet I can't localize it
UPDATE
Found a solution:
al_text.collocation_list()
Apparently collocations is buggy: Github
来源:https://stackoverflow.com/questions/59266387/problem-with-nltk-collocations-too-many-values-to-unpack-expected-2