Novello – Thesaurus

This is nowhere near finished yet, but I have added a thesaurus feature to novello. It is fun to play with. Just start Novello and then, when the cursor is in a word press control-T and you get a popup of suggested words:

MS Word also has a thesaurus, but in Novello the user is forced to access the thesaurus via the “control T” key combo. Therefore users learn to work faster!

The thesaurus service is currently pointing at a webservice provided by http://words.bighugelabs.com/ . We get 10,000 word lookups per day for free.

The code is really simple to do the look up. Line 14 downloads the result from bighugelabs and the rest of the code parses the result. The m_cache variable stores results for words we’ve already looked up, therefore we don’t use up any of our 10,000 requests unnecessarily!

public class ThesaurusService
{
    private static final String URL = "http://words.bighugelabs.com/api/2/?/%s/";

    private Map<String, List<String>> m_cache = new HashMap<String, List<String>>();

    public List<String> suggest(String word)
    {
        List<String> options = m_cache.get(word);
        if (options == null)
        {
            options = new ArrayList<String>();
            m_cache.put(word, options);
            String result = FileUtils.downloadToString(String.format(URL, word));
            if (result!=null)
            {
                String[] lines = result.split("\n");
                for (String line : lines)
                {
                    int i = line.lastIndexOf('|');
                    if (i != -1)
                    {
                        String option = line.substring(i);
                        options.add(option);
                    }
                }
            }
        }
        return options;
    }
}
Advertisements

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: