Programmatically install NLTK corpora / models, i.e. without the GUI downloader?

后端 未结 4 655
盖世英雄少女心
盖世英雄少女心 2020-12-12 15:56

My project uses the NLTK. How can I list the project\'s corpus & model requirements so they can be automatically installed? I don\'t want to click through the nltk

4条回答
  •  生来不讨喜
    2020-12-12 16:53

    I've managed to install the corpora and models inside a custom directory using the following code:

    import nltk
    nltk.download(info_or_id="popular", download_dir="/path/to/dir")
    nltk.data.path.append("/path/to/dir")
    

    this will install "all" corpora/models inside /path/to/dir, and will let know NLTK where to look for it (data.path.append).

    You can't «freeze» the data in a requirements file, but you could add this code to your __init__ besides come code to check if the files are already there.

提交回复
热议问题