我试图用 NLTK 检索搭配,但出现错误。我使用了内置的古腾堡语料库
我写:
alice = nltk.corpus.gutenberg.fileids()[7]
al = nltk.corpus.gutenberg.words(alice)
al_text = nltk.Text(al)
al_text.collocations(25)
Run Code Online (Sandbox Code Playgroud)
我有:
---------------------------------------------------------------------------
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)
Run Code Online (Sandbox Code Playgroud)
但是,当我使用 ie 其他使用 nltk,tetx() 的函数时:
al_text.concordance('Beautiful', width=39, lines=50)
Run Code Online (Sandbox Code Playgroud)
一切正常。
有谁知道问题出在哪里?我尝试使用不同的数字等,但我无法对其进行本地化
更新
找到了解决办法:
al_text.collocation_list()
Run Code Online (Sandbox Code Playgroud)
显然搭配有问题:Github
| 归档时间: |
|
| 查看次数: |
1310 次 |
| 最近记录: |