1

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()
Lindsay
  • 25
  • 2
  • `word_tokenize` returns `list` (via `findall`), and `list` has no `collocation_list` method [look](https://github.com/nltk/nltk/blob/2742fba034b8a320ab91b35df5e6a14c186de01c/nltk/tokenize/punkt.py#L248) – 0dminnimda Aug 30 '21 at 21:34
  • Thank you so much!!!! With your help, I fixed it...and learnt something important :-) – Lindsay Aug 31 '21 at 07:57

1 Answers1

0

The problem is that word_tokenize returns list (via findall), and list does not have a collocation_list method look.
You probably wanted to use another function that would supposedly return Tokens that have a collocation_list method.

0dminnimda
  • 1,242
  • 3
  • 12
  • 29
  • @Lindsay, if my comment helped you that much, I think you won't mind if I turn this into an answer, and then, please, [vote up and mark the answer as a solution](https://stackoverflow.com/help/someone-answers) – 0dminnimda Aug 31 '21 at 08:04