Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Language detection with gzip

I saw this a while back when I saw a post on a dailyprogrammer thread (which was based around language detection) that linked to this lecture by Peter Norvig:
Lecture (Click to View)

The basic idea of this is that you have your text you want to determine the language of, and a variety of text files containing words or sentences of different languages.

If you compare the gzipped original language files with the gzipped language files concatenated with the text you want to verify the language of and record the difference in bytes for each language file, the right language will have the least difference in bytes.

An explaination of why it works is in the lecture above.

For this tutorial, the language files I will be using (and I am only using a few for simplicity) are:

I renamed the files EN.txt, FR.txt and DE.txt respectively, and placed them in a subdirectory named /LanguageFiles

Instead of this being a tutorial outlining what I write line by line and then posting the full python code at the end I have decided to comment the (probably overthought and overcomplicated) source and just post that. I will also include a download to a zip file containing the full project directory including the three language files.

This is how I chose to write my implementation: Pastebin Link

Link to full project directory download and individual file download from my website

References:

Notes:
  • This does not have a 100% success rate (Especially if you start adding more and more languages that are similar to each other)

  • Longer text = higher success rate


Very nice thread, thanks for taking the time to make it.
[ 0xC0D3_BR34K3R // 🙈🙉🙊 // SYS_REFORGER ]
Interesting tutorial. Better than the majority of "tutorials" in this section.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by BarretMar 8, 2019 10:30 AM 5 446 Mar 8, 2019 10:30 AM
Last Post: fec-ri.muhayyel
[Shell] by Z0RaFeb 20, 2019 12:29 PM 2 214 Feb 20, 2019 12:29 PM
Last Post: Z0Ra
[Shell] by 'PalladiumApr 17, 2016 09:52 AM 22 658 Apr 17, 2016 09:52 AM
Last Post: ๖ۣۜLogic_Bomb