pythonでnltkをimportして、単語の共起の結果を出力するプログラムを作成しようとしました。
そのため、ネットに上がっていたサンプルプログラムを動かそうとしたのですが、エラーが
出てしまい実行が出来ません。
python
1import nltk 2f = open('obama_inaugural_transcript.txt') 3raw = f.read() 4tokens = nltk.word_tokenize(raw) #テキストをトークンに分割 5print(tokens) 6 7<obama_inaugural_transcript.txtの中身> 8'I stand here today humbled by the task before us, grateful for the trust you've bestowed, mindful of the sacrifices borne by our ancestors.\n\n I thank President Bush for his service to our nation 9 10<実行結果> 11Traceback (most recent call last): 12 File "C:\atom\sample.py", line 3, in <module> 13 tokens = nltk.word_tokenize(raw) 14 File "C:\Anaconda\lib\site-packages\nltk\tokenize\__init__.py", line 130, in word_tokenize 15 sentences = [text] if preserve_line else sent_tokenize(text, language) 16 File "C:\Anaconda\lib\site-packages\nltk\tokenize\__init__.py", line 96, in sent_tokenize 17 tokenizer = load('tokenizers/punkt/{0}.pickle'.format(language)) 18 File "C:\Anaconda\lib\site-packages\nltk\data.py", line 814, in load 19 opened_resource = _open(resource_url) 20 File "C:\Anaconda\lib\site-packages\nltk\data.py", line 932, in _open 21 return find(path_, path + ['']).open() 22 File "C:\Anaconda\lib\site-packages\nltk\data.py", line 653, in find 23 raise LookupError(resource_not_found) 24LookupError: 25********************************************************************** 26 Resource 'tokenizers/punkt/english.pickle' not found. Please 27 use the NLTK Downloader to obtain the resource: >>> 28 nltk.download() 29 Searched in: 30 - 'C:\Users\�_��/nltk_data' 31 - 'C:\nltk_data' 32 - 'D:\nltk_data' 33 - 'E:\nltk_data' 34 - 'C:\Anaconda\nltk_data' 35 - 'C:\Anaconda\lib\nltk_data' 36 - 'C:\Users\�_��\AppData\Roaming\nltk_data' 37 - '' 38**********************************************************************
実行できると下記が出力される
['I','stand','here','today','humbled','by','the','task','before','us',',','grateful','for','the','trust','you',"'ve",'bestowed',',','mindful','of','the','sacrifices','borne','by','our','ancestors','.','I','thank','President','Bush','for','his','service','to','our','nation']
長々と申し訳ありませんが、宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/20 01:50
2018/06/20 01:58