如何使用nltk找出英语中存在的单词

aks*_*tia 4 python nlp nltk wordnet python-3.x

我正在寻找这个问题的正确解决方案.之前已经多次询问过这个问题,我没有找到适合的单一答案.我需要在NLTK中使用语料库来检测单词是否是英语单词

我试过这样做:

wordnet.synsets(word)
Run Code Online (Sandbox Code Playgroud)

对于许多常见词汇而言,这无法言喻.使用英语单词列表并在文件中执行查找不是一种选择.使用附魔也不是一种选择.如果有另一个库可以执行相同的操作,请提供api的用法.如果没有,请提供nltk语料库,其中包含所有英语单词.

Kas*_*mvd 13

NLTK包括一些仅仅是单词列表的语料库.Words Corpus是来自Unix的/ usr/share/dict/words文件,被一些拼写检查器使用.我们可以使用它来查找文本语料库中的异常或拼写错误的单词,如下所示:

def unusual_words(text):
    text_vocab = set(w.lower() for w in text.split() if w.isalpha())
    english_vocab = set(w.lower() for w in nltk.corpus.words.words())
    unusual = text_vocab - english_vocab
    return sorted(unusual)
Run Code Online (Sandbox Code Playgroud)

在这种情况下,您可以检查您的单词的成员船english_vocab.

>>> import nltk
>>> english_vocab = set(w.lower() for w in nltk.corpus.words.words())
>>> 'a' in english_vocab
True
>>> 'this' in english_vocab
True
>>> 'nothing' in english_vocab
True
>>> 'nothingg' in english_vocab
False
>>> 'corpus' in english_vocab
True
>>> 'Terminology'.lower() in english_vocab
True
>>> 'sorted' in english_vocab
True
Run Code Online (Sandbox Code Playgroud)