我想编写一个简单的函数来通过 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 code>) 我找不到。
请您参考如下方法:
WordNet 不包含这些词或类似词。有关解释,请参阅 WordNet docs 中的以下内容:
Q. Why is WordNet missing: of, an, the, and, about, above, because, etc.
A. WordNet only contains "open-class words": nouns, verbs, adjectives, and adverbs. Thus, excluded words include determiners, prepositions, pronouns, conjunctions, and particles.
您也不会在 WordNet 的在线版本中找到这些类型的词。
