我想写一个简单的函数,通过NLTK查看WordNet中是否存在这个单词。为什么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当它是一个停用词? – alvas
这只是一个尝试忽略这些词。但我注意到并非所有常见的词都是停用词。 – Sadik