CMSC132: Summer 2018

Project: Word Frequency List

Due Date: June 25, 11:59 pm
Assignment Type: Closed (See Policy)

Overview

In this assignment, we use linked list to count the words from a given text file or an 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 want tokeep 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

Code examples

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);
}

Objectives

This project will allow you practice linked list insert, remove, and test development.

Grading

Clarifications

Any clarifications or corrections associated with this project will be available at Project Clarifications.

Code Distribution

The project's code distribution is available by checking out the project named WordFrequency. The code distribution provides you with the following:

Specifications

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 that checks if a word exists in the list, a remove method that removes a word from the list, an insertNode method that 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.

Requirements

Suggestions on How To Start the Project

Submission

Submit your project using the "Submit Project" option (available by right clicking on the project folder).

Academic Integrity

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.