Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that creates a concordance from some text. It will list all the words in alphabetic order followed by a list of line

Write a program that creates a concordance from some text. It will list all the words in alphabetic order followed by a list of line numbers where the word can be found

in the text.

Hash Table,

Link List,

hash code, buckets/chaining,

exception handling,

read/write files using FileChooser

Data Element - ConcordanceDataElement,

ConcordanceDataElement implements Comparable and consists of a String (the word) and a reference to a LinkedList (list of line numbers

where word occurs). Follow the Javadoc provided for you.

Data Structure - ConcordanceDataStructure,

Implements the ConcordanceDataStructureInterface Interface that is provided.

You will be implementing a hash table with buckets. It will be an array of linked list of ConcordanceDataElements. The add method will take a word and a line number to

be added to the data structure. If the word already exists, the line number will be added to the linked list for this word. If the line number for the word already exists, dont add it again to the linked list. (i.e. if Sarah was on line 5 twice, the first line 5 would be added to the linked list for Sarah, the second one would not). If the word doesnt exist, create a ConcordanceDataElement and add it to the HashTable. Two constructors will be required, one that takes in an integer that is the estimated number of words in the text, the other is used for testing purposes. Look at the provided Javadoc.

Data Manager - ConcordanceDataManager

Implements the ConcordanceDataManagerInterface interface that is provided.

The data manager allows the user to create a concordance file or a concordance list (ArrayList of strings). The input is read (from a file or string) and is added to the

data structure through the add method. The add method requires a word and a line number. The line number is incremented every time a newline appears in the file or the

string. Change all words to lowercase so that Now and now are considered the same word.

Exception Classes

IOException created and thrown when user selects an input file that cannot be read (check out the methods of File).

GUI Driver

Do not allow the user to create a concordance file until they have entered an input file and an output file

Show the text area only when the option to create from text is chosen.

Use a FileChooser for the user to select the input and output files. Use a filter so that user can only select .txt files.

Inform the user if there is an error with the input file or the output file

Use exception handling for the validity of the files.

If creating a concordance from text, make sure the user has entered some text in the text area. Inform user if text area is empty.

Display the concordance from the text in the text area.

Provide a way for the user to clear the text area.

Testing

1. Create a JUnit Test - ConcordanceDataManagerTest_STUDENT. Test all the methods of the ConcordanceDataManager with a different set of data than the

ConcordanceDataManagerTest provided for you.

2. Create a JUnit Test ConcordanceDataStructureTest_STUDENT. Test all the methods of the ConcordanceDataStructure with a different set of data than the

ConcordanceDataStructureTest provided for you.

There will be two ways to create a concordance. The first requires a document to be read from an input file, and the concordance data is written to an output file.

The second reads the input from a string and returns an ArrayList of strings that represent the concordance of the string.

Because they are so common, don't include the words "the" or and in your concordance. Also, do not include words that have length less than 3. Strip out all punctuation,

except apostrophes that occur in the middle of a word, i.e. lets, wed, etc.

---------------------------------------------------------

//ConcordanceDataManagerInterface

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

/**

* This program makes a concordance for a file or a String.

* A concordance lists all the words that occur in the file or String,

* along with all the line numbers on which each word occurs.

* (Words of length less than 3 are omitted, "and" and "the" are omitted.)

* Strip out all punctuation, except apostrophes that occur in the

* middle of a word, i.e. lets, wed, etc.

*

* Uses an object that implements ConcordanceDataStructureInterface

*

*

*/

public interface ConcordanceDataManagerInterface {

/**

*

* Display the words in Alphabetical Order followed by a :,

* followed by the line numbers in numerical order, followed by a newline

* here's an example:

* after: 129, 175

* agree: 185

* agreed: 37

* all: 24, 93, 112, 175, 203

* always: 90, 128

*

* @param input a String (usually consist of several lines) to

* make a concordance of

*

* @return an ArrayList of Strings. Each string has one word,

* followed by a :, followed by the line numbers in numerical order,

* followed by a newline.

*/

public ArrayList createConcordanceArray(String input);

/**

* Creates a file that holds the concordance

*

* @param input the File to read from

* @param output the File to write to

*

* Following is an example:

*

* about: 24, 210

* abuse: 96

* account: 79

* acknowledged: 10

*

* @return true if the concordance file was created successfully.

* @throws FileNotFoundException if file not found

*/

public boolean createConcordanceFile(File input, File output) throws FileNotFoundException;

} // end class Concordance

----------------------------------------------------------------

//ConcordanceDataStructureInterface

import java.util.ArrayList;

import java.util.LinkedList;

/**

* This is the Concordance Data Structure Class. It is the data structure

* class that is used with the Concordance Data Manager class.

* This is a hash table with buckets. Your hash table with be an array of

* linked lists of ConcordanceDataElements. Use the hashcode for an

* ConcordanceDataElement and the size of the hash table to place in the hashtable.

* Do not enter duplicate words or duplicate line numbers for a word.

*

* There should be two constructors. The first one takes in an integer which represents the

* estimated number of words in the text. Determine the size of the table by using a loading

* factor of 1.5 and a 4K+3 prime. Example: if you estimated 500 words, 500/1.5 = 333.

* The next 4K+3 prime over 333 is 347. So the tableSize would be 347.

*

* The other constructor will take in a String and an int. The string will be "Testing"

* and the int will be the size of the hash table. This is used only for testing.

*

* @author Professor Kartchner

*

*/

public interface ConcordanceDataStructureInterface{

/**

* Returns the size of the ConcordanceDataStructure (number of indexes in the array)

*/

public int getTableSize();

/**

* Returns an ArrayList of the words at this index

* [0] of the ArrayList holds the first word in the "bucket" (index)

* [1] of the ArrayList holds the next word in the "bucket", etc.

* This is used for testing

* @param index location within the hash table

* @return an Arraylist of the words at this index

*/

public ArrayList getWords(int index);

/**

* Returns an ArrayList of the Linked list of page numbers for each word at this index

* [0] of the ArrayList holds the LinkedList of page numbers for the first word in the "bucket" (index)

* [1] of the ArrayList holds the LinkedList of page numbers for next word in the "bucket", etc.

* This is used for testing

* @param index location within the hash table

* @return an ArrayList of the Linked list of page numbers for each word at this index

*/

public ArrayList> getPageNumbers(int index);

/**

* Use the hashcode of the ConcordanceDataElement to see if it is

* in the hashtable.

*

* If the word does not exist in the hashtable - Add the ConcordanceDataElement

* to the hashtable. Put the line number in the linked list

*

* If the word already exists in the hashtable

* 1. add the line number to the end of the linked list in the ConcordanceDataElement

* (if the line number is not currently there).

*

* @param word the word to be added/updated with a line number.

* @param lineNum the line number where the word is found

*/

public void add(String word, int lineNum);

/**

* Display the words in Alphabetical Order followed by a :,

* followed by the line numbers in numerical order, followed by a newline

* here's an example:

* after: 129, 175

* agree: 185

* agreed: 37

* all: 24, 93, 112, 175, 203

* always: 90, 128

*

* @return an ArrayList of Strings. Each string has one word,

* followed by a :, followed by the line numbers in numerical order,

* followed by a newline.

*/

public ArrayList showAll();

}// end of ConcordanceDataStructureInterface

---------------------------------------------------------------------------------

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions