我想寫一個簡單的函數,通過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