The intelligence of machines and the branch of computer science which aims to create it

Artificial Intelligence Journal

Subscribe to Artificial Intelligence Journal: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get Artificial Intelligence Journal: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Artificial Intelligence Authors: William Schmarzo, Liz McMillan, Yeshim Deniz, Elizabeth White, Pat Romanski

Related Topics: Artificial Intelligence Journal

Artificial Intelligence: Article

Building a Simple VocabBuilder Application

Creating a good impression

To make a good impression, one needs to have a good vocabulary. Management Professionals, University Professors, or GRE/GMAT aspirants - we all benefit from a decent set of words in this competitive world. There are different ways we can improve our vocabulary, such as reading novels, articles, dictionaries and so on, but we often find very little time to do so.

During our "down-time" - when we are stuck in traffic for hours, or standing in some long queue - our mobile phone is often our only source of entertainment. If our mobiles - which one in three people already carry - had word-tutors, this time could be efficiently used to learn new adjectives, verbs and nouns.

To build such an application, words need to be stored in a database. Since simple database implementation (RMS) is dynamic, the database needs to be built on every new mobile, after application is installed. To remove this overhead, the only way to maintain the word-list is in a file. Because of some programming related issues, j2me does not provide a full fledged API for file access. Still, there are ways to use a file in a j2me application. In a Vocab Builder application, words and their meanings, stored in those files randomly, can be retrieved.

There are "n" number of constraints with mobile programming - such as power, speed, UI size, memory size limitations, and many others - which make programming for mobile applications difficult. Probably, this is the reason why we see very few attempts to create such software. However, a simple vocabulary builder can be implemented without much effort. The following article can be used as a guideline to develop a simple vocabulary builder for your mobile phone.

First, let's look at Implementation Diagram, as shown in Figure 1.

All classes from the above diagram are explained in this article. Let's start with the MIDlet class. Our application will have a MIDlet that will initiate the application.

VocabBuilder Class
Let's define this MIDlet Class and name it VocabBuilder (see Figure 2).

public class VocabBuilder extends MIDlet implements CommandListener {

This VocabBuilder MIDlet displays the operations menu for the user. The menu provides different functions that are supported by the VocabBuilder tool. Since the tool has 5 functionalities, the same are provided in the operations menu.

menuList = new List("Expert Vocab Building",List.IMPLICIT);
menuList.append("Learn Adjectives",adjectivesImage);
menuList.append("Learn Verbs", adjectivesImage);
menuList.append("Learn Nouns", adjectivesImage);
menuList.append("Add words", verbsImage);
menuList.append("View / Delete words", verbsImage);
menuList.append("Help ",helpImage);

To provide the word-list, a file is used as a datastore. In this class, a string that contains the name of this file stores different words and their meanings. Providing the get() method for this variable will ensure that the get() method returns the name of the file currently in use by the application.

private String wordDatabaseFile;

As shown in Figure 3, the menu UI is displayed after the displayList() function of the VocabBuilder class is called on.

After the user selects a particular option from List, the corresponding operation is performed by implementing the CommandListener Interface. In need of a common algorithm to implement functionality of the first three options, we call on the method of getRandomWords() of the accessFile class. This class will, in turn, fetch the words and display them on the Form. But before calling on the aforementioned method, we need to set the value for the wordDatabaseFile string.

else if (c == List.SELECT_COMMAND)
    {
      int selection=menuList.getSelectedIndex();
      switch(selection)
      {
      case 0:
        wordDatabaseFile = "adjectives.kw";
        accessFile.getRandomWords();
        break;
      case 1:
        wordDatabaseFile = "verbs.kw";
        accessFile.getRandomWords();
        break;
      case 2:
        wordDatabaseFile = "nouns.kw";
        accessFile.getRandomWords();
        break;
      case 3:
        AddWordsToDictionary awdForm = new AddWordsToDictionary(this);
        Display.getDisplay(this).setCurrent(awdForm);
        awdForm = null
        break;
      case 4:
        DeleteWord dw = new DeleteWord(this);
        dw = null;
        break;
      case 5:
        HelpForm helpForm = new HelpForm(this);
        Display.getDisplay(this).setCurrent(helpForm);
        helpForm = null;
        break;
      }
    }

For the last three options, different classes are intitialized. These classes, in turn, will provide the functionality for adding, updating, deleting, and viewing the custom Dictionary.

AccessFile Class
This class fetches three random words at a time from the selected file as shown in Figure 4. In order to display these words, this class needs to extend Form Class.

public class AccessFile extends Form implements CommandListener

Note: Generally, when people read words that are consecutive, they tend to get bored. Hence, the random words generation strategy can be used to retain the interest of the user.

We need a "Next" button in order to display the next set of random words. This application opens the file in which word-meaning pairs are stored. We all have come across the apothegm, "different people, different needs". Accordingly, the user can choose a "learning area" appropriate to his or her needs. Some people are weak in adjectives, whereas others are weak in nouns, so different interfaces are provided for nouns, adjectives and verbs. Since implementation of all three is identical, an AccessFile class was created. To open the file and read the contents, the following function is used:

inputStream = getClass().getResourceAsStream(vb.getDataFileName());

inputStream is an object of InputStream class. Using getClass.getResourceAsStream(), we can open the file that is stored in the "res" library of the application package. After opening the file, we need to position the cursor in a random position. This can be done using following function:

inputStream.skip(selectRandom.getRandomPosition())

Here, a selectRandom class is used, which returns the random position in the file. By using the skip function of inputStream object, we reposition the cursor in a random position.

After a random position has been selected, the selected words can be fetched. Take extra care in the format in which the selected file is stored. Since the file used in the application has a word-meaning pair in a line the following strategy is used for fetching:

for(int j = 0; j<3;j++)
    {
    /** Create the word by adding all the characters */
    while ((tempCharRead = inputStream.read()) != -1 &&
       tempCharRead != '\n' )
    {
       word_meaning[j] = word_meaning[j]+ (char) tempCharRead;
    }
    this.append(wordMeaning);
    }

Since a word and its meaning are separated by a colon, the pair can be displayed in the same way on Form, using the append() method. In formatting, string item data type can be used. Next and Exit buttons are provided on the form for navigating through the word list.

    if (cmd == nextCommand)
       getRandomWords();
    else if (cmd == exitCommand) vb.displayList();
       // This is the main MIDlet Operations List.

If the user presses the next button, the application displays a new set of words, whereas if Exit is selected, the application takes control to the main List.

SelectRandom Class
This class fetches the file and depending on its size, it generates a random value. If the value generated is positioned towards last word, then the application might display only one or two words instead of three. In order to avoid this the maximum value to be generated can be set:

int skipValue= Math.abs((int) System.currentTimeMillis() % count);

The maximum feasible number that will prevent the display of less than three randomly generated words is "count". A more sophisticated algorithm can be used for generating the random number.

AddWordsToDictionary Class


More Stories By Kanchan Waikar

Kanchan Waikar is a software professional working with an IT company. She is very much inclined toward mobile programming. Her hobbies include reading novels, painting, playing table tennis, and programming.

Comments (2) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Mr. X 10/24/06 06:29:00 AM EDT

There's a lot of scope for improving, and seondly, think of more applications, ideas do matter!

JDJ News Desk 10/22/06 04:37:33 PM EDT

To make a good impression, one needs to have a good vocabulary. Management Professionals, University Professors, or GRE/GMAT aspirants - we all benefit from a decent set of words in this competitive world. There are different ways we can improve our vocabulary, such as reading novels, articles, dictionaries and so on, but we often find very little time to do so.