Discover the language.


Lets try and unbox Python langdetect library, which will be very useful for text processing and linguistic tasks. This is a language detection library implemented in plain Java.

Language detection with Python.


As stated in pypi.org langdetect supports 55 languages out of the box , now maybe even more. So let's try some practical examples !



Lets install langdetect.


        
pip install langdetect

from langdetect import detect

Lets detect english text.


        
try_text="My daughter just revealed to me she's transexual... I guess that makes me transparent."
detect(try_text)

OUT: en


Lets detect spanish text.


        
try_text2='Hoy pasaré por la biblioteca para devolver los libros.'
detect(try_text2)

OUT: es



Lets detect russian text.


        
try_text3="Ночь темна и полна ужасов, а холодильник светел и полон обещаний."
detect(try_text3)

OUT: ru


Lets detect french text.


        
try_text4="La pire position sexuelle c'est quand t'es allongé en dessous et qu'au dessus il n'y a personne..."
detect(try_text4)

OUT: fr



Lets detect chinese text.


        
try_text5='''妈妈说:“今天能完成的事,不要留到明天。”

儿子回答:“好吧,把全蛋糕给我,我今天都吃光了吧。'''
detect(try_text5)

OUT: zh-cn





See also related topics: