问题描述
我正在尝试对文本进行词形还原,当我这样做时说:
KeyError: 'NNP'
我认为这是与专有名词词形还原有关的问题,不确定,非常感谢任何帮助
没有导入的完整代码:
lemmatizer = WordNetLemmatizer()
stop_words = set(stopwords.words('english'))
text = wikipediaTextProcessor("https://en.wikipedia.org/wiki/Pangolin")
tokenizedText = word_tokenize(text)
textNoStopwords = [word for word in tokenizedText if word not in stop_words]
posTaggedText = pos_tag(textNoStopwords)
lemmatizedText = []
for word,tag in posTaggedText:
lemmatizedText.append(lemmatizer.lemmatize(word,tag))
print(lemmatizedText)
完全错误:
Traceback (most recent call last):
File "c:\Users\nayna\Desktop\PangolinProject\NaturalLanguageProcessingFile.py",line 25,in <module>
lemmatizedText.append(lemmatizer.lemmatize(word,tag))
File "C:\Users\nayna\Desktop\PangolinProject\.venv\lib\site-packages\nltk\stem\wordnet.py",line 38,in lemmatize
lemmas = wordnet._morphy(word,pos)
File "C:\Users\nayna\Desktop\PangolinProject\.venv\lib\site-packages\nltk\corpus\reader\wordnet.py",line 1917,in _morphy
exceptions = self._exception_map[pos]
KeyError: 'NNP'
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)