回答
你有没有遇到下面的代码片段?
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)
从http://groups.google.com/group/nltk-users/browse_thread/thread/a5f52af2cbc4cfeb?pli=1&safe=active
或者下面的演示文件?
这个图书馆不是来自NLTK,但肯定有帮助。
$ sudo的PIP安装langdetect
支持Python版本2.6,2.7,3.x的
>>> from langdetect import detect
>>> detect("War doesn't show who's right, just who's left.")
'en'
>>> detect("Ein, zwei, drei, vier")
'de'
https://pypi.python.org/pypi/langdetect?
P.S .:不要指望这总是正确的工作:
>>> detect("today is a good day")
'so'
>>> detect("today is a good day.")
'so'
>>> detect("la vita e bella!")
'it'
>>> detect("khoobi? khoshi?")
'so'
>>> detect("wow")
'pl'
>>> detect("what a day")
'en'
>>> detect("yay!")
'so'
谢谢你指出它并不总是有效。 '检测(“你让它回家!”)'给我“fr”。我想知道是否有更好的。 – 2017-10-14 03:43:51
下面是另一个有趣的观察:它似乎没有给每个相同的答案。 >>> >>> detect_langs(“你好,我是christiane amanpour。”) [it:0.8571401485770536,en:0.14285811674731527] >>> detect_langs(“你好,我是christiane amanpour。”) [it:0.8571403121803622, fr:0.14285888197332486] >>> detect_langs(“你好,我是christiane amanpour。”) [it:0.999995562246093]' – 2017-10-14 04:03:25
- 1. 语言检测
- 2. 语言检测
- 3. 检测iOS语言
- 4. CLI语言检测
- 5. 语言检测器
- 6. Solr语言检测
- 7. 检测语言和django语言环境-url
- 8. 用API和语言检测Pastie
- 9. Symfony2语言环境检测和翻译
- 10. 语言检测API/Library
- 11. 检测NSString的语言
- 12. 浏览器语言检测
- 13. 检测输入语言?
- 14. 较短的语言检测
- 15. 检测Android语言支持
- 16. python网站语言检测
- 17. 检测编程语言
- 18. 检测文本的语言
- 19. 将语言添加到NLTK WordNet
- 20. 用NLTK检查英语语法
- 21. 微软认知语言到文本 - 检测语言
- 22. 检测浏览器语言环境/语言并生成输出
- 23. 如何检测软键盘语言?
- 24. 如何检测Visualstudio的语言版本?
- 25. Ruby Rails Gem来检测其他语言
- 26. 极短文本的语言检测
- 27. 语言检测重定向(主页)
- 28. 在java中检测浏览器语言
- 29. 梨包语言检测上PHP 7
- 30. 在Emacs中自动检测语言
PS,它仍然依赖于nltk.detect,虽然。任何关于如何在Mac上安装的想法? – niklassaers 2010-08-03 09:59:35
我不相信detect是nltk的本地模块。 下面是代码:http://docs.huihoo.com/nltk/0.9.5/api/nltk.detect-pysrc.html 你可以下载它并把它放到你的python库中,它可能在: /Library/Python/2.x/site-packages/nltk ... – 2010-08-03 13:53:12
检查出来.. http://blog.alejandronolla.com/2013/05/15/detecting-text-language-with-python -and-nltk/ – 2016-04-08 05:46:04