I have spent hours trying to get identify collocations in my data. When I run the NLTK example
text4.collocation_list()
...it works. But when I directly thereafter try to apply it to my own data, I get the following error message:
Traceback (most recent call last): File "<pyshell#95>", line 1, in Tokens.collocation_list() AttributeError: 'list' object has no attribute 'collocation_list'
This is my script:
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()