In this assignment, we use linked list to count the words from a given text le or URL and print the words by their frequnct order. The iterable class "Frequency" uses a "Node" to represent each word and its frequency. The Node class is given here:
class Node {
private E key;
private int count;
private Node next;
Node(E item){
key = item;
count = 1;
next = null;
}
}
Frequency class can insert words into a linked list. When a new word is inserted, it adds the word into the list. If the word exists in the list, we simply increment the value of "count" for the word. We also keep the words in the linked list by their frequency order. Therefore, when the frequency of a word has changed, we have to move the word to correct position in the linked list. If two words have same frequency, they are sorted alphabetically. For example: if we insert three words Alice, Bob, Cathy, we will have
To read a webpage at the given URL, and print the content (the html le) of the webpage:
In in = new In(urlName);
while (!in.isEmpty()) {
String s = in.readLine();
System.out.println(s);
freq.insertWords(s);
}
To read the text le and print the content.
In in = new
In(fileName);
while(!in.isEmpty()) {
String s = in.readLine();
System.out.println(s);
freq.insertWords(s);
}
The InsertWords method of the Frequency class takes a sentence, split the sentence into words, and calls "insert" method of the Frequency class to insert each single word into the Linked List. The InsetWords method is shown here:
public void insertWords(String str){
String delims =
"[.,?!’\"()}{;/<>&=#-:\\_]+";
String[] words = str.split(delims);
for(String s: words){
s = s.toLowerCase();
if(!s.equals(""))
freq.insert(s);
}
This project will allow you practice linked list insert, remove, and test development.
Any clarifications or corrections associated with this project will be available at Project Clarifications.
The project's code distribution is available by checking out the project named WordFrequency. The code distribution provides you with the following:
You are expected to implement the insert method for Frequency class. The other classes have been provided and you should not modify them. You can add other helper methods. For example, a find method checks if a word exists in the list. a remove method removes a word from the list, an insertnode method inserts a node in the correct location etc.
Notice you are not required to write student tests for credit, however, if you need assistance during office hours you need to bring student tests that illustrates the problem you are experiencing. Also, keep in mind the percentage associated with secret tests is high, so you need to test your project thoroughly.
Submit your project using the "Submit Project" option (available by right clicking on the project folder).
Please make sure you read the academic integrity section of the syllabus so you understand what is permissible in our programming projects. We want to remind you that we check your project against other students' projects and any case of academic dishonesty will be referred to the Office of Student Conduct.