Question: Here is my program called wordlist that goes with the other program called Concordance(Concordance is the program i need help with) //Program WordList import java.io.BufferedReader;


Here is my program called wordlist that goes with the other program called Concordance(Concordance is the program i need help with)
//Program WordList import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.Arrays; import java.util.SortedSet; import java.util.TreeSet;
/** * The {@code WordList} class presents a simple commandline program which outputs * all of the unique words in the given file(s) in alphabetical order. This program * makes a simplifying assumption that words are delimited by any symbol matching * the regular expression {@code "\\W+"}. * */ public class WordList {
private static final String DELIMITER = "\\W+"; //special kinda of string (one or more repetitions of the set is the + // \\W means non word characters/ so im going to separate my words
private static SortedSet
try (BufferedReader input = new BufferedReader(new FileReader(fileName))) { //creating buffered reader String line;
while ((line = input.readLine()) != null) { //while reading a line, going to split according to delimiter String[] words = line.split(DELIMITER); for (String word : words) { if (!word.isEmpty()) { results.add(word.toLowerCase()); //would add stuff here for actual program
} } } }
return results; //sorted set }
public static void main(String[] args) {
if (args.length != 0) { for (String fileName : args) { try { SortedSet
}
Concordance Program(The program i need help finishing up in the if loop with the comments talking about it)
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.Map; import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet;
public class Concordance { static class Entry { private int numberOfOccurrences; private SortedSet
public Entry(int line) { setNumberOfOccurrences(1); setLineNumbers(new TreeSet()); updateLineNumbers(line); }
public void incrementNumberOfOccurrences() { this.numberOfOccurrences++; }
public void updateLineNumbers(int line) { this.lineNumbers.add(line); }
public void setNumberOfOccurrences(int x) { this.numberOfOccurrences = x; }
public void setLineNumbers(SortedSet
public int getNumberOfOccurrences() { return numberOfOccurrences; }
public SortedSet
public String toString() { return String.format("number: %d lines: %s", getNumberOfOccurrences(), getLineNumbers()); }
private static Map
Map
try (BufferedReader input = new BufferedReader(new FileReader(fileName))) { // String line; int linenumber = 1;
while ((line = input.readLine()) != null) { // String[] words = line.split(DELIMITER); for (String word : words) { if (!word.isEmpty()) { // Here is where the implementation would go to finish off the program, so making sure once our file is read, we print out the first word from the text file, then the number of times it appears and then the line coordinate that it is on (so like in the example of the assignment) // // // // // // //
} } } } return results; } } }
Overview The purpose of this assignment is to serve as an introduction sequences, sets, and relations and their realizations in Java through the List and Map interfaces. Background Consider the following problem: given a text, for every word in the text, count both the number of times that the word occurs, and also the line numbers on which the word occurs in the text. Such a program is a simplified concordance, and has a broad range of application in numerous fields such as legal or theological analysis. Specification For this assignment you are to define a program Concordance, which for every word in the given text file(s) outputs the word, the number of times the word appears in the text, and the set of unique line numbers on which the word appears (in order). Words, are to be understood as consecutive sequences of alphanumeric characters; lines are defined by the presence of the newline, In',character and are enumerated starting with 1. Equality for words is defined by the member function equalslgnoreCase of the String class File Format For this assignment you may assume the following file format: 1. Files will be saved as plain text. 2. If a file is not empty, then it will be readable and not contain any data that will cause an IOException to be thrown while reading the file 3. All data in a file may be read by the read) method associated with a BufferedReader. 4. Every file given as input to the program exists, and is readable. 5. Files do not contain any punctuation symbols
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
