我花了几个小时试图在我的数据中识别搭配。当我运行 NLTK 示例时
text4.collocation_list()
...有用。但是当我此后直接尝试将其应用于我自己的数据时,我收到以下错误消息:
回溯(最后一次调用):文件“<pyshell#95>”,第 1 行,在 Tokens.collocation_list() 中 AttributeError:'list' 对象没有属性 'collocation_list'
这是我的脚本:
File1 = open("/Applications/Python 3.9/StormZuluStory.txt",encoding="Latin-1")
StormZuluStory=File1.read()
File2 = open("/Applications/Python 3.9/StormZuluPOSStory.txt",encoding="Latin-1")
StormZuluPOSStory=File2.read()
#print (StormZuluStory)
#print (StormZuluPOSStory)
import nltk
nltk.download()
from nltk.book import *
from nltk import word_tokenize
Tokens = word_tokenize(StormZuluStory)
StormZuluStory.split()
fdist = FreqDist(Tokens)
#print(fdist)
Freq1 = fdist.most_common(30)
print (Freq1)
Plot1 = fdist.plot(30,cumulative=True)
Tokens.collocation_list()