Question: MultiLists in Java In this problem, you will count the frequency of the words in a file using a mulit-list. To accomplish this you will

MultiLists in Java

In this problem, you will count the frequency of the words in a file using a mulit-list. To accomplish this you will create an ADT Dictionary. To accomplish this, you will first create a subclass Entry that contains a dictionary entry with the following attributes:

word - the word

number of occurrences - the number of times it occurred

Constructors and other methods are up to you to figure out.

The Dictionary class will have an ArrayList of 26 elements (the number of characters in the alphabet). Each element in the ArrayList will be an ArrayList whose elements are of type Entry. Words that begin with the letter a will be stored in the first ArrayList, words that begin with b will be stored in the second ArrayList, etc. In addition, the class should have an attribute total that counts the number of occurrences of all words. You will need this to calculate the frequency.

Note: Ignore cases and special characters. An easy way to do this is every time you read a line to do: line = line.replaceAll("[^a-zA-Z]", " "); This replaces all non alphabetic characters with whitespaces.

Methods:

Constructor that creates an empty dictionary

put(String word) - a method that stores a word in the dictionary. If the word already exists it should update its frequency. Update total.

double get(String word) - returns the frequency of the specified word. 0 if the word is not found.

double remove(String word) - removes the word from the dictionary and returns the frequency. 0 if the word is not found. Also update total.

double getAverageLength() - returns the average length of the words in the dictionary.

double getAverageFreq() returns the average frequency of the words in the dictionary.

String [] getTopWords(int top) - returns an array of the most popular words in the dictionary. The attribute top specifies the number of words to be returned.

In Java, it is possible to read file from the Internet directly. To do that use: URL url = new URL("http://www.gutenberg.org/files/11/11-0.txt");

Scanner input = new Scanner(url.openStream());

The fun part: The file Alice.txt that contains Alice in Wonderland is taken from Project Gutenberg. Run your program with this file.

Also, write a main method that reads from the URL/file Alice.txt and stores the words in an object of the class dictionary. Print the top 100 words. Compare the results to the top 100 most commonly used words in the English language:

https://en.wikipedia.org/wiki/Most_common_words_in_English

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!