#!/usr/bin/env python
# coding=utf-8
"""
:author: Konrad Podlawski <kpodlawski@kretstudios.pl>
"""
from chatterbot import ChatBot

def nltk_download_corpus(corpus_name):
    """
    Download the specified NLTK corpus file
    unless it has already been downloaded.

    Returns True if the corpus needed to be downloaded.
    """
    from nltk.data import find
    from nltk import download

    # Download the wordnet data only if it is not already downloaded
    zip_file = '{}.zip'.format(corpus_name)
    downloaded = False

    try:
        find(zip_file)
    except LookupError:
        download(corpus_name, quiet=True)
        downloaded = True

    return downloaded


class Bot(ChatBot):
    """
    Bot that silences NLTK downloads
    """

    def initialize(self):
        """
        Do any work that needs to be done before the responses can be returned.
        """

        # Download required NLTK corpora if they have not already been downloaded
        nltk_download_corpus('stopwords')
        nltk_download_corpus('wordnet')
        nltk_download_corpus('punkt')
        nltk_download_corpus('vader_lexicon')