I'm new in Python and try to import my own corpus to find collocations in its texts. I'm using Python 3.7.5. and followed instructions of the textbook by Bird, Klein and Loper.
However, when I try to use "collocation_list" on the whole corpus the environment returns "'ConcatenatedCorpusView' object has no attribute 'collocation_list'", and when I use it on a separate text then it's "'StreamBackedCorpusView' object has no attribute 'collocation_list'".
What should I do to find collocations in the corpus texts?
I tried to call "import nltk.collocations", but it didn't work, of course...
>>> from nltk.corpus import PlaintextCorpusReader
>>> eng_corpus_root = 'D:\Corpus\EN'
>>> eng_corpus = PlaintextCorpusReader(eng_corpus_root, '.*')
>>> eng = eng_corpus.words()
>>> eng.collocation_list()
Traceback (most recent call last):
File "<pyshell#39>", line 1, in <module>
eng.collocation_list()
AttributeError: 'ConcatenatedCorpusView' object has no attribute 'collocation_list'
>>> eng1 = eng_corpus.words('CNN/2019.10.18_EN_CNN 2.txt')
>>> eng1.collocation_list()
Traceback (most recent call last):
File "<pyshell#68>", line 1, in <module>
eng1.collocation_list()
AttributeError: 'StreamBackedCorpusView' object has no attribute 'collocation_list'
Would be great if I could have the results like this (an example from the textbook mentioned above).
>>> from nltk.book import *
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
>>> text4.collocation_list()
['United States', 'fellow citizens', 'four years', 'years ago', 'Federal Government', 'General Government', 'American people', 'Vice President', 'God bless', 'Chief Justice', 'Old World', 'Almighty God', 'Fellow citizens', 'Chief Magistrate', 'every citizen', 'one another', 'fellow Americans', 'Indian tribes', 'public debt', 'foreign nations']
Would be grateful for any help...