python nltk nltk_data 离线安装,chatterbot

离线数据包下载地址: https://codeload.github.com/nltk/nltk_data/zip/gh-pages
unzip nltk_data-gh-pages.zip
cd nltk_data-gh-pages/packages/
cp -r * ~/nltk_data
批量解压 数据包:  ls *.zip | xargs -n1 unzip -o -P infected

chatterbot  每次启动执行 nltk_download_corpus  
[nltk_data] Error loading stopwords: ]
[nltk_data]     Operation timed out>
[nltk_data] Error loading averaged_perceptron_tagger: <urlopen error
[nltk_data]     [Errno 60] Operation timed out>

chatterbot里stopwords在nltk-data目录下、上述下载方式stopwords在nltk-data下的corpora目录

由于目录结构问题导致每次下载 stopwords、wordnet、averaged_perceptron_tagger、vader_lexicon

而网络问题导致各种timed out

修改文件 .pyenv/versions/3.7.4/lib/python3.7/site-packages/chatterbot/utils.py  
 

def download_nltk_stopwords():
    """
    Download required NLTK stopwords corpus if it has not already been downloaded.
    """
    nltk_download_corpus('corpora/stopwords')

def download_nltk_wordnet():
    """
    Download required NLTK corpora if they have not already been downloaded.
    """
    nltk_download_corpus('corpora/wordnet')

def download_nltk_averaged_perceptron_tagger():
    """
    Download the NLTK averaged perceptron tagger that is required for this algorithm
    to run only if the corpora has not already been downloaded.
    """
    nltk_download_corpus('taggers/averaged_perceptron_tagger')

def download_nltk_vader_lexicon():
    """
    Download the NLTK vader lexicon for sentiment analysis
    that is required for this algorithm to run.
    """
    nltk_download_corpus('sentiment/vader_lexicon')

 

转载于:https://www.cnblogs.com/dockers/p/11414881.html

你可能感兴趣的:(python)