回答
你有沒有遇到下面的代碼片段?
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. 語言檢測器
- 4. ANN:語言檢測
- 5. 檢測Facebook語言
- 6. Solr語言檢測
- 7. CLI語言檢測
- 8. 檢測iOS語言
- 9. NLTK synset與其他語言
- 10. 檢測語言和django語言環境-url
- 11. Symfony2語言環境檢測和翻譯
- 12. Phonegap App檢測語言和國家
- 13. 國家和語言代碼檢測
- 14. 用API和語言檢測Pastie
- 15. 語言檢測API/Library
- 16. 檢測文本的語言
- 17. SOLR 4.1語言檢測
- 18. 檢測Android語言支持
- 19. 檢測NSString的語言
- 20. 檢測語言從RecognizerIntent
- 21. iPad檢測鍵盤/語言
- 22. 的.htaccess的語言檢測
- 23. 較短的語言檢測
- 24. 檢測編程語言
- 25. python網站語言檢測
- 26. 蠻力語言檢測
- 27. 檢測輸入語言?
- 28. CodeMirror - 自動檢測語言
- 29. 瀏覽器語言檢測
- 30. JMSI18nRoutingBundle檢測首選語言
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