niklassaers niklassaers - 1 year ago 207
Python Question

NLTK and language detection

How do I detect what language a text is written in using NLTK?

The examples I've seen use nltk.detect, but when I've installed it on my mac, I cannot find this package.



Answer Source

Have you come across the following code snippet?

english_vocab = set(w.lower() for w in nltk.corpus.words.words())
text_vocab = set(w.lower() for w in text if w.lower().isalpha())
unusual = text_vocab.difference(english_vocab) 


Or the following demo file?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download