热线电话:13121318867

登录
2021-03-19 阅读量: 4812
词根还原WordNetLemmatizer报错

1.png

2.png

import nltk

nltk.download()

from nltk.stem import SnowballStemmer

from nltk.stem import WordNetLemmatizer

wnl = WordNetLemmatizer()

wnl.lemmatize('countries')


报错提示如下:

---------------------------------------------------------------------------

LookupError Traceback (most recent call last)

C:\ProgramData\Anaconda3\lib\site-packages\nltk\corpus\util.py in __load(self)

82 try:

---> 83 root = nltk.data.find("{}/{}".format(self.subdir, zip_name))

84 except LookupError:


C:\ProgramData\Anaconda3\lib\site-packages\nltk\data.py in find(resource_name, paths)

584 resource_not_found = "\n%s\n%s\n%s\n" % (sep, msg, sep)

--> 585 raise LookupError(resource_not_found)

586


LookupError:

**********************************************************************

Resource wordnet not found.

Please use the NLTK Downloader to obtain the resource:


>>> import nltk

>>> nltk.download('wordnet')

For more information see: https://www.nltk.org/data.html


Attempted to load corpora/wordnet.zip/wordnet/


Searched in:

- 'C:\\Users\\chen/nltk_data'

- 'C:\\ProgramData\\Anaconda3\\nltk_data'

- 'C:\\ProgramData\\Anaconda3\\share\\nltk_data'

- 'C:\\ProgramData\\Anaconda3\\lib\\nltk_data'

- 'C:\\Users\\chen\\AppData\\Roaming\\nltk_data'

- 'C:\\nltk_data'

- 'D:\\nltk_data'

- 'E:\\nltk_data'

**********************************************************************



During handling of the above exception, another exception occurred:


LookupError Traceback (most recent call last)

<ipython-input-17-414b7ff7b287> in <module>

----> 1 wnl.lemmatize('countries')


C:\ProgramData\Anaconda3\lib\site-packages\nltk\stem\wordnet.py in lemmatize(self, word, pos)

36

37 def lemmatize(self, word, pos=NOUN):

---> 38 lemmas = wordnet._morphy(word, pos)

39 return min(lemmas, key=len) if lemmas else word

40


C:\ProgramData\Anaconda3\lib\site-packages\nltk\corpus\util.py in __getattr__(self, attr)

118 raise AttributeError("LazyCorpusLoader object has no attribute '__bases__'")

119

--> 120 self.__load()

121 # This looks circular, but its not, since __load() changes our

122 # __class__ to something new:


C:\ProgramData\Anaconda3\lib\site-packages\nltk\corpus\util.py in __load(self)

83 root = nltk.data.find("{}/{}".format(self.subdir, zip_name))

84 except LookupError:

---> 85 raise e

86

87 # Load the corpus.


C:\ProgramData\Anaconda3\lib\site-packages\nltk\corpus\util.py in __load(self)

78 else:

79 try:

---> 80 root = nltk.data.find("{}/{}".format(self.subdir, self.__name))

81 except LookupError as e:

82 try:


C:\ProgramData\Anaconda3\lib\site-packages\nltk\data.py in find(resource_name, paths)

583 sep = "*" * 70

584 resource_not_found = "\n%s\n%s\n%s\n" % (sep, msg, sep)

--> 585 raise LookupError(resource_not_found)

586

587


LookupError:

**********************************************************************

Resource wordnet not found.

Please use the NLTK Downloader to obtain the resource:


>>> import nltk

>>> nltk.download('wordnet')

For more information see: https://www.nltk.org/data.html


Attempted to load corpora/wordnet


Searched in:

- 'C:\\Users\\chen/nltk_data'

- 'C:\\ProgramData\\Anaconda3\\nltk_data'

- 'C:\\ProgramData\\Anaconda3\\share\\nltk_data'

- 'C:\\ProgramData\\Anaconda3\\lib\\nltk_data'

- 'C:\\Users\\chen\\AppData\\Roaming\\nltk_data'

- 'C:\\nltk_data'

- 'D:\\nltk_data'

- 'E:\\nltk_data'

**********************************************************************


300.0000
5
关注作者
收藏
评论(5)

发表评论