微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我会遇到这个词性错误,我该如何解决

如何解决为什么我会遇到这个词性错误,我该如何解决

我正在尝试对文本进行词形还原,当我这样做时说:

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 举报,一经查实,本站将立刻删除。