【发布时间】:2023-03-30 11:02:01
【问题描述】:
我想编写一个简单的函数,通过 NLTK 来查看 WordNet 中是否“存在”这个词。
def is_known(word):
"""return True if this word "exists" in WordNet
(or at least in nltk.corpus.stopwords)."""
if word.lower() in nltk.corpus.stopwords.words('english'):
return True
synset = wn.synsets(word)
if len(synset) == 0:
return False
else:
return True
为什么像could, since, without, although 这样的词会返回 False?它们没有出现在 WordNet 中吗?有没有更好的方法来找出 WN 中是否存在一个单词(使用 NLTK)?
我的第一次尝试是消除“停用词”,即像 to, if, when, then, I, you 这样的词,但我仍然找不到非常常见的词(如 could)。
【问题讨论】:
-
当它是一个停用词时,你为什么返回 True?
-
那只是试图忽略这些词。但我注意到并非所有常用词都是停用词。