私はPythonが初めてで、独自のコーパスをインポートして、テキスト内のコロケーションを見つけようとしています。Python 3.7.5 を使用しています。バード、クライン、ローパーの教科書の指示に従った。
ただし、コーパス全体で「collocation_list」を使用しようとすると、環境は「「ConcatenatedCorpusView」オブジェクトには属性「collocation_list」がありません」を返し、別のテキストで使用すると「「StreamBackedCorpusView」オブジェクトには属性がありません」 collocation_list'".
コーパステキストでコロケーションを見つけるにはどうすればよいですか?
「import nltk.collocations」を呼び出してみましたが、もちろんうまくいきませんでした...
>>> 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'
このような結果が得られれば素晴らしいことです (上記の教科書の例)。
>>> 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']
どんな助けにも感謝します...