您好,登錄后才能下訂單哦!
最為小菜,最近初次了解NLTK,因此想學一下代碼如下
nltk.tokenize import sent_tokenize
mytext = "Hello Mr. Adam, how are you? I hope everything is going well. Today is a good day, see you dude."
sent_tokenize(mytext)
出現報錯,
Resource punkt not found.
Please use the NLTK Downloader to obtain the resource:
import nltk
nltk.download('punkt')
但實際上是存在的
仔細一看,
錯誤中Search在C盤下C:\Users\Hu/nltk_data
Searched in:
- 'C:\Users\Hu/nltk_data'
- 'D:\ProgramData\Miniconda3\envs\tensorflow\nltk_data'
- 'D:\ProgramData\Miniconda3\envs\tensorflow\share\nltk_data'
- 'D:\ProgramData\Miniconda3\envs\tensorflow\lib\nltk_data'
- 'C:\Users\Hu\AppData\Roaming\nltk_data'
- 'C:\nltk_data'
- 'D:\nltk_data'
- 'E:\nltk_data'
- ''
查看源碼可以看見
tokenizer=load('tokenizers/punkt/{0}.pickle'.format(language))
在看load來自nltk下的data
def load(
resource_url,
format='auto',
cache=True,
verbose=False,
logic_parser=None,
fstruct_reader=None,
encoding=None,
從這里,我的第一反應是resource_url,因此迅速找到下文發現
resource_url = normalize_resource_url(resource_url)
resource_url = add_py3_data(resource_url)
先看到被屏蔽的說明文字windows = sys.platform.startswith('win')
于是我找到前文
path += [
os.path.join(sys.prefix, str('nltk_data')),
os.path.join(sys.prefix, str('share'), str('nltk_data')),
os.path.join(sys.prefix, str('lib'), str('nltk_data')),
os.path.join(os.environ.get(str('APPDATA'), str('C:\')), str('nltk_data')),
str(r'C:\nltk_data'),
str(r'D:\nltk_data'),
str(r'E:\nltk_data'),
所以我改了nltk.data.path = ['D:\Users/Hu/AppData/Roaming/nltk_data']
OK運行成功
['Hello Mr. Adam, how are you?', 'I hope everything is going well.', 'Today is a good day, see you dude.']
Process finished with exit code 0
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。