NLTK y detección de idiomas


¿Cómo puedo detectar en qué idioma está escrito un texto usando NLTK?

Los ejemplos que he visto usan nltk.detect, pero cuando lo he instalado en mi mac, no puedo encontrar este paquete.

Author: John Vandenberg, 2010-07-06

3 answers

¿Te has encontrado con el siguiente fragmento de código?

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) 

Desde http://groups.google.com/group/nltk-users/browse_thread/thread/a5f52af2cbc4cfeb?pli=1&safe=active

O el siguiente archivo de demostración?

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

 30
Author: William Niu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-14 22:22:26

Esta biblioteca tampoco es de NLTK, pero sin duda ayuda.

Install sudo pip install langdetect

Compatible con las versiones de 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.d.: No espere que esto funcione correctamente siempre:

>>> 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'
 20
Author: SVK,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-07 00:42:32

Aunque esto no está en la NLTK, he tenido grandes resultados con otra biblioteca basada en Python:

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

Esto es muy simple de importar e incluye un gran número de idiomas en su modelo.

 17
Author: burgersmoke,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-30 03:43:43