# 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.

• (30%) Public Tests
• (30%) Release Tests
• (30%) Secret Tests
• (10%) Style

## 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:

• frequency package → This package includes a linked list class and a driver. Executing the main method of in WordFrequency class prints the output.
• utils package →Reads the input source.
• tests package → Includes the public test model.
• Text files → Represent the expected output for public tests.

## 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

• The main method iterates through linked list of Frequency class and prints MAX number of words from the
list. "inputSourceName" is the text file name or the URL for the webpage. You can create your test files too. You can also test with URLs. Pay attention to the corner cases, where words are inserted at the start of the linked list, at the end of the linked list.
• Create small text files, test your code with small files. Test with bigger files such as War and Peace when you feel confident with your program.
• See Style Guidelines for information regarding style.
• We cannot provide any information regarding release nor secret tests. Once your project has been graded, you can see a TA if you would like to find out why you failed a release or secret test.

## Suggestions on How To Start the Project

• Study the public tests before starting implementing your project.

## Submission

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