在python交互下使用
import nltk.book
此时你应能看到一系列的,一长串的报错。最末尾会有一段(可能并不完全相同,数量也不一样):
Searched in: - '/home/<一个路径>/nltk_data' - '/home/<一个路径>\\nltk_data' - '/home/<一个路径>\\nltk_data' - '/home/<一个路径>\\nltk_data' - '/home/<一个路径>\\nltk_data' - '/home/nltk_data' - '/home/nltk_data' - '/home/nltk_data'
好,记下其中任一路径。接下来我们去https://github.com/nltk/nltk_data下载我们需要的数据。
只需下载正数第二个“packages”文件夹即可。
好的,假定你已经下载并成功得到了packages文件夹及其内含的所有文件。现在,把packages文件夹下的所有子文件夹拷贝至前述任一路径处nltk_data下。请注意,不要把packages拷过去,而是packages的子文件夹。结果如下图
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200708140032645.png)好,大功告成。在python交互下使用
import nltk.book
此时你应看见如下输出:
*** Introductory Examples for the NLTK Book *** Loading text1, ..., text9 and sent1, ..., sent9 Type the name of the text or sentence to view it. Type: 'texts()' or 'sents()' to list the materials. text1: Moby Dick by Herman Melville 1851 text2: Sense and Sensibility by Jane Austen 1811 text3: The Book of Genesis text4: Inaugural Address Corpus text5: Chat Corpus text6: Monty Python and the Holy Grail text7: Wall Street Journal text8: Personals Corpus text9: The Man Who Was Thursday by G . K . Chesterton 1908
恭喜,安装完成。
然后nltk使用时不再需要nltk.download('XXX') 直接使用:from nltk.corpus import wordnet as wn
hyper1 = wn.synset(‘apple’ + ‘.n.01’).hypernyms()