import nltk
from nltk.corpus import brown
brown_tagged_sents = brown.tagged_sents(categories='news')
((x[1],y[1],z[0],z[1])
for sent in brown_tagged_sents
for x,y,z in nltk.trigrams(sent))
cfd = nltk.ConditionalFreqDist(
((x[1],y[1],z[0],z[1])
for sent in brown_tagged_sents
for x,y,z in nltk.trigrams(sent))
)
会出现上面的代码:
Traceback (most recent call last):
File "/Users/shike/Desktop/textprocess/nltktest.py", line 10, in <module>
for sent in brown_tagged_sents
File "/usr/local/lib/python3.6/site-packages/nltk/probability.py", line
1803, in __init__
for (cond, sample) in cond_samples:
ValueError: too many values to unpack (expected 2)
该列表理解
((x[1],y[1],z[0],z[1])
for sent in brown_tagged_sents
for x,y,z in nltk.trigrams(sent))
可以单独工作,但是当它用作参数时会出错。我仍然不知道为什么。所有代码均在 Python3 中测试。
慕姐8265434
斯蒂芬大帝
相关分类