Я использую Google Colab для работы над сценарием, который я изучаю с помощью видео. К сожалению, я получаю ошибку, хотя следуя инструкциям видео.
sentences_tokens=nltk.sent_tokenize(allParagraphContent_cleanedData)
words_tokens=nltk.word_tokenize(allParagraphContent_cleanedData)
вызывает проблему. Обе линии. Я пробовал каждый из них в одиночку, в Python 3 (который я использую в основном). Вот импортированные библиотеки:
from urllib import request
from bs4 import BeautifulSoup as bs
import re
import nltk
import heapq
Я получаю ошибку:
---------------------------------------------------------------------------
LookupError Traceback (most recent call last)
<ipython-input-13-2467ae276de5> in <module>()
26 allParagraphContent_cleanedData=re.sub(r'\s+','',allParagraphContent_cleanedData)
27
---> 28 sentences_tokens=nltk.sent_tokenize(allParagraphContent_cleanedData)
29 words_tokens=nltk.word_tokenize(allParagraphContent_cleanedData)
30
Откровенно говоря, я не понимаю ошибку.
В чем проблема что я не вижу?
- Вот весь код
from urllib import request
from bs4 import BeautifulSoup as bs
import re
import nltk
import heapq
url="https://en.wikipedia.org/wiki/Machine_learning"
allParagraphContent = ""
htmlDoc=request.urlopen(url)
soupObject=bs(htmlDoc,'html.parser')
for paragraphContent in paragraphContents:
allParagraphContent += paragraphContent.text
allParagraphContent_cleanerData=re.sub(r'\[0-9]*\]','',allParagraphContent)
allParagraphContent_cleanedData=re.sub(r'\s+','',allParagraphContent_cleanerData)
allParagraphContent_cleanedData=re.sub(r'[^a-zA-Z]','',allParagraphContent_cleanedData)
allParagraphContent_cleanedData=re.sub(r'\s+','',allParagraphContent_cleanedData)
sentences_tokens=nltk.sent_tokenize(allParagraphContent_cleanedData)
words_tokens=nltk.word_tokenize(allParagraphContent_cleanedData)
Решение: добавление nltk.download("popular")
после import nltk