CIT 594 Counting Words with ForkJoin
Spring 2014, David Matuszek
ForkJoin. Read in a book-length text file. Count how many times each word occurs in the file. Print a table of the 25 most frequent words and a table of the 25 least frequent words. Both tables should be ordered most frequent to least frequent.
Name your project WordCounter, your package wordCounter, and your main class WordCounter.
When your program is executed, it should use a JFileChooser to select a file. The actual counting should be done by a public void countWords(String text, int numberOfSegments) method, which is I/O free and saves its result in a global variable of some type. The program should then print out the time required (in milliseconds) by the above call, along with the 25 most frequent and 25 least frequent words. (If ties occur, words with equal counts may occur in any order.)
Also provide these methods:
public int numberOfDifferentWords() returns the number of different words found.public String[] getWords(int from, int to) returns an array of words, where 1 <= from <= to <= number of different words, and 1 indicates the most frequent word.public int[] getWordCounts(int from, int to) returns an array of word counts, where 1 <= from <= to <= number of different words, and 1 indicates the most frequent word.public void print(int from, int to) prints to-from+1 lines, where each line has the form rank count word. The rank is a number between from and to, inclusive, and the count is the number of times the word occurs in the text. Use printf to get neat columns.For purposes of this assignment, a "word" consists of letters, and may contain an apostrophe (') or hyphen (-), but only if the apostrophe or hyphen has a letter on each side of it. Hence, "don't" is a word, but "'tis" is the word "tis". Words do not contain digits or other punctuation. Sherlock Holmes's address, "221B" on Baker Street, will be treated as the word "B". All words should be lowercased for purposes of counting; proper names ("France", "John", etc.) will be treated as words. (If these rules aren't enough to distinguish words from other things, ask me, or do something reasonable. Details aren't that critical.)
For some suitably long text, perform the following timings:
countWords with numberOfSegments=1, it should simply call this sequential method, rather than using ForkJoin.)Include a readme.txt file with the above information. Also, for the computer on which you did the testing, tell how many cores it has.
How do you know you have the correct answer? As usual, try your program with a small sample of text, where you have manually counted the words.
Your program is due before 6am Tuesday, April 22. Submit via Canvas, as usual.