Monday, 20 August 2012

Trick for using Google's Did You Mean feature in Java

You must have used the Google's Did you mean feature. It corrects any mistakes in your query automatically. It acts as a spell checker. Best part is it also handles proper nouns like Delhi, Sachin Tendulkar, or any place names or any movie title or series name which is not possible using any regular spell checker. So here is a trick to use Google's Did you mean feature in your own apps.
I wrote a small java code to demonstrate it. The function didYouMean takes as input the query and makes a request to Google search and parses the HTML response to get the suggestion (if any). Its written in java and uses the Jsoup library for parsing the HTML content. But understanding the logic it can be converted to any language.
 If you take a look at the HTML response from Google you will find that the div tag with id "topstuff" contains the Did you mean suggestion by google if any. We simply extract that element and the parse it to plain text.Then we remove any extra characters in result and extract only the actual suggestion.
You can find the code for it on github.

Let me know if you like it.

Thursday, 16 August 2012

So damn true: "Necessity the mother of building cool stuff"

Few days back, some hardware issue with my hard drive left it irrepairable and all my data was lost including softwares, movies, music. (Thank god I use github to host all my projects).

Now loss of movies and softwares is no big deal. But finding one's song collection is difficult as one has a particular taste for music. But good for me all that music is stored in my IPod. But as we all know Apple doesn't allow one to copy music files from IPod to computer. So what I did was look around some way to get my music from IPod to PC. I opened the IPod in USB storage mode and looked at where the files are stored. I found all the files but they were stored with random (unrecognizable) names in it. So for starters I copied all those files to my PC. Then I looked for a way to get the files some understandable names. But naming around 1000 songs listening to each one is not the way a geek would do it. So then I wrote this java app that scanned through all mp3 files and read the ID3 tags to get the song title and renamed all songs. Cool so it scanned all files and did the task in few minutes. Then I thought why not modify it a little and let it scan through your entire computer and look for mp3 files, rename them using song title and store them in a single directory where the songs are categorized in subdirectories using the album  name or artist name. In this way all the duplicates of a single mp3 would also be removed.

So this Mp3Manager is a console utility in java that takes as input the name of root directory to store all your music files and type of categorization to use to store the music files in directories(album name or artist). It is available on github

Read the to know how to use it. Let me know if you like it or if you would like any modifications to it.