如何解决NLTK WordNetLemmatizer 为特定单词返回的错误 (?) 引理
我正在阅读这篇 article 并在我自己的数据上进行实验,我发现文章中给出的两个例子和我的一个词都没有按照描述的那样工作。 您可以参考这篇文章以获取更多信息,尽管这里的问题可以解决一切问题。
# stemmed root words: Books,Braveri,Harri,Transpar
from nltk.stem.wordnet import WordNetLemmatizer as Lemmatizer
# the article shared the same lemmatizer initialization.
lem = WordNetLemmatizer()
# returned 'harry' in the example without pos tag
In [269]: lem.lemmatize('harri',pos='n')
Out[269]: 'harri'
In [270]: lem.lemmatize("Books",pos='n')
Out[269]: 'Books'
# returned 'book' in the example with pos tag
In [270]: lem.lemmatize("Books",pos='v')
Out[269]: 'Books'
# my example root word,didn't change at all
[ins] In [278]: lem.lemmatize("Transpar",pos="a")
Out[278]: 'Transpar'
[ins] In [281]: lem.lemmatize("Transpar",pos="n")
Out[281]: 'Transpar'
# returned 'bravery' in the example without pos tag
[ins] In [280]: lem.lemmatize("Braveri",pos="n")
Out[280]: 'Braveri'
这个 lemmatizer 的默认 pos 标签只是 wordnet.NOUN
因此提供 pos 标签与否不会有什么区别。
仅供参考,transpar
最初是 transparent
。
唯一的区别是作者使用 NLTK 词干提取器来提取单词,而我使用的是 texthero.stem
。
是我做错了还是 NLTK 发生了一些变化?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com(将#修改为@)