2010-07-05 30 views
23

Bir metnin NLTK kullanılarak yazılmış bir dili nasıl algılayabilirim?NLTK ve dil algılama

Gördüğüm örnekler nltk.detect kullanıyor, ancak bu yazılımı Mac'ime yüklediğimde bu paketi bulamıyorum.

cevap

26

Aşağıdaki kod parçacığına rastladınız mı? http://groups.google.com/group/nltk-users/browse_thread/thread/a5f52af2cbc4cfeb?pli=1&safe=active

Veya aşağıdaki demo dosyasından

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) 

?

https://github.com/saffsd/langid.py

Bu ithal etmek çok basittir ve çok sayıda içerir: Bu NLTK olmasa

https://web.archive.org/web/20120202055535/http://code.google.com/p/nltk/source/browse/trunk/nltk_contrib/nltk_contrib/misc/langid.py

+0

PS, hala olsa nltk.detect dayanıyordu. Mac’e nasıl yükleyeceğiniz hakkında bir fikrin var mı? – niklassaers

+0

Algılamanın nltk için bir yerel modül olduğuna inanmıyorum. İşte kod: http://docs.huihoo.com/nltk/0.9.5/api/nltk.detect-pysrc.html Muhtemelen indirip de olabilen sizin piton kütüphanede koyabilirsiniz : /Library/Python/2.x/site-packages/nltk ... –

+0

Bunu kontrol edin .. http://blog.alejandronolla.com/2013/05/15/detecting-text-language-with-python -ve-nltk/ –

15

, başka Python tabanlı kütüphane ile mükemmel sonuçlar vardı kendi modelinde diller.

18

Bu kitaplık NLTK'dan değil ama kesinlikle yardımcı oluyor.

$ sudo langdetect yüklemek pip

Desteklenen Python sürümleri 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. bu doğru her zaman işe beklemeyin .::

>>> 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' 
+1

Her zaman işe yaramadığını belirttiğiniz için teşekkür ederiz. '("Onu ev yaptın!") "beni" fr "veriyor. Daha iyi bir şey olup olmadığını merak ediyorum. –

+1

İşte başka bir eğlenceli gözlem: Her seferinde aynı cevabı vermek gibi görünmüyor. '>>> detect_langs (" Merhaba, ben christiane amanpour. ") [it: 0.8571401485770536, tr: 0.14285811674731527] >>> detect_langs (" Merhaba, ben christiane amanpour. ") [it: 0.8571403121803622, fr: 0.14285888197332486] >>> detect_langs ("Merhaba, ben christiane amanpour.") [it: 0.999995562246093] ' –